Useful Common Functions

These are some utility functions used throughout the guide. You may want to include them in your project.

  • A getWallet function that returns a ready-made wallet object.

  • A getVertexClient function that returns a ready-made client object.

  • A prettyPrintJson function that logs readable JSON.

Note

  • Make sure your account has ETH on the relevant network.

  • Make sure to replace your private key of choice in the function getWallet below

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

/**
 * Creates an Ethers wallet connected to Arbitrum Goerli testnet
 */
export function getWallet() {
  return new Wallet(
    "xxx", // input PK here 
    new JsonRpcProvider(
      'https://goerli-rollup.arbitrum.io/rpc',
      {
        name: 'arbitrum-goerli',
        chainId: 421613,
      },
    ),
  );
}

/**
 * Creates a Vertex client for example scripts
 */
export async function getVertexClient() {
  const signer = getWallet();
  return createVertexClient('testnet', {
    chainSignerOrProvider: signer
  });
}

/**
 * Util for pretty printing JSON
 */
export function prettyPrintJson(label: string, json: any) {
  console.log(label);
  console.log(JSON.stringify(toPrintableObject(json), null, 2));
}

Last updated