Run a standalone example
Requires Node.js 20+.ctoken.mjs:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Use the same client and session flow in services, scripts, native ESM, and CommonJS.
mkdir ctoken-example
cd ctoken-example
npm init -y
npm install @inco/ctoken@^0.2.0 viem @inco/lightning-js
ctoken.mjs:
import { createPublicClient, http } from "viem";
import { baseSepolia } from "viem/chains";
import { CTokenClient } from "@inco/ctoken";
const rpcUrl = process.env.RPC_URL;
if (!rpcUrl) throw new Error("Set RPC_URL to your Base Sepolia read endpoint.");
const publicClient = createPublicClient({
chain: baseSepolia,
transport: http(rpcUrl),
});
const ctoken = new CTokenClient({ network: "baseSepolia", publicClient });
const token = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
console.log("USDC wrapper:", await ctoken.wrapperOf({ token }));
RPC_URL="https://your-read-endpoint.example" node ctoken.mjs
const ctoken = new CTokenClient({ network: "baseSepolia", publicClient, walletClient });
import { createPublicClient, createWalletClient, getAddress, http } from "viem";
import { baseSepolia } from "viem/chains";
import { CTokenClient } from "@inco/ctoken";
const readRpc = process.env.RPC_URL;
if (!readRpc) throw new Error("Configure your read RPC endpoint.");
const publicClient = createPublicClient({ chain: baseSepolia, transport: http(readRpc) });
const address = process.env.WALLET_ADDRESS;
const signingRpc = process.env.WALLET_RPC_URL;
if (!address || !signingRpc) throw new Error("Configure your signing service.");
const walletClient = createWalletClient({
account: getAddress(address),
chain: baseSepolia,
transport: http(signingRpc),
});
const ctoken = new CTokenClient({
network: "baseSepolia",
publicClient,
walletClient,
});
const token = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
const balance = await ctoken.publicBalanceExact({ token });
console.log(balance.formatted);
// CommonJS
const { CTokenClient } = require("@inco/ctoken");
const ctoken = new CTokenClient({ network: "baseSepolia", publicClient, walletClient });
Was this page helpful?