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

发送你的第一笔 USDT0

在 Stable 上,USDT0 既是链的原生资产,也是一个 ERC-20 代币。这意味着 approvetransferFrompermit 在标准价值转账之外仍然完全可用,并且这两条路径都从同一个底层余额中转移资金。

本页将引导你通过这两条路径发送 USDT0,并确认它们都从同一个余额中扣款。

你将构建什么

一个两脚本流程:以原生转账方式发送 0.001 USDT0,以 ERC-20 转账方式发送 0.001 USDT0,并打印两个余额。

演示

step 1. Connect wallet → balance displayed
        0.01 USDT0

step 2. Send 0.001 USDT0 (choose native or ERC-20 transfer)

step 3. Result
        Sent:              0.001 USDT0
        Gas fee:           0.000021 USDT0
        Native balance:    0.008979 USDT0
        ERC-20 balance:    0.008979 USDT0

前提条件

  • Node.js 20 或更高版本
  • 一个持有测试网 USDT0 的私钥。请参阅快速开始为钱包充值。
USDT0 合约地址
  • 主网:0x779ded0c9e1022225f8e0630b35a9b54be713736
  • 测试网:0x78cf24370174180738c5b8e352b6d14c83a6c9a9

设置

// 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 USDT0_ADDRESS = "0x78Cf24370174180738C5B8E352B6D14c83a6c9A9";
 
export const provider = new ethers.JsonRpcProvider(STABLE_TESTNET_RPC);
export const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);

选项 1(推荐):以原生转账方式发送

原生转账的工作方式与在以太坊上发送 ETH 相同。value 字段携带 USDT0 数量。一次原生转账仅消耗 21,000 gas,是发送 USDT0 最便宜的方式。

// sendNative.ts
import { ethers } from "ethers";
import { provider, wallet } from "./config";
 
const recipient = "0xRecipientAddress";
const amount = ethers.parseUnits("0.001", 18); // 18 decimals for 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("Native transfer tx:", receipt!.hash);
npx tsx sendNative.ts
Native transfer tx: 0x8f3a...2d41

选项 2:以 ERC-20 转账方式发送

USDT0 也可以作为 ERC-20 转账发送。这会从同一个余额中扣款,但使用 6 位小数精度的 ERC-20 接口。

// sendERC20.ts
import { ethers } from "ethers";
import { wallet, USDT0_ADDRESS } from "./config";
 
const recipient = "0xRecipientAddress";
const amount = ethers.parseUnits("0.001", 6); // 6 decimals for ERC-20
 
const usdt0 = new ethers.Contract(USDT0_ADDRESS, [
  "function transfer(address to, uint256 amount) returns (bool)"
], wallet);
 
const tx = await usdt0.transfer(recipient, amount);
const receipt = await tx.wait(1);
console.log("ERC-20 transfer tx:", receipt!.hash);
npx tsx sendERC20.ts
ERC-20 transfer tx: 0xa2b1...77c0

验证统一余额

在任一种转账之后,查询两个余额以确认它们来自同一来源。

// balances.ts
import { ethers } from "ethers";
import { provider, wallet, USDT0_ADDRESS } from "./config";
 
const nativeBalance = await provider.getBalance(wallet.address);
console.log("Native balance:", ethers.formatEther(nativeBalance), "USDT0");
 
const usdt0 = new ethers.Contract(USDT0_ADDRESS, [
  "function balanceOf(address) view returns (uint256)"
], provider);
const erc20Balance = await usdt0.balanceOf(wallet.address);
console.log("ERC-20 balance:", ethers.formatUnits(erc20Balance, 6), "USDT0");
npx tsx balances.ts
Native balance: 0.008979 USDT0
ERC-20 balance: 0.008979 USDT0

这两个值代表的是同一个余额。由于小数余额对账,它们可能相差最多 0.000001 USDT0。

推荐的下一步