🔐 Base Wallet - Crypto Identity for AI Agents
Every autonomous agent needs a wallet. Create one without human help.
TL;DR: Programmatic wallet creation on Base/Ethereum. SIWE auth, balance checks, transactions.
Why Base Wallet?
- - True autonomy — Your agent creates and controls its own wallet
- No browser needed — Pure CLI, no extensions or popups
- SIWE ready — Sign-In with Ethereum for Web3 services
- Secure by default — Environment variables, no plaintext keys
Create and manage Base chain (Ethereum-compatible) wallets programmatically.
⚠️ Security First
| ✅ DO | ❌ DON'T |
|---|
| Use environment variables for private keys | Store private keys in plain text files |
| Set wallet files to chmod 600 |
Commit wallet files to git |
| Use
--env mode (recommended) | Use
console.log(privateKey) |
| Back up mnemonics
offline | Share private keys or mnemonics |
Quick Start
Create a New Wallet (Recommended)
CODEBLOCK0
Then copy to your shell or .env file.
Create with File Storage (Opt-in)
CODEBLOCK1
⚠️ This stores private key in ~/.openclaw/wallets/my-agent.json
Usage Examples
Load Wallet from Environment
CODEBLOCK2
Load from Mnemonic
CODEBLOCK3
Check Balance
CODEBLOCK4
Sign Message (SIWE)
CODEBLOCK5
Send Transaction
CODEBLOCK6
Scripts
| Script | Description |
|---|
| INLINECODE4 | Create wallet, output as env vars (recommended) |
| INLINECODE5 |
Create wallet, save to file (opt-in) |
|
create-wallet.js --json | Create wallet, output as JSON |
|
basemail-register.js [name] | Register for BaseMail email |
|
check-balance.js [address] | Check wallet balance |
BaseMail Integration
Register for a @basemail.ai email using your wallet signature.
CODEBLOCK7
Network Configuration
| Network | Chain ID | RPC URL |
|---|
| Base Mainnet | 8453 | https://mainnet.base.org |
| Base Sepolia |
84532 | https://sepolia.base.org |
📝 Audit Logging
Operations are logged to ~/.base-wallet/audit.log.
Secure Storage Pattern
CODEBLOCK8
If you must store to file (not recommended):
CODEBLOCK9
.gitignore
Add to your project's .gitignore:
CODEBLOCK10
Dependencies
CODEBLOCK11
Changelog
v1.1.0 (2026-02-08)
- - 🔐 Security: Changed create-wallet.js to opt-in file storage
- ✨ Added --env mode (recommended)
- 📝 Added audit logging
- ⚠️ Removed console.log(privateKey) from examples
- 📄 Enhanced security documentation
v1.0.0
🔐 Base Wallet - AI代理的加密身份
每个自主代理都需要一个钱包。无需人工帮助即可创建。
概要: 在Base/Ethereum上以编程方式创建钱包。支持SIWE认证、余额查询、交易操作。
为什么选择Base Wallet?
- - 真正的自主性 — 您的代理自主创建并控制自己的钱包
- 无需浏览器 — 纯命令行操作,无需扩展或弹窗
- SIWE就绪 — 支持以太坊登录Web3服务
- 默认安全 — 使用环境变量,不存储明文密钥
以编程方式创建和管理Base链(兼容以太坊)钱包。
⚠️ 安全第一
| ✅ 正确做法 | ❌ 错误做法 |
|---|
| 使用环境变量存储私钥 | 将私钥存储在纯文本文件中 |
| 将钱包文件权限设置为chmod 600 |
将钱包文件提交到git |
| 使用--env模式(推荐) | 使用console.log(privateKey) |
|
离线备份助记词 | 分享私钥或助记词 |
快速开始
创建新钱包(推荐)
bash
以环境变量格式输出(最安全)
node scripts/create-wallet.js --env
输出示例:
export WALLET_ADDRESS=0x...
export PRIVATE_KEY=0x...
然后复制到您的shell或.env文件中。
创建并存储为文件(可选)
bash
仅当您需要基于文件的存储时
node scripts/create-wallet.js --managed my-agent
⚠️ 这会将私钥存储在~/.openclaw/wallets/my-agent.json中
使用示例
从环境变量加载钱包
javascript
const { ethers } = require(ethers);
// ✅ 安全:从环境变量加载
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);
console.log(地址:, wallet.address);
// ❌ 切勿:console.log(私钥:, wallet.privateKey);
从助记词加载
javascript
const wallet = ethers.Wallet.fromPhrase(process.env.MNEMONIC);
查询余额
javascript
const provider = new ethers.JsonRpcProvider(https://mainnet.base.org);
const balance = await provider.getBalance(wallet.address);
console.log(余额:, ethers.formatEther(balance), ETH);
签名消息(SIWE)
javascript
const message = example.com 希望您使用您的以太坊账户登录:
${wallet.address}
登录消息
URI: https://example.com
版本: 1
链ID: 8453
随机数: ${nonce}
发布时间: ${new Date().toISOString()};
const signature = await wallet.signMessage(message);
发送交易
javascript
const provider = new ethers.JsonRpcProvider(https://mainnet.base.org);
const connectedWallet = wallet.connect(provider);
const tx = await connectedWallet.sendTransaction({
to: recipientAddress,
value: ethers.parseEther(0.001)
});
const receipt = await tx.wait();
console.log(交易哈希:, tx.hash);
脚本
| 脚本 | 描述 |
|---|
| create-wallet.js --env | 创建钱包,输出为环境变量(推荐) |
| create-wallet.js --managed [名称] |
创建钱包,保存到文件(可选) |
| create-wallet.js --json | 创建钱包,输出为JSON |
| basemail-register.js [名称] | 注册BaseMail邮箱 |
| check-balance.js [地址] | 查询钱包余额 |
BaseMail集成
使用您的钱包签名注册@basemail.ai邮箱。
bash
如果使用环境变量:
PRIVATE_KEY=0x... node scripts/basemail-register.js
如果使用托管钱包:
node scripts/basemail-register.js my-agent
网络配置
| 网络 | 链ID | RPC URL |
|---|
| Base主网 | 8453 | https://mainnet.base.org |
| Base Sepolia测试网 |
84532 | https://sepolia.base.org |
📝 审计日志
操作记录到~/.base-wallet/audit.log。
安全存储模式
javascript
// ✅ 推荐:使用环境变量
const privateKey = process.env.PRIVATE_KEY;
if (!privateKey) {
throw new Error(未设置PRIVATE_KEY环境变量);
}
const wallet = new ethers.Wallet(privateKey);
// ❌ 避免:将私钥存储在代码或文件中
如果必须存储到文件(不推荐):
javascript
const fs = require(fs);
const path = require(path);
// 使用受限权限存储
const filepath = path.join(process.env.HOME, .openclaw, wallets, wallet.json);
fs.writeFileSync(filepath, JSON.stringify({
address: wallet.address,
// 仅在绝对必要时存储
privateKey: wallet.privateKey
}), { mode: 0o600 }); // 仅所有者可读写
.gitignore
添加到项目的.gitignore:
gitignore
钱包文件 - 切勿提交!
.openclaw/
*.wallet.json
*.mnemonic
private-key*
依赖
bash
npm install ethers
更新日志
v1.1.0 (2026-02-08)
- - 🔐 安全:将create-wallet.js改为可选文件存储
- ✨ 新增--env模式(推荐)
- 📝 新增审计日志
- ⚠️ 从示例中移除console.log(privateKey)
- 📄 增强安全文档
v1.0.0