trade

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Trading Tokens

代币交易

Use the
npx awal@latest trade
command to swap tokens on Base network via the CDP Swap API. You must be authenticated to trade.
使用
npx awal@latest trade
命令,通过CDP Swap API在Base网络上进行代币兑换。交易前必须完成身份验证。

Confirm wallet is initialized and authed

确认钱包已初始化并完成验证

bash
npx awal@latest status
If the wallet is not authenticated, refer to the
authenticate-wallet
skill.
bash
npx awal@latest status
如果钱包未验证,请参考
authenticate-wallet
技能文档。

Command Syntax

命令语法

bash
npx awal@latest trade <amount> <from> <to> [options]
bash
npx awal@latest trade <amount> <from> <to> [options]

Arguments

参数说明

ArgumentDescription
amount
Amount to swap (see Amount Formats below)
from
Source token: alias (usdc, eth, weth) or contract address (0x...)
to
Destination token: alias (usdc, eth, weth) or contract address (0x...)
参数描述
amount
兑换金额(详见下方的金额格式)
from
源代币:别名(usdc, eth, weth)或合约地址(0x...)
to
目标代币:别名(usdc, eth, weth)或合约地址(0x...)

Amount Formats

金额格式

The amount can be specified in multiple formats:
FormatExampleDescription
Dollar prefix
'$1.00'
,
'$0.50'
USD notation (decimals based on token)
Decimal
1.0
,
0.50
,
0.001
Human-readable with decimal point
Whole number
5
,
100
Interpreted as whole tokens
Atomic units
500000
Large integers treated as atomic units
Auto-detection: Large integers without a decimal point are treated as atomic units. For example,
500000
for USDC (6 decimals) = $0.50.
Decimals: For known tokens (usdc=6, eth=18, weth=18), decimals are automatic. For arbitrary contract addresses, decimals are read from the token contract.
金额支持多种格式:
格式示例描述
美元前缀
'$1.00'
,
'$0.50'
美元表示法(小数位数基于代币规则)
小数格式
1.0
,
0.50
,
0.001
带小数点的易读格式
整数格式
5
,
100
被解析为完整代币数量
原子单位
500000
大整数将被视为原子单位
自动识别:不带小数点的大整数会被视为原子单位。例如,USDC(6位小数)的
500000
原子单位等价于0.50美元。
小数位数:对于已知代币(usdc=6位,eth=18位,weth=18位),小数位数自动适配。对于自定义合约地址,小数位数将从代币合约中读取。

Options

可选参数

OptionDescription
-c, --chain <name>
Blockchain network (default: base)
-s, --slippage <n>
Slippage tolerance in basis points (100 = 1%)
--json
Output result as JSON
选项描述
-c, --chain <name>
区块链网络(默认值:base)
-s, --slippage <n>
滑点容忍度,单位为基点(100基点=1%)
--json
以JSON格式输出结果

Token Aliases

代币别名

AliasTokenDecimalsAddress
usdcUSDC60x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
ethETH180xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
wethWETH180x4200000000000000000000000000000000000006
IMPORTANT: Always single-quote amounts that use
$
to prevent bash variable expansion (e.g.
'$1.00'
not
$1.00
).
别名代币小数位数合约地址
usdcUSDC60x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
ethETH180xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
wethWETH180x4200000000000000000000000000000000000006
重要提示:使用美元前缀的金额时,务必用单引号包裹,避免bash变量解析(例如使用
'$1.00'
而非
$1.00
)。

Examples

示例

bash
undefined
bash
undefined

Swap $1 USDC for ETH (dollar prefix — note the single quotes)

将1美元的USDC兑换为ETH(美元前缀格式——注意单引号)

npx awal@latest trade '$1' usdc eth
npx awal@latest trade '$1' usdc eth

Swap 0.50 USDC for ETH (decimal format)

将0.50 USDC兑换为ETH(小数格式)

npx awal@latest trade 0.50 usdc eth
npx awal@latest trade 0.50 usdc eth

Swap 500000 atomic units of USDC for ETH

将500000原子单位的USDC兑换为ETH

npx awal@latest trade 500000 usdc eth
npx awal@latest trade 500000 usdc eth

Swap 0.01 ETH for USDC

将0.01 ETH兑换为USDC

npx awal@latest trade 0.01 eth usdc
npx awal@latest trade 0.01 eth usdc

Swap with custom slippage (2%)

自定义滑点(2%)进行兑换

npx awal@latest trade '$5' usdc eth --slippage 200
npx awal@latest trade '$5' usdc eth --slippage 200

Swap using contract addresses (decimals read from chain)

使用合约地址进行兑换(小数位数从链上读取)

npx awal@latest trade 100 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 0x4200000000000000000000000000000000000006
npx awal@latest trade 100 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 0x4200000000000000000000000000000000000006

Get JSON output

获取JSON格式输出

npx awal@latest trade '$1' usdc eth --json
undefined
npx awal@latest trade '$1' usdc eth --json
undefined

Prerequisites

前置条件

  • Must be authenticated (
    awal status
    to check)
  • Wallet must have sufficient balance of the source token
  • 必须完成身份验证(使用
    awal status
    检查状态)
  • 钱包中源代币的余额必须充足

Error Handling

错误处理

Common errors:
  • "Not authenticated" - Run
    awal auth login <email>
    first
  • "Invalid token" - Use a valid alias (usdc, eth, weth) or 0x address
  • "Cannot swap a token to itself" - From and to must be different
  • "Swap failed: TRANSFER_FROM_FAILED" - Insufficient balance or approval issue
  • "No liquidity" - Try a smaller amount or different token pair
  • "Amount has X decimals but token only supports Y" - Too many decimal places
常见错误:
  • "Not authenticated" - 先执行
    awal auth login <email>
    完成登录
  • "Invalid token" - 使用有效的代币别名(usdc, eth, weth)或0x格式的合约地址
  • "Cannot swap a token to itself" - 源代币和目标代币必须不同
  • "Swap failed: TRANSFER_FROM_FAILED" - 余额不足或授权问题
  • "No liquidity" - 尝试减小兑换金额或更换代币对
  • "Amount has X decimals but token only supports Y" - 金额小数位数超过代币支持的上限