Skip to main content

SDK & Code Examples

Use any EVM library. Below are copy-paste starters; the runnable examples repo contains full clone-and-run projects.

Chain config

Network Name
Mo Chain Testnet
Chain ID
6688 (0x1a20)
Currency Symbol
MO
RPC URL
https://rpc-testnet.mo.fit
WebSocket
wss://wss-testnet.mo.fit
Block Explorer
https://scan-testnet.mo.fit

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).

note

@mochain/sdk and the runnable examples repo are tracked in the dev-plan (sections 52 / 54). Addresses below come from the live deployment:

ContractAddressExplorer
v2Factory0xc1f728e16D83F822599C810155731AC5302DeFd4view ↗
v2Router020x5965f93551411D3ba621593470Dd08f951441b7aview ↗
v3Factory0x0177F39C814Fec1462A169e9689EFB904874efF0view ↗
v3PositionManager0x87A7D23217d0A633e51B2a97dec648D25B793996view ↗
v3Router0x35201E3B4Ce12448fF4EC3d4107D28Ace10acde3view ↗
v3Quoter0x985f113bbFA7953F5Abc37F95d5E577c971F7F4aview ↗
universalRouter0x78E2FF97feeeFfE7D167F46a2cDBba9fb9551720view ↗
permit20xDCFeC1d498D46E836c65e2Cd27dD1E8292bD8d95view ↗

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
StackExamples
Hardhaterc20-deploy · erc721-mint · upgrade-uups · multisig-safe-deploy · verify-on-blockscout
Foundryerc20-deploy · invariant-test · fuzz-test · deploy-script-multichain · verify-on-blockscout
viemread-balance · send-tx · bridge-deposit · swap-exactin · ens-resolve
ethers v6read-balance · send-tx · bridge-deposit-abi
web3.pyread-balance · send-tx · faucet-claim-oauth
GraphQLbridge-history · dex-tvl · ens-reverse-lookup
dAppsnextjs-wallet-connect · vite-react-swap · faucet-bot-discord
CI templatesfoundry · hardhat

Next steps