Early release. This is published in
@uzolabs/sdk 0.2.0 on npm and you can use it today. The API may change before 1.0, so pin the version.What you’ll build
A wagmi config for BOT Chain testnet and mainnet, and a component that reads a token balance with the SDK’s addresses.Prerequisites
- A React app with wagmi set up. Set up wagmi walks through it from scratch.
@uzolabs/sdkinstalled:npm install @uzolabs/sdk.
Steps
1
Add the chains to your config
botChain and botChainTestnet are viem chain objects, which is what wagmi expects.src/wagmi.ts
Register block types every hook from your config. Without it, useChainId returns a plain number, which getAddresses won’t accept.Each chain object includes the public RPC, BOTScan as the explorer and the Multicall3 address, so wagmi can batch reads without extra config.2
Look up addresses for the connected chain
getAddresses(chainId) takes 677 or 968, the two IDs in the config. Pair it with useChainId so the component follows the user’s network.src/UsdtBalance.tsx
Register block, useChainId returns a chain ID from your config, so its type is 677 | 968, which is the SDK’s SupportedChainId.3
Use the SDK's ABIs for BDEX and the bridge
The SDK’s ABIs are
as const arrays, so wagmi infers function names, arguments and return types from them:src/useQuote.ts
Verify
Connect a wallet on BOT Chain testnet. The balance component shows your testnet USDT, and switching to mainnet in your wallet updates it to the mainnet USDT contract.Troubleshooting
Type error: chain ID is not assignable to SupportedChainId
Type error: chain ID is not assignable to SupportedChainId
useChainId is typed from your config. If you add a chain the SDK doesn’t support, guard before calling getAddresses, or it throws UnsupportedChainError.The wallet doesn't know BOT Chain
The wallet doesn't know BOT Chain
wagmi can ask the wallet to add the network. See Connect a wallet.
Next steps
Read contract state
More reads with wagmi.
Send transactions
Writes, receipts and errors.