Set up viem clients, the Robinhood Chain definition, contract addresses, and ABIs before integrating Bags launching and trading.
This guide sets up the shared building blocks — chain definition, read/write clients, addresses, and ABIs — used by every other Robinhood Chain guide. The examples use viem, but the same calls translate directly to ethers or any EVM library.
Node.js 18+ and a TypeScript project. If you’re starting fresh, follow the TypeScript & Node.js Setup Guide for the base project, then install the EVM dependencies below.
Some ETH on Robinhood Chain (chain ID 4663) in the wallet you’ll sign with.
Create a .env file. The public RPC works out of the box but is rate-limited; set a dedicated endpoint if you have one.
# .envROBINHOOD_RPC_URL=https://rpc.mainnet.chain.robinhood.com# Required only for guides that send transactions (launch, trade, claim):PRIVATE_KEY=0xYOUR_PRIVATE_KEY_HERE
Never commit your .env file. Add it to .gitignore. Treat your private key as a secret.
Save this as clients.ts. The public client is for reads and simulations; the wallet client signs and sends transactions.
clients.ts
import { createPublicClient, createWalletClient, http } from "viem";import { privateKeyToAccount } from "viem/accounts";import { robinhoodChain, ROBINHOOD_RPC_URL } from "./chain";/** * Shared read client. `batch.multicall` coalesces parallel readContract calls * into single multicall3 requests — the main defense against public-RPC rate * limits. 500 ms polling suits the ~100 ms block time. */export const publicClient = createPublicClient({ chain: robinhoodChain, transport: http(ROBINHOOD_RPC_URL, { batch: true }), batch: { multicall: true }, pollingInterval: 500,});/** Write client. Only needed for launch / trade / claim guides. */export function getWalletClient() { const pk = process.env.PRIVATE_KEY; if (!pk) throw new Error("PRIVATE_KEY is required to send transactions"); const account = privateKeyToAccount(pk as `0x${string}`); return createWalletClient({ account, chain: robinhoodChain, transport: http(ROBINHOOD_RPC_URL), });}
In a browser dApp, replace getWalletClient with a wallet-backed client, e.g. createWalletClient({ account, chain: robinhoodChain, transport: custom(window.ethereum) }), and switch the wallet to chain 4663 before writing.
import bagsFactory from "./BagsFactory.json";import bagsBondingCurve from "./BagsBondingCurve.json";import bagsFeeShare from "./BagsFeeShare.json";import bagsLens from "./BagsLens.json";import bagsToken from "./BagsToken.json";import bagsV4Hook from "./BagsV4Hook.json";import bagsVault from "./BagsVault.json";export const bagsFactoryAbi = bagsFactory;export const bagsBondingCurveAbi = bagsBondingCurve;export const bagsFeeShareAbi = bagsFeeShare;export const bagsLensAbi = bagsLens;export const bagsTokenAbi = bagsToken;export const bagsV4HookAbi = bagsV4Hook;export const bagsVaultAbi = bagsVault;
Import the full ABIs including their custom error definitions — viem uses them to decode revert reasons into readable errors (e.g. BagsBondingCurve_SlippageExceeded). See the Contracts Reference for the error catalog.
The Uniswap-style infrastructure (UniversalRouter, Permit2, WETH, V4Quoter, StateView) is not part of the Bags ABI export. The Trade Tokens guide includes the minimal hand-written ABIs you need for post-migration swaps. The full definitions are also listed in the Contracts Reference.