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 作为 Gas 进行操作

在 Stable 上,USDT0 既是链的原生资产,也是 ERC-20 代币。Gas 代币是 USDT0,而不是单独的原生资产。标准以太坊 Gas 估算工作原理如下,但您需要调整三点:maxPriorityFeePerGas 始终为 0baseFee 以 USDT0 计价,并且原生转账中的 value 字段承载 USDT0(而不是 ETH)。

本指南展示了如何在 Stable 上正确构建交易以及移植以太坊代码时需要更改的内容。

与以太坊相比的变化

字段以太坊Stable
Gas 代币ETHUSDT0
maxPriorityFeePerGas用于排序忽略(设置为 0
baseFeePerGas以 ETH 计价以 USDT0 计价
value(原生转账)转账 ETH转账 USDT0
EIP-1559 交易格式支持支持
eth_estimateGas, eth_gasPrice支持支持
eth_maxPriorityFeePerGas返回小费返回 0

因为交易格式不变,所以现有的 ethers.js、viem、Hardhat 和 Foundry 代码可以在 Stable 上运行而无需更改。区别在于您如何计算 Gas 字段,而不是如何编码它们。

构建交易

获取基本费用,将 maxPriorityFeePerGas 设置为 0,并将基本费用加倍作为安全余量。

// sendNative.ts
import { ethers } from "ethers";
import "dotenv/config";
 
const provider = new ethers.JsonRpcProvider("https://rpc.testnet.stable.xyz");
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
 
const block = await provider.getBlock("latest");
const baseFee = block!.baseFeePerGas!;
 
const maxPriorityFeePerGas = 0n; // always 0 on Stable
const maxFeePerGas = baseFee * 2n + maxPriorityFeePerGas; // 2x headroom
 
const tx = await wallet.sendTransaction({
  to: "0xRecipientAddress",
  value: ethers.parseEther("0.001"), // 0.001 USDT0, 18 decimals
  maxFeePerGas,
  maxPriorityFeePerGas,
});
 
const receipt = await tx.wait(1);
console.log("Tx:", receipt!.hash);
console.log("Gas used:", receipt!.gasUsed.toString());
console.log("Effective gas price:", receipt!.gasPrice.toString(), "(USDT0 wei-equivalent)");
npx tsx sendNative.ts
Tx: 0x8f3a...2d41
Gas used: 21000
Effective gas price: 1000000000 (USDT0 wei-equivalent)

有效 Gas 价格是以 USDT0 计价的值。以 1 gwei 计算,21,000 Gas 的原生转账大约需要 0.000021 USDT0。

估算 USDT0 中的 Gas 成本

eth_estimateGaseth_gasPrice 的行为与以太坊完全相同。结果已经是 USDT0,因为它是 Gas 代币。

// estimate.ts
import { ethers } from "ethers";
 
const provider = new ethers.JsonRpcProvider("https://rpc.testnet.stable.xyz");
 
const gasPrice = await provider.send("eth_gasPrice", []);
const gasEstimate = await provider.estimateGas({
  to: "0xContractAddress",
  data: "0x...",
});
 
const feeInUSDT0 = BigInt(gasPrice) * gasEstimate;
console.log("Estimated fee:", ethers.formatEther(feeInUSDT0), "USDT0");
npx tsx estimate.ts
Estimated fee: 0.000021 USDT0

工具配置

  • Hardhat / Foundry:无需特殊配置。标准 EVM 设置即可。如果您的配置明确设置了优先费用,请将其设置为 0
  • 钱包:隐藏或禁用优先小费输入字段。显示它具有误导性,因为该值对排序或包含没有影响。
  • 监控:费用分析仪表板不应绘制优先费用图表。它们在 Stable 上始终为零。

从以太坊移植时常见的错误

  • 应用以 ETH 计价的小费:复制以太坊的优先费用常量不会导致更快的包含。Stable 仅按基本费用对交易进行排序。
  • value 视为 ETH:原生转账的 value 是 USDT0。不要通过 ETH/USD 价格进行转换。
  • 硬编码费用上限:从实时 baseFeePerGas(例如 baseFee * 2)设置 maxFeePerGas,而不是固定值,这样当基本费用上涨时交易不会停滞。

推荐阅读