chainai — Ethereum Transactions Skill
⚠️ DISCLAIMER — USE AT YOUR OWN RISK
This tool interacts with real blockchain networks and real funds. The author(s) of this tool are not responsible for any loss of funds, damages, or unintended consequences arising from its use. By using this skill, you accept full responsibility for all operations performed.
🔒 MANDATORY SECURITY REQUIREMENTS FOR ALL AGENTS
Agents MUST take every possible action to safeguard CHAINAI_PRIVATE_KEY and all other private keys from exposure. Specifically:
- 1. NEVER log, print, echo, or display private keys in any user-facing output, logs, chat messages, or debug traces.
- NEVER store private keys in plain text files, version control, or any persistent storage that is not explicitly encrypted and access-controlled.
- NEVER transmit private keys over unencrypted channels or include them in URLs, query parameters, or request bodies to third-party services.
- NEVER include private keys in error messages, stack traces, or diagnostic output.
- ALWAYS prefer the
CHAINAI_PRIVATE_KEY environment variable over the -k flag to minimize key exposure in shell history and process listings. - ALWAYS treat private keys as the highest-sensitivity secret. A leaked private key grants full, irrevocable control over all funds in the associated wallet.
� ADDRESS FORMATTING RULES
- 1. Always use ERC-55 checksum addresses when passing addresses to any command (wallet addresses, token contract addresses, recipient addresses, etc.).
- If you do not know the correct checksum, use all lowercase addresses (e.g.
0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 instead of guessing the mixed-case checksum). - Never guess a token contract address. If you are unsure of the correct token contract address, always ask the user to provide it. Do not fabricate or assume token addresses.
�🚀 BEFORE YOU BEGIN
- 1. Verify your private key is set: Run
npx chainai@0.0.10 who-am-i to confirm CHAINAI_PRIVATE_KEY is properly configured and resolves to the expected address before proceeding with any other command. - No private key? Use
npx chainai@0.0.10 gen-wallet to generate a new wallet. Save the returned private key securely (e.g. as an environment variable) — it will not be shown again. - Fund your account: You must deposit the necessary funds (native tokens for gas + any tokens you intend to send or swap) to the wallet address before using
send, swap, or any transaction-submitting command. Commands will fail if the account has insufficient balance.
Overview
INLINECODE9 is a non-interactive CLI tool for Ethereum and EVM-compatible blockchain operations. It handles signing, sending, broadcasting transactions, token swaps (1inch Fusion), balance queries, and wallet generation.
Invocation
CODEBLOCK0
- - Runtime: Node.js (>=18)
- Non-interactive: All parameters must be passed as arguments or flags. Never prompts for input.
Authentication
Most commands accept a private key via:
- -
-k, --private-key <key> flag (hex string starting with 0x) - INLINECODE12 environment variable (fallback when
-k is not provided)
Supported Networks
| Name | Chain ID | Aliases | Native Token |
|---|
| Ethereum | 1 | INLINECODE14 , ethereum, INLINECODE16 | ETH |
| BNB Smart Chain |
56 |
bsc,
binance,
bnb | BNB |
Use -n, --network to specify a network by name, alias, or chain ID. Defaults to mainnet.
Exit Codes
| Code | Meaning |
|---|
| INLINECODE22 | Operation completed successfully. |
| INLINECODE23 |
Operation failed. Inspect
stderr for a structured error message. |
Message Contract
Success (stdout)
CODEBLOCK1
Errors (stderr)
CODEBLOCK2
| Error Code | Description | Agent Action |
|---|
| INLINECODE25 | Malformed or missing required fields. | Re-validate input parameters and retry. |
| INLINECODE26 |
Operation could not be completed. Description contains failure details. | Inspect description and adjust approach. |
|
TIMEOUT | Operation exceeded the allowed time limit. | Retry with a longer timeout or simplify the request. |
|
UNKNOWN | Unexpected error. | Report to orchestrator for manual inspection. |
Retry Strategy
For TIMEOUT and EXECUTION_FAILED errors, retry up to 2 times with exponential backoff before escalating.
Commands
gen-wallet
Generate a new random wallet (private key and address).
CODEBLOCK3
Options: None.
Output (stdout):
CODEBLOCK4
Usage instructions are printed to stderr.
who-am-i
Return the Ethereum address derived from a private key.
CODEBLOCK5
Options:
| Flag | Required | Description |
|---|
| INLINECODE34 | No | Private key. Falls back to CHAINAI_PRIVATE_KEY. |
Output (stdout):
CODEBLOCK6
sign-message
Sign a message using EIP-191 personal sign.
CODEBLOCK7
Options:
| Flag | Required | Description |
|---|
| INLINECODE37 | No | Private key. Falls back to CHAINAI_PRIVATE_KEY. |
| INLINECODE39 |
Yes | The message to sign. |
|
-r, --raw | No | Treat message as raw hex data (
0x-prefixed). |
Output (stdout):
CODEBLOCK8
sign
⚠️ CRITICAL SECURITY WARNING: Signs a raw hash (secp256k1) without any prefix. The resulting signature can authorize any on-chain action. Use sign-message instead unless raw hash signing is explicitly required. Before using, verify the hash is legitimate and no safer alternative exists.
CODEBLOCK9
Options:
| Flag | Required | Description |
|---|
| INLINECODE44 | No | Private key. Falls back to CHAINAI_PRIVATE_KEY. |
| INLINECODE46 |
Yes | The hash to sign (
0x-prefixed hex string). |
Output (stdout):
CODEBLOCK10
sign-typed-data
Sign EIP-712 typed data.
CODEBLOCK11
Options:
| Flag | Required | Description |
|---|
| INLINECODE49 | No | Private key. Falls back to CHAINAI_PRIVATE_KEY. |
| INLINECODE51 |
Yes | EIP-712 typed data as JSON with
domain,
types,
primaryType,
message. |
Data Format:
CODEBLOCK12
Output (stdout):
CODEBLOCK13
sign-transaction
Sign a transaction (legacy, EIP-2930, or EIP-1559). Returns a serialized signed transaction ready to broadcast.
CODEBLOCK14
Options:
| Flag | Required | Description |
|---|
| INLINECODE57 | No | Private key. Falls back to CHAINAI_PRIVATE_KEY. |
| INLINECODE59 |
Yes | Transaction object as JSON string. |
Transaction Formats:
Legacy:
CODEBLOCK15
EIP-1559:
CODEBLOCK16
Omit to for contract deployment. Numeric values can be strings or numbers.
Output (stdout):
CODEBLOCK17
get-balance
Get native or ERC-20 token balances.
CODEBLOCK18
Options:
| Flag | Required | Description |
|---|
| INLINECODE62 | No | Wallet address. Falls back to address derived from CHAINAI_PRIVATE_KEY. |
| INLINECODE64 |
No | Network (default:
mainnet). |
|
-t, --token <token> | No | Token contract address. Default:
0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee (native). |
|
--all | No | Return all token balances (native + ERC-20).
-t is ignored when set. |
Output (stdout) — single token:
CODEBLOCK19
With --all, returns an array of balance objects.
send
Build and sign a transaction to send native tokens or ERC-20 tokens. Automatically fetches nonce, gas, and fee data from the network.
CODEBLOCK20
Options:
| Flag | Required | Description |
|---|
| INLINECODE72 | No | Private key. Falls back to CHAINAI_PRIVATE_KEY. |
| INLINECODE74 |
Yes | Recipient address. |
|
-t, --token <token> | Yes | Token contract address. Use
0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee for native. |
|
--amount <amount> | Yes | Amount in human-readable units (e.g.
"1.5"). |
|
-n, --network <network> | No | Network (default:
mainnet). |
|
-b, --broadcast | No | Automatically broadcast after signing. |
Output (stdout):
CODEBLOCK21
broadcast
Broadcast a serialized signed transaction to the network.
CODEBLOCK22
Options:
| Flag | Required | Description |
|---|
| INLINECODE83 | Yes | Serialized signed transaction (0x-prefixed). |
| INLINECODE85 |
No | Network (default:
mainnet). |
Output (stdout):
CODEBLOCK23
tx-status
Get the status of a transaction by hash.
CODEBLOCK24
Options:
| Flag | Required | Description |
|---|
| INLINECODE88 | Yes | Transaction hash (0x-prefixed, 32 bytes). |
| INLINECODE90 |
No | Network (default:
mainnet). |
Output (stdout):
CODEBLOCK25
For pending transactions, status is "pending" and blockNumber, from, to, gasUsed, effectiveGasPrice will be null.
swap
Swap tokens via 1inch Fusion. Gets a quote first, then optionally submits the order. Use -y to skip confirmation and submit immediately.
CODEBLOCK26
Use 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee for native tokens.
Options:
| Flag | Required | Description |
|---|
| INLINECODE103 | No | Private key. Falls back to CHAINAI_PRIVATE_KEY. |
| INLINECODE105 |
Yes | Source token contract address. |
|
--to-token <address> | Yes | Destination token contract address. |
|
--amount <amount> | Yes | Amount in human-readable units (e.g.
"1.5"). |
|
-n, --network <network> | No | Network (default:
mainnet). |
|
-y, --yes | No | Skip confirmation prompt and submit immediately. |
Output (stdout) — quote:
CODEBLOCK27
Output (stdout) — order submission:
CODEBLOCK28
INLINECODE112 is non-null only when an ERC-20 token approval was required. For native token swaps or already-approved tokens, it is null.
swap-order-status
Get the status of a 1inch Fusion swap order by its order hash.
CODEBLOCK29
Options:
| Flag | Required | Description |
|---|
| INLINECODE115 | No | Private key. Falls back to CHAINAI_PRIVATE_KEY. |
| INLINECODE117 |
Yes | Order hash returned from the
swap command. |
|
-n, --network <network> | No | Network (default:
mainnet). |
Output (stdout):
CODEBLOCK30
Possible status values: "pending", "filled", "expired", "cancelled". For pending/cancelled orders, finalToAmount is null and fills is empty.
chainai — 以太坊交易技能
⚠️ 免责声明 — 使用风险自负
此工具与真实的区块链网络和真实资金交互。本工具的作者不对任何资金损失、损害或使用本工具产生的意外后果负责。使用此技能即表示您对所有执行的操作承担全部责任。
🔒 所有代理的强制性安全要求
代理必须采取一切可能的措施保护 CHAINAIPRIVATEKEY 和所有其他私钥不被泄露。具体来说:
- 1. 绝不在任何面向用户的输出、日志、聊天消息或调试跟踪中记录、打印、回显或显示私钥。
- 绝不以明文形式将私钥存储在文本文件、版本控制或任何未经明确加密和访问控制的持久存储中。
- 绝不通过未加密通道传输私钥,或将其包含在URL、查询参数或发送给第三方服务的请求体中。
- 绝不将私钥包含在错误消息、堆栈跟踪或诊断输出中。
- 始终优先使用 CHAINAIPRIVATEKEY 环境变量,而非 -k 标志,以最小化私钥在shell历史记录和进程列表中的暴露。
- 始终将私钥视为最高敏感度的机密。 泄露的私钥将授予对关联钱包中所有资金的完全、不可撤销的控制权。
📝 地址格式化规则
- 1. 始终使用 ERC-55 校验和地址,在向任何命令传递地址时(钱包地址、代币合约地址、接收方地址等)。
- 如果您不知道正确的校验和,请使用全小写地址(例如 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,而不是猜测大小写混合的校验和)。
- 切勿猜测代币合约地址。 如果您不确定正确的代币合约地址,始终询问用户提供。不要编造或假设代币地址。
🚀 开始之前
- 1. 验证您的私钥已设置:运行 npx chainai@0.0.10 who-am-i 确认 CHAINAIPRIVATEKEY 已正确配置并解析为预期地址,然后再执行任何其他命令。
- 没有私钥? 使用 npx chainai@0.0.10 gen-wallet 生成新钱包。安全保存返回的私钥(例如作为环境变量)——它将不再显示。
- 为您的账户充值:在使用 send、swap 或任何提交交易的命令之前,您必须将必要的资金(用于gas的原生代币 + 您打算发送或交换的任何代币)存入钱包地址。如果账户余额不足,命令将失败。
概述
chainai 是一个用于以太坊和EVM兼容区块链操作的非交互式CLI工具。它处理签名、发送、广播交易、代币交换(1inch Fusion)、余额查询和钱包生成。
调用方式
npx chainai@0.0.10 [options]
- - 运行环境:Node.js (>=18)
- 非交互式:所有参数必须作为参数或标志传递。从不提示输入。
身份验证
大多数命令通过以下方式接受私钥:
- - -k, --private-key 标志(以 0x 开头的十六进制字符串)
- CHAINAIPRIVATEKEY 环境变量(当未提供 -k 时的回退方式)
支持的网络
| 名称 | 链ID | 别名 | 原生代币 |
|---|
| 以太坊 | 1 | mainnet, ethereum, eth | ETH |
| BNB智能链 |
56 | bsc, binance, bnb | BNB |
使用 -n, --network 通过名称、别名或链ID指定网络。默认为 mainnet。
退出码
操作失败。检查 stderr 获取结构化错误消息。 |
消息约定
成功(stdout)
CHAINAI_OK: <描述>
{ ... }
错误(stderr)
CHAINAI_ERR: <错误码> — <描述>
| 错误码 | 描述 | 代理操作 |
|---|
| INVALIDINPUT | 格式错误或缺少必填字段。 | 重新验证输入参数并重试。 |
| EXECUTIONFAILED |
操作无法完成。描述包含失败详情。 | 检查描述并调整方法。 |
| TIMEOUT | 操作超过允许的时间限制。 | 使用更长的超时时间重试或简化请求。 |
| UNKNOWN | 意外错误。 | 报告给编排器进行手动检查。 |
重试策略
对于 TIMEOUT 和 EXECUTION_FAILED 错误,在升级前最多重试2次,使用指数退避。
命令
gen-wallet
生成一个新的随机钱包(私钥和地址)。
bash
npx chainai@0.0.10 gen-wallet
选项:无。
输出(stdout):
json
{
address: 0x...,
privateKey: 0x...
}
使用说明打印到 stderr。
who-am-i
返回从私钥派生的以太坊地址。
bash
npx chainai@0.0.10 who-am-i -k 0xKEY
或
CHAINAI
PRIVATEKEY=0xKEY npx chainai@0.0.10 who-am-i
选项:
| 标志 | 必需 | 描述 |
|---|
| -k, --private-key <key> | 否 | 私钥。回退到 CHAINAIPRIVATEKEY。 |
输出(stdout):
json
{
address: 0x...
}
sign-message
使用 EIP-191 个人签名签署消息。
bash
npx chainai@0.0.10 sign-message -k 0xKEY -m Hello World
npx chainai@0.0.10 sign-message -k 0xKEY -m 0x68656c6c6f --raw
选项:
| 标志 | 必需 | 描述 |
|---|
| -k, --private-key <key> | 否 | 私钥。回退到 CHAINAIPRIVATEKEY。 |
| -m, --message <message> |
是 | 要签署的消息。 |
| -r, --raw | 否 | 将消息视为原始十六进制数据(0x 前缀)。 |
输出(stdout):
json
{
address: 0x...,
message: <原始消息>,
signature: 0x...
}
sign
⚠️ 关键安全警告:签署原始哈希(secp256k1),不带任何前缀。生成的签名可以授权任何链上操作。除非明确需要原始哈希签名,否则请使用 sign-message。 在使用前,验证哈希是合法的且没有更安全的替代方案。
bash
npx chainai@0.0.10 sign -k 0xKEY -h 0xHASH
选项:
| 标志 | 必需 | 描述 |
|---|
| -k, --private-key <key> | 否 | 私钥。回退到 CHAINAIPRIVATEKEY。 |
| -h, --hash <hash> |
是 | 要签署的哈希(0x 前缀的十六进制字符串)。|
输出(stdout):
json
{
address: 0x...,
hash: 0x...,
signature: 0x...
}
sign-typed-data
签署 EIP-712 类型化数据。
bash
npx chainai@0.0.10 sign-typed-data -k 0xKEY -d
选项:
| 标志 | 必需 | 描述 |
|---|
| -k, --private-key <key> |