Create a Vertex client

The VertexClient Object

To start using the SDK, you need an initialized VertexClient from the client package. The VertexClient is the main entrypoint to common APIs.

Create a VertexClient object

The VertexClient class is rarely instantiated directly. Instead, call the createVertexClient function from the client package and provide the relevant parameters.

Import the dependencies

import { createVertexClient } from '@vertex-protocol/client';
import { createPublicClient, createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { arbitrumSepolia } from 'viem/chains';

Create a WalletClient and PublicClient

The WalletClient is optional and required only for write operations

const walletClient = createWalletClient({
  account: privateKeyToAccount('0x...'),
  chain: arbitrumSepolia,
  transport: http(),
});

const publicClient = createPublicClient({
  chain: arbitrumSepolia,
  transport: http(),
});

Call createVertexClient

The first argument is the ChainEnvassociated with the client. Each client can talk to one chain that Vertex Edge is deployed on. For example, use arbitrumTestnetto connect to Vertex's instance on Arbitrum Sepolia.

const vertexClient = createVertexClient('arbitrumTestnet', {
  walletClient,
  publicClient,
});

Full example

import { createVertexClient } from '@vertex-protocol/client';
import { createPublicClient, createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { arbitrumSepolia } from 'viem/chains';

function main() {
  const walletClient = createWalletClient({
    account: privateKeyToAccount('0x...'),
    chain: arbitrumSepolia,
    transport: http(),
  });

  const publicClient = createPublicClient({
    chain: arbitrumSepolia,
    transport: http(),
  });

  const vertexClient = createVertexClient('arbitrumTestnet', {
    walletClient,
    publicClient,
  });
}

main();

Run the script, this example uses ts-node:

ts-node test.ts 

If no errors are thrown, you're good to go!

Last updated