网淘吧来吧,欢迎您!

Base Wallet技能使用说明

2026-04-01 新闻来源:网淘吧 围观:19
电脑广告
手机广告

🔐 Base钱包——AI代理的加密身份

每个自主代理都需要一个钱包。无需人工协助即可创建。

摘要:在Base/以太坊上以编程方式创建钱包。支持SIWE身份验证、余额查询、交易处理。

Base Wallet

为何选择Base钱包?

  • 真正的自主性——您的代理可自主创建并控制其专属钱包
  • 无需浏览器——纯命令行操作,无需扩展插件或弹窗
  • SIWE就绪——支持以太坊登录,无缝接入Web3服务
  • 默认安全防护——采用环境变量存储,杜绝私钥明文暴露

通过编程方式创建并管理Base链(兼容以太坊)钱包。


⚠️ 安全第一

✅ 务必❌ 禁止
使用环境变量存储私钥将私钥存储在明文文件中
将钱包文件设置为chmod 600将钱包文件提交到 git
使用--env模式(推荐)使用console.log(privateKey)
离线备份助记词共享私钥或助记词快速开始

创建新钱包(推荐)

然后复制到您的 shell 或

# Output as environment variable format (safest)
node scripts/create-wallet.js --env

# Output example:
# export WALLET_ADDRESS="0x..."
# export PRIVATE_KEY="0x..."

.env文件中。使用文件存储创建(可选)

⚠️ 这将私钥存储在

# Only if you need file-based storage
node scripts/create-wallet.js --managed my-agent

~/.openclaw/wallets/my-agent.json使用示例


从环境变量加载钱包

从助记词加载

const { ethers } = require('ethers');

// ✅ SECURE: Load from environment variable
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);
console.log('Address:', wallet.address);
// ❌ NEVER: console.log('Private Key:', wallet.privateKey);

检查余额

const wallet = ethers.Wallet.fromPhrase(process.env.MNEMONIC);

签名消息(SIWE)

const provider = new ethers.JsonRpcProvider('https://mainnet.base.org');
const balance = await provider.getBalance(wallet.address);
console.log('Balance:', ethers.formatEther(balance), 'ETH');

Sign Message (SIWE)

const message = `example.com wants you to sign in with your Ethereum account:
${wallet.address}

Sign in message

URI: https://example.com
Version: 1
Chain ID: 8453
Nonce: ${nonce}
Issued At: ${new Date().toISOString()}`;

const signature = await wallet.signMessage(message);

发送交易

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:', 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 邮箱。

# If using environment variable:
PRIVATE_KEY="0x..." node scripts/basemail-register.js

# If using managed wallet:
node scripts/basemail-register.js my-agent

网络配置

网络链IDRPC URL
Base 主网8453https://mainnet.base.org
基础Sepolia84532https://sepolia.base.org

📝 审计日志记录

操作被记录到~/.base-wallet/audit.log


安全存储模式

// ✅ Recommended: Use environment variables
const privateKey = process.env.PRIVATE_KEY;
if (!privateKey) {
  throw new Error('PRIVATE_KEY environment variable not set');
}
const wallet = new ethers.Wallet(privateKey);

// ❌ Avoid: Storing private keys in code or files

如果您必须存储到文件(不推荐):

const fs = require('fs');
const path = require('path');

// Store with restricted permissions
const filepath = path.join(process.env.HOME, '.openclaw', 'wallets', 'wallet.json');
fs.writeFileSync(filepath, JSON.stringify({ 
  address: wallet.address,
  // Only store if absolutely necessary
  privateKey: wallet.privateKey
}), { mode: 0o600 }); // Owner read/write only

.gitignore

添加到您项目的.gitignore

# Wallet files - NEVER commit!
.openclaw/
*.wallet.json
*.mnemonic
private-key*

依赖项

npm install ethers

更新日志

v1.1.0 (2026-02-08)

  • 🔐 安全性:将 create-wallet.js 更改为选择加入文件存储
  • ✨ 新增 --env 模式(推荐)
  • 📝 新增审计日志记录
  • ⚠️ 从示例中移除了 console.log(privateKey)
  • 📄 增强了安全文档

v1.0.0

  • 🎉 初始版本发布

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏

文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第393833名访客 今日有1篇新文章/评论