ethers.js example (Node)

Goal: read native + LEP-100 balances, sign and send a token transfer from a Node script using ethers v6 alongside the Lithosphere SDK's network registry and ABIs.

Install

pnpm add @lithosphere/sdk ethers

Read native balance via LithoClient

LithoClient ships with getBalance baked in — for read-only flows you don't need ethers at all.

// read-balance.ts
import { LithoClient, LithoError, ErrorCode } from '@lithosphere/sdk';

const client = new LithoClient('mainnet');

try {
  const { formatted, symbol } = await client.getBalance(
    '0x22d279d24f0b7ca5d49c5a7a7f032da416f72387',
  );
  console.log(`${formatted} ${symbol}`);
} catch (err) {
  if (err instanceof LithoError && err.code === ErrorCode.RPC_TIMEOUT) {
    console.error('RPC slow — retrying or switching endpoint advised');
  } else {
    throw err;
  }
}

Run:

Read a LEP-100 token balance via ethers

Sign and send a native transfer

Never hard-code a private key. Use process.env.PRIVATE_KEY and source it from a secret manager. For multi-sig / hardware-wallet flows, use the appropriate ethers signer (HardwareWalletSigner, gnosis Safe SDK, etc.).

Wait for confirmations with LithoClient

The SDK's waitForTransaction exits as soon as N confirmations are seen, with a configurable poll interval — useful for batch jobs that want stronger guarantees than ethers' default tx.wait(1):

Notes

  • Chain ID 700777 is the same for NETWORKS.mainnet, staging, and devnet today — they all route at the live testnet. Choose the profile based on the intent of your code path (production vs. CI staging job vs. local hardhat fork), even though they currently resolve to the same endpoints.

  • LEP100_ABI and WLITHO_ABI ship typed; pass them to ethers Contract directly — no codegen step needed.

Last updated