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 { JsonRpcProvider, Wallet } from 'ethers';

Create an Ethers Wallet object

For example, if interacting within a Node environment

const signer = new Wallet(
  "xxx", // add private key, or import, or use .env
  // Use a provider of choice, initialized for the relevant testnet/mainnet network
  new JsonRpcProvider(
    'https://goerli-rollup.arbitrum.io/rpc',
    {
      name: 'arbitrum-goerli',
      chainId: 421613,
    },
  ),
);

Call createVertexClient

The VertexClient can be instantiated in the following modes:

  • testnet: creates a Vertex client that connects to the arbitrum-goerli testnet network.

  • mainnet: creates a Vertex client that connects to the arbitrum-one mainnet network.

// Instantiate the main Vertex client
const vertexClient = await createVertexClient('testnet', {
  signerOrProvider: signer
});

Full example

import { JsonRpcProvider, Wallet } from 'ethers';
import {createVertexClient} from '@vertex-protocol/client';

/**
 * Create a VertexClient object
 */
async function main() {

  // Create a signer connected to Goerli testnet
  const signer = new Wallet(
    "xxx", // add private key, or import, or use .env
    new JsonRpcProvider(
      'https://goerli-rollup.arbitrum.io/rpc',
      {
        name: 'arbitrum-goerli',
        chainId: 421613,
      },
    ),
  );

  // Instantiate the main Vertex client
  const vertexClient = await createVertexClient('testnet', {
    signerOrProvider: signer,
  });
}

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