Useful Common Functions

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

  • A getVertexClient function that returns a ready-made client object connected to Arbitrum Sepolia.

  • A prettyPrintJson function that logs readable JSON.

Note

  • Make sure your account has funds for gas on the relevant network.

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

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

/**
 * Creates a Vertex client for example scripts
 */
export function getVertexClient() {
  const walletClient = createWalletClient({
    account: privateKeyToAccount('0x...'),
    chain: arbitrumSepolia,
    transport: http(),
  });

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

  return createVertexClient('arbitrumTestnet', {
    walletClient,
    publicClient,
  });
}

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

Last updated