SDK 与示例
任何 EVM 库都能用。下面是可复制起步代码;可运行示例仓里有完整 clone-and-run 项目。
链配置
ethers v6
import { JsonRpcProvider, Wallet, parseEther } from 'ethers';
const provider = new JsonRpcProvider('https://rpc-testnet.superaichain.ai', 8848);
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 superTestnet = defineChain({
id: 8848,
name: 'Super AI Chain Testnet',
nativeCurrency: { name: 'Super AI Coin', symbol: 'SUP', decimals: 18 },
rpcUrls: { default: { http: ['https://rpc-testnet.superaichain.ai'] } },
});
const client = createPublicClient({ chain: superTestnet, transport: http() });
console.log(await client.getBlockNumber());
wagmi(React)
import { createConfig, http } from 'wagmi';
import { superTestnet } from './chains';
export const config = createConfig({
chains: [superTestnet],
transports: { [superTestnet.id]: http('https://rpc-testnet.superaichain.ai') },
});
@superaichain/sdk
带类型的辅助库,预置链配置、合约地址和 ABI:
import { SuperClient } from '@superaichain/sdk';
import { parseUnits } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const client = SuperClient.testnet({ account });
const { stables } = client.addresses;
// Best-route quote across V2 + V3 (single or two-hop via WSUP).
const route = await client.swap.routeExactIn({
tokenIn: stables.WSUP,
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.WSUP,
tokenOut: stables.tUSDT,
amountIn: parseUnits('1', 18),
});
完整 Universal Router + Permit2 流程见 DEX(TS + Python)。
备注
@superaichain/sdk 与可运行示例仓在 dev-plan(第 52 / 54 节)跟踪。下面地址来自当前部署:
Loading contract addresses…
可运行示例
完整 clone-and-run 项目在 superaichain/examples(MIT)。5 套栈共 29 个示例 — 每个 README ≤100 行,最多 3 条命令就能跑起来。
git clone https://github.com/superaichain/examples
cd examples/hardhat/erc20-deploy
pnpm install && cp .env.example .env && pnpm run deploy
| 栈 | 示例 |
|---|---|
| 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 模板 | foundry · hardhat |