Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

快速开始

你只需要 Node.js、一些来自水龙头的 USDT0 以及一个私钥。Stable 使用 USDT0 作为其 gas 代币,因此你只需要 USDT0 即可进行交易。无需单独为某种 gas 资产注资。

前置条件

  • Node.js 20 或更高版本
  • 一个你掌控的私钥(一个全新的测试密钥即可)

1. 安装与配置

创建一个项目,安装 ethers,并保存测试网配置。

mkdir stable-quickstart && cd stable-quickstart
npm init -y && npm install ethers
added 1 package, audited 2 packages in 1s

将你的私钥保存到 .env

echo "PRIVATE_KEY=0xYOUR_PRIVATE_KEY_HERE" > .env

创建 config.ts

// config.ts
import { ethers } from "ethers";
import "dotenv/config";
 
export const STABLE_TESTNET_RPC = "https://rpc.testnet.stable.xyz";
export const CHAIN_ID = 2201;
 
export const provider = new ethers.JsonRpcProvider(STABLE_TESTNET_RPC);
export const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);

2. 为钱包注资

打印你的地址,然后从水龙头申请测试网 USDT0。

// address.ts
import { wallet } from "./config";
 
console.log("Wallet address:", wallet.address);
npx tsx address.ts
Wallet address: 0x1234...abcd

前往 https://faucet.stable.xyz,粘贴地址,并选择按钮以接收测试网 USDT0。水龙头会发送 1 USDT0,足以进行数千次原生转账。

3. 发送你的第一笔交易

原生发送 0.001 USDT0。在 Stable 上,USDT0 是原生资产,因此简单的价值转账是最便宜的方式(21,000 gas)。

// send.ts
import { ethers } from "ethers";
import { provider, wallet } from "./config";
 
const recipient = "0xRecipientAddress"; // replace with any address
const amount = ethers.parseEther("0.001"); // 0.001 USDT0 (18 decimals, native)
 
const block = await provider.getBlock("latest");
const baseFee = block!.baseFeePerGas!;
 
const tx = await wallet.sendTransaction({
  to: recipient,
  value: amount,
  maxFeePerGas: baseFee * 2n,
  maxPriorityFeePerGas: 0n, // always 0 on Stable
});
 
const receipt = await tx.wait(1);
console.log("Tx:", receipt!.hash);
console.log("Explorer:", `https://testnet.stablescan.xyz/tx/${receipt!.hash}`);
npx tsx send.ts
Tx: 0x8f3a...2d41
Explorer: https://testnet.stablescan.xyz/tx/0x8f3a...2d41

打开浏览器链接以确认该交易。出块时间大约为 0.7 秒,因此它应该已经最终确认。

接下来去哪里