Multi-Chain Support
Chain configuration, built-in presets, custom networks, and chain switching
Multi-Chain Support
The chain configuration subsystem is exposed by @nerochain/mpc-sdk/chains. It provides the ChainConfig type, built-in chain presets, ChainManager, and chain management methods on NeroMpcSDK.
ChainConfig Type
| Field | Type | Required | Description |
|---|---|---|---|
chainId | number | Yes | EIP-155 chain ID |
chainName | string | Yes | Internal machine-readable name |
displayName | string | Yes | Human-readable name |
nativeCurrency.name | string | Yes | Full name of the native token |
nativeCurrency.symbol | string | Yes | Ticker symbol |
nativeCurrency.decimals | number | Yes | Decimal precision (always 18 for EVM) |
rpcUrls | string[] | Yes | Ordered list of JSON-RPC endpoints |
blockExplorerUrls | string[] | No | Block explorer base URLs |
isTestnet | boolean | Yes | Flag distinguishing testnets |
entryPointAddress | string | No | ERC-4337 EntryPoint contract address |
simpleAccountFactoryAddress | string | No | SimpleAccount factory contract address |
bundlerUrl | string | No | ERC-4337 bundler endpoint |
paymasterUrl | string | No | Paymaster service endpoint |
Built-in Chain Presets
import {
NERO_TESTNET,
NERO_MAINNET,
ETHEREUM_MAINNET,
ETHEREUM_SEPOLIA,
POLYGON_MAINNET,
ARBITRUM_ONE,
BASE_MAINNET,
} from "@nerochain/mpc-sdk/chains";| Constant | Chain ID | Display Name | Testnet | Bundler | Paymaster |
|---|---|---|---|---|---|
NERO_TESTNET | 689 | NERO Testnet | Yes | Yes | Yes |
NERO_MAINNET | 1689 | NERO Mainnet | No | Yes | Yes |
ETHEREUM_MAINNET | 1 | Ethereum | No | No | No |
ETHEREUM_SEPOLIA | 11155111 | Sepolia Testnet | Yes | No | No |
POLYGON_MAINNET | 137 | Polygon | No | No | No |
ARBITRUM_ONE | 42161 | Arbitrum One | No | No | No |
BASE_MAINNET | 8453 | Base | No | No | No |
NERO Testnet Details
| Field | Value |
|---|---|
| RPC | https://rpc-testnet.nerochain.io |
| Explorer | https://testnet.neroscan.io |
| Bundler | https://bundler-testnet.nerochain.io |
| Paymaster | https://paymaster-testnet.nerochain.io |
| EntryPoint | 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 |
| Factory | 0x9406Cc6185a346906296840746125a0E44976454 |
NERO Mainnet Details
| Field | Value |
|---|---|
| RPC | https://rpc.nerochain.io |
| Explorer | https://neroscan.io |
| Bundler | https://bundler-mainnet.nerochain.io |
| Paymaster | https://paymaster-mainnet.nerochain.io |
| EntryPoint | 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 |
| Factory | 0x9406Cc6185a346906296840746125a0E44976454 |
Utility Functions
| Function | Signature | Returns |
|---|---|---|
getChainConfig | (chainId: number) => ChainConfig | undefined | Single config from BUILTIN_CHAINS |
getAllChains | () => ChainConfig[] | All built-in configs |
getTestnetChains | () => ChainConfig[] | Configs where isTestnet === true |
getMainnetChains | () => ChainConfig[] | Configs where isTestnet === false |
import { getChainConfig, getAllChains, getTestnetChains } from "@nerochain/mpc-sdk/chains";
const neroTestnet = getChainConfig(689);
const allChains = getAllChains();
const testnets = getTestnetChains();Custom Chain Configuration
Register private or newly launched networks using addChain():
sdk.addChain({
chainId: 1,
chainName: "ethereum-mainnet",
displayName: "Ethereum Mainnet",
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
rpcUrls: ["https://eth.llamarpc.com"],
blockExplorerUrls: ["https://etherscan.io"],
isTestnet: false,
});Chain Switching
switchChain(chainId) updates the SDK's active chain. It validates the chain is either built-in or previously added via addChain, then calls notifyListeners to trigger UI updates or provider reconfigurations.
await sdk.switchChain(1689);The SDK emits a chain_changed event when the active chain updates:
sdk.on("chain_changed", ({ chainId }) => {
console.log("Switched to chain:", chainId);
});RpcConnection Features
The ChainManager creates RpcConnection instances that provide:
- Automatic RPC Rotation: Cycles through the
rpcUrlslist on call failures - Standard EVM Methods: Built-in helpers for
getBalance,getTransactionCount,estimateGas, andsendRawTransaction - Transaction Polling:
waitForTransactionpolls for receipts until the specified confirmation count is reached
Local Signing Integration
When using the SDK for local signing (bypassing MPC rounds by reconstructing the private key), the ChainConfig initializes the LocalKeyProvider:
- Signing: Intercepts
personal_sign,eth_signTypedData_v4, andeth_sendTransactionto sign locally - State: Responds to
eth_chainIdusing thechainIdfrom activeChainConfig - Forwarding: Sends all other requests (e.g.,
eth_call) to the primary RPC URL