trade
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTrading Tokens
代币交易
Use the 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网络上进行代币兑换。交易前必须完成身份验证。
npx awal@latest tradeConfirm wallet is initialized and authed
确认钱包已初始化并完成验证
bash
npx awal@latest statusIf the wallet is not authenticated, refer to the skill.
authenticate-walletbash
npx awal@latest status如果钱包未验证,请参考技能文档。
authenticate-walletCommand Syntax
命令语法
bash
npx awal@latest trade <amount> <from> <to> [options]bash
npx awal@latest trade <amount> <from> <to> [options]Arguments
参数说明
| Argument | Description |
|---|---|
| Amount to swap (see Amount Formats below) |
| Source token: alias (usdc, eth, weth) or contract address (0x...) |
| Destination token: alias (usdc, eth, weth) or contract address (0x...) |
| 参数 | 描述 |
|---|---|
| 兑换金额(详见下方的金额格式) |
| 源代币:别名(usdc, eth, weth)或合约地址(0x...) |
| 目标代币:别名(usdc, eth, weth)或合约地址(0x...) |
Amount Formats
金额格式
The amount can be specified in multiple formats:
| Format | Example | Description |
|---|---|---|
| Dollar prefix | | USD notation (decimals based on token) |
| Decimal | | Human-readable with decimal point |
| Whole number | | Interpreted as whole tokens |
| Atomic units | | Large integers treated as atomic units |
Auto-detection: Large integers without a decimal point are treated as atomic units. For example, for USDC (6 decimals) = $0.50.
500000Decimals: For known tokens (usdc=6, eth=18, weth=18), decimals are automatic. For arbitrary contract addresses, decimals are read from the token contract.
金额支持多种格式:
| 格式 | 示例 | 描述 |
|---|---|---|
| 美元前缀 | | 美元表示法(小数位数基于代币规则) |
| 小数格式 | | 带小数点的易读格式 |
| 整数格式 | | 被解析为完整代币数量 |
| 原子单位 | | 大整数将被视为原子单位 |
自动识别:不带小数点的大整数会被视为原子单位。例如,USDC(6位小数)的原子单位等价于0.50美元。
500000小数位数:对于已知代币(usdc=6位,eth=18位,weth=18位),小数位数自动适配。对于自定义合约地址,小数位数将从代币合约中读取。
Options
可选参数
| Option | Description |
|---|---|
| Blockchain network (default: base) |
| Slippage tolerance in basis points (100 = 1%) |
| Output result as JSON |
| 选项 | 描述 |
|---|---|
| 区块链网络(默认值:base) |
| 滑点容忍度,单位为基点(100基点=1%) |
| 以JSON格式输出结果 |
Token Aliases
代币别名
| Alias | Token | Decimals | Address |
|---|---|---|---|
| usdc | USDC | 6 | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| eth | ETH | 18 | 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE |
| weth | WETH | 18 | 0x4200000000000000000000000000000000000006 |
IMPORTANT: Always single-quote amounts that use to prevent bash variable expansion (e.g. not ).
$'$1.00'$1.00| 别名 | 代币 | 小数位数 | 合约地址 |
|---|---|---|---|
| usdc | USDC | 6 | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| eth | ETH | 18 | 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE |
| weth | WETH | 18 | 0x4200000000000000000000000000000000000006 |
重要提示:使用美元前缀的金额时,务必用单引号包裹,避免bash变量解析(例如使用而非)。
'$1.00'$1.00Examples
示例
bash
undefinedbash
undefinedSwap $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
undefinednpx awal@latest trade '$1' usdc eth --json
undefinedPrerequisites
前置条件
- Must be authenticated (to check)
awal status - Wallet must have sufficient balance of the source token
- 必须完成身份验证(使用检查状态)
awal status - 钱包中源代币的余额必须充足
Error Handling
错误处理
Common errors:
- "Not authenticated" - Run first
awal auth login <email> - "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" - 金额小数位数超过代币支持的上限