SDK & Code Examples
Use any EVM library. Below are copy-paste starters; the runnable examples repo contains full clone-and-run projects.
Chain config
ethers v6
import { JsonRpcProvider, Wallet, parseEther } from 'ethers';
const provider = new JsonRpcProvider('https://rpc-testnet.rmb.cash', 6688);
const wallet = new Wallet(process.env.PRIVATE_KEY!, provider);
const tx = await wallet.sendTransaction({ to: wallet.address, value: parseEther('0.01') });
console.log((await tx.wait())?.hash);
viem
import { createPublicClient, http, defineChain } from 'viem';
export const moTestnet = defineChain({
id: 6688,
name: 'RMB Chain Testnet',
nativeCurrency: { name: 'RMB Coin', symbol: 'RMB', decimals: 18 },
rpcUrls: { default: { http: ['https://rpc-testnet.rmb.cash'] } },
});
const client = createPublicClient({ chain: moTestnet, transport: http() });
console.log(await client.getBlockNumber());
wagmi (React)
import { createConfig, http } from 'wagmi';
import { moTestnet } from './chains';
export const config = createConfig({
chains: [moTestnet],
transports: { [moTestnet.id]: http('https://rpc-testnet.rmb.cash') },
});
@mochain/sdk
A typed helper that pre-bundles chain config, contract addresses, and ABIs:
import { MoClient } from '@mochain/sdk';
import { parseUnits } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const client = MoClient.testnet({ account });
const { stables } = client.addresses;
// Best-route quote across V2 + V3 (single or two-hop via WMO).
const route = await client.swap.routeExactIn({
tokenIn: stables.WMO,
tokenOut: stables.tUSDT,
amountIn: parseUnits('1', 18),
});
// Swap via the Universal Router + Permit2 (approve + sign handled once).
const { hash } = await client.swap.exactInUniversal({
tokenIn: stables.WMO,
tokenOut: stables.tUSDT,
amountIn: parseUnits('1', 18),
});
See DEX for the full Universal Router + Permit2 walkthrough (TS + Python).
note
@mochain/sdk and the runnable examples repo are tracked in the dev-plan (sections 52 / 54). Addresses below come from the live deployment:
| Contract | Address | Explorer |
|---|---|---|
| v2Factory | 0x0310B4DEC0C9548962efcB8e3d112a27bc038dBE | view ↗ |
| v2Router02 | 0xf7F19B0D45b2334054B0159F07e60eDA43e6E4cC | view ↗ |
| v3Factory | 0xe05a3C33957fA19A447ecc97F304bfC46d5c8c77 | view ↗ |
| v3PositionManager | 0x4652008e7fCF38ad002030D87D2e9d49Cf5a1805 | view ↗ |
| v3Router | 0x51Bf06928a89cfda68b4059F91a1C001972B7e3B | view ↗ |
| v3Quoter | 0xd93F5a11013748752FE6485AC9179646aB6C3320 | view ↗ |
| universalRouter | 0x643B427a2858E86821FCD60862121e8d0d07D472 | view ↗ |
| permit2 | 0xe4fB1Db4fb118443C6545F8B92fbe409eB7217fC | view ↗ |
Runnable examples
Full clone-and-run projects live in the mochain/examples repo (MIT). 29 examples across 5 stacks — each with a ≤100-line README and 跑起来 in ≤3 commands.
git clone https://github.com/mochain/examples
cd examples/hardhat/erc20-deploy
pnpm install && cp .env.example .env && pnpm run deploy
| Stack | Examples |
|---|---|
| Hardhat | erc20-deploy · erc721-mint · upgrade-uups · multisig-safe-deploy · verify-on-blockscout |
| Foundry | erc20-deploy · invariant-test · fuzz-test · deploy-script-multichain · verify-on-blockscout |
| viem | read-balance · send-tx · bridge-deposit · swap-exactin · ens-resolve |
| ethers v6 | read-balance · send-tx · bridge-deposit-abi |
| web3.py | read-balance · send-tx · faucet-claim-oauth |
| GraphQL | bridge-history · dex-tvl · ens-reverse-lookup |
| dApps | nextjs-wallet-connect · vite-react-swap · faucet-bot-discord |
| CI templates | foundry · hardhat |