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.mo.fit', 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: 'Mo Chain Testnet',
nativeCurrency: { name: 'Mo Coin', symbol: 'MO', decimals: 18 },
rpcUrls: { default: { http: ['https://rpc-testnet.mo.fit'] } },
});
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.mo.fit') },
});
@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).
备注
@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 | 0xc1f728e16D83F822599C810155731AC5302DeFd4 | view ↗ |
| v2Router02 | 0x5965f93551411D3ba621593470Dd08f951441b7a | view ↗ |
| v3Factory | 0x0177F39C814Fec1462A169e9689EFB904874efF0 | view ↗ |
| v3PositionManager | 0x87A7D23217d0A633e51B2a97dec648D25B793996 | view ↗ |
| v3Router | 0x35201E3B4Ce12448fF4EC3d4107D28Ace10acde3 | view ↗ |
| v3Quoter | 0x985f113bbFA7953F5Abc37F95d5E577c971F7F4a | view ↗ |
| universalRouter | 0x78E2FF97feeeFfE7D167F46a2cDBba9fb9551720 | view ↗ |
| permit2 | 0xDCFeC1d498D46E836c65e2Cd27dD1E8292bD8d95 | 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 |