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
v2Factory0x0fB0bA051106d4d0470B612BCE155298B2A1b39bview ↗
v2Router020x9E2D1a442a40660a6d0570014eEfa6F3498A82ABview ↗
v3Factory0x793CA1699A7578B8AE088BE3dbcEbad476fa1cBEview ↗
v3PositionManager0x4c47f69F566D06b4Cf53995D211Fe27899C5AC1aview ↗
v3Router0xa9B3D01E9297aB201BaeA250DB9135fe7465Dc90view ↗
v3Quoter0x487ccc66D246a185717361847bB326910b2019Eaview ↗
universalRouter0xb1c4f326F60F86B115b15094A7ae8FFEa67FdF53view ↗
permit20x8bF7477147bEC6890cbee250492930bF71E61140view ↗

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