Configuration
Basic setup
Section titled “Basic setup”In an Astro app, run configureSetup once by putting the wagmi + SDK wiring in a small module and importing that module from your root layout (side-effect import). The wagmi config must list every chain you use and define a transport per chain (for example http() for defaults, or http(url) for your own RPC).
src/lib/cooperative.ts
import { configureSetup, createWagmiChainClient } from "cooperative";import { createConfig, http } from "wagmi";import { mainnet, polygon, base } from "viem/chains";
const wagmiConfig = createConfig({ chains: [mainnet, polygon, base], transports: { [mainnet.id]: http(), [polygon.id]: http(), [base.id]: http(), },});
configureSetup({ chainClient: createWagmiChainClient(wagmiConfig),});Custom RPC URLs
Section titled “Custom RPC URLs”For production, point each chain at a provider you control (Alchemy, Infura, and so on) so you avoid public RPC rate limits and get more predictable behavior.
Add environment variables at the project root in .env. Prefix names with PUBLIC_ when the value must be available in code that Astro ships to the client (typical for wagmi and wallet flows):
PUBLIC_ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/your_keyPUBLIC_POLYGON_RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/your_keyPUBLIC_BASE_RPC_URL=https://base-mainnet.g.alchemy.com/v2/your_keysrc/lib/cooperative.ts
import { configureSetup, createWagmiChainClient } from "cooperative";import { createConfig, http } from "wagmi";import { mainnet, polygon, base } from "viem/chains";
const wagmiConfig = createConfig({ chains: [mainnet, polygon, base], transports: { [mainnet.id]: http(import.meta.env.PUBLIC_ETH_RPC_URL), [polygon.id]: http(import.meta.env.PUBLIC_POLYGON_RPC_URL), [base.id]: http(import.meta.env.PUBLIC_BASE_RPC_URL), },});
configureSetup({ chainClient: createWagmiChainClient(wagmiConfig),});Supported chains
Section titled “Supported chains”| Chain ID | Name | Native token |
|---|---|---|
| 1 | Ethereum | ETH |
| 137 | Polygon | POL |
| 8453 | Base | ETH |