Connect with ethers
Set up ethers v6 providers, signers, addresses, and minimal ABIs.
The contract examples use ethers v6 and minimal human-readable ABIs. Install ethers in a browser or Node project before copying a call.
pnpm add ethers
Define the network and addresses
export const CHAIN_ID = 4663n;
export const RPC_URL = "https://rpc.mainnet.chain.robinhood.com";
const launchConfigResponse = await fetch("/api/launchpad/config");
if (!launchConfigResponse.ok) throw new Error("Launch configuration could not be loaded.");
const launchConfig = await launchConfigResponse.json() as {
contracts: {
factoryAddress: string;
routerAddress: string;
};
};
export const addresses = {
launchFactory: launchConfig.contracts.factoryAddress,
launchRouter: launchConfig.contracts.routerAddress,
nftFactory: "0x86cc928EE77492ee6B9e6b651cDA5A649CD2cFe6",
nftMarketplace: "0x576f3228c473136790Ed3b065c1B816C188884A6",
} as const;
if (!addresses.launchFactory || !addresses.launchRouter) {
throw new Error("The SushiSwap-backed Spawn deployment is not configured.");
}
Read /api/nft/config too when your application should follow the hosted NFT deployment automatically.
Create a read provider
A JSON-RPC provider can read state and query logs without a wallet.
import { JsonRpcProvider } from "ethers";
const provider = new JsonRpcProvider(RPC_URL, Number(CHAIN_ID), {
staticNetwork: true,
});
const blockNumber = await provider.getBlockNumber();
console.log({ blockNumber });
Create a browser signer
Write calls need an EIP-1193 wallet provider and user approval.
import { BrowserProvider } from "ethers";
if (!window.ethereum) throw new Error("Install an EVM wallet.");
const browserProvider = new BrowserProvider(window.ethereum);
await browserProvider.send("eth_requestAccounts", []);
const network = await browserProvider.getNetwork();
if (network.chainId !== CHAIN_ID) {
throw new Error(`Switch the wallet to chain ${CHAIN_ID}.`);
}
const signer = await browserProvider.getSigner();
console.log(await signer.getAddress());
Your app can request wallet_switchEthereumChain with hexadecimal chain ID 0x1237 before creating the signer.
Use minimal ABIs
Include only the functions and events required by a screen. Human-readable fragments are concise and preserve named tuple fields.
import { Contract } from "ethers";
const marketplace = new Contract(
addresses.nftMarketplace,
[
"function platformFeeBps() view returns (uint96)",
"function paused() view returns (bool)",
],
provider,
);
const [feeBps, paused] = await Promise.all([
marketplace.platformFeeBps(),
marketplace.paused(),
]);
Continue with Read contracts or a write-call guide.