pubfi-walletconnect-transactions
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePubFi WalletConnect Transactions
PubFi WalletConnect 交易
Connect wallet via QR code and execute blockchain transactions with WalletConnect
通过二维码连接钱包,使用WalletConnect执行区块链交易
Overview
概述
This skill enables users to:
- Connect their crypto wallet by scanning a WalletConnect QR code
- Execute blockchain transactions using standard ethers.TransactionRequest format
- Sign and broadcast transactions for any Ethereum-compatible operations
- Receive transaction confirmations with block explorer links
The skill uses WalletConnect v2 protocol for secure wallet connections and supports Ethereum and EVM-compatible chains.
该技能支持用户:
- 通过扫描WalletConnect二维码连接加密货币钱包
- 使用标准ethers.TransactionRequest格式执行区块链交易
- 为任何兼容Ethereum的操作签名并广播交易
- 接收带有区块浏览器链接的交易确认信息
本技能采用WalletConnect v2协议实现安全的钱包连接,支持Ethereum及兼容EVM的区块链。
Rules
规则
- No Mock Data: All transactions must be real blockchain operations
- User Confirmation Required: Never auto-sign; always request user signature approval
- Network Validation: Verify wallet is connected to the correct network before transaction
- Gas Estimation: Always estimate gas and show costs before signing
- Real-time Data: All transaction data must be current (prices, balances, etc.)
- Security First: Never request or store private keys; WalletConnect handles key management
- 禁止模拟数据:所有交易必须为真实区块链操作
- 需用户确认:绝不自动签名;始终请求用户批准签名
- 网络验证:交易前验证钱包是否连接到正确的网络
- Gas估算:签名前始终估算Gas并显示成本
- 实时数据:所有交易数据必须是最新的(价格、余额等)
- 安全优先:绝不请求或存储私钥;密钥管理由WalletConnect处理
Inputs
输入参数
Required Parameters
必填参数
- transaction: Standard ethers.TransactionRequest object
- Format: JSON object with transaction parameters
- Example:
typescript
{ to: '0x932460072495a5eaa5029289b342c6186715f5a0', value: ethers.parseEther('0.0001'), data: '0x...' // optional contract call data }
- transaction:标准ethers.TransactionRequest对象
- 格式:包含交易参数的JSON对象
- 示例:
typescript
{ to: '0x932460072495a5eaa5029289b342c6186715f5a0', value: ethers.parseEther('0.0001'), data: '0x...' // 可选的合约调用数据 }
Optional Parameters
可选参数
- chain: Blockchain network
- Default: (mainnet)
ethereum - Supported: ,
ethereum,polygon,arbitrum,optimismbase
- Default:
- chain:区块链网络
- 默认值:(主网)
ethereum - 支持的网络:,
ethereum,polygon,arbitrum,optimismbase
- 默认值:
Environment Variables
环境变量
-
WALLETCONNECT_PROJECT_ID (required): WalletConnect Cloud project ID
- Obtain from: https://cloud.walletconnect.com/
-
RPC_ENDPOINT_ETHEREUM (optional): Custom Ethereum RPC endpoint
- Default: Public RPC endpoint
-
WALLETCONNECT_PROJECT_ID(必填):WalletConnect Cloud项目ID
-
RPC_ENDPOINT_ETHEREUM(可选):自定义Ethereum RPC节点
- 默认值:公共RPC节点
Execution Workflow
执行流程
Step 1: Initialize WalletConnect Session
步骤1:初始化WalletConnect会话
- Load WalletConnect project ID from environment
- Create SignClient instance with metadata
- Generate pairing URI and display QR code in terminal
- Wait for user to scan QR code with wallet app
- Establish session and retrieve connected wallet address
- Verify connected chain matches requested chain
- 从环境变量加载WalletConnect项目ID
- 使用元数据创建SignClient实例
- 生成配对URI并在终端显示二维码
- 等待用户使用钱包应用扫描二维码
- 建立会话并获取连接的钱包地址
- 验证连接的链是否与请求的链匹配
Step 2: Prepare Transaction
步骤2:准备交易
- Accept standard ethers.TransactionRequest object
- Set default values if not provided:
- : Use connected wallet address
from - : Use selected chain ID
chainId - : Estimate gas if not provided
gasLimit - or EIP-1559 fees: Fetch current network fees
gasPrice
- Validate transaction parameters
- 接收标准ethers.TransactionRequest对象
- 若未提供则设置默认值:
- :使用连接的钱包地址
from - :使用所选链的ID
chainId - :若未提供则估算Gas
gasLimit - 或EIP-1559手续费:获取当前网络手续费
gasPrice
- 验证交易参数
Step 3: Request Signature
步骤3:请求签名
- Format transaction request according to WalletConnect JSON-RPC spec
- Display transaction summary to user:
- From: Connected wallet address
- To: Recipient or contract address
- Value: ETH amount
- Gas Limit: Estimated gas limit
- Send request via WalletConnect
eth_sendTransaction - Wait for user to approve/reject in wallet app
- Handle user response (approved or rejected)
- 根据WalletConnect JSON-RPC规范格式化交易请求
- 向用户显示交易摘要:
- 转出地址:连接的钱包地址
- 转入地址:接收方或合约地址
- 金额:ETH数量
- Gas限额:估算的Gas限额
- 通过WalletConnect发送请求
eth_sendTransaction - 等待用户在钱包应用中批准/拒绝
- 处理用户响应(批准或拒绝)
Step 4: Broadcast and Confirm
步骤4:广播与确认
- If approved, receive signed transaction hash from wallet
- Broadcast transaction to blockchain network
- Monitor transaction status (pending → confirmed)
- Wait for transaction confirmation (1+ blocks)
- Generate output report with transaction details
- 若获得批准,从钱包接收已签名的交易哈希
- 向区块链网络广播交易
- 监控交易状态(待处理→已确认)
- 等待交易确认(至少1个区块)
- 生成包含交易详情的输出报告
Step 5: Close Session (Optional)
步骤5:关闭会话(可选)
- Keep session active for subsequent transactions
- Allow user to disconnect when done
- Clean up resources and close WalletConnect client
- 保持会话活跃以支持后续交易
- 允许用户完成操作后断开连接
- 清理资源并关闭WalletConnect客户端
Output Format
输出格式
markdown
undefinedmarkdown
undefinedWalletConnect Transaction Report
WalletConnect 交易报告
Chain: {chain_name} | Wallet: {wallet_address} | Status: {status} Timestamp: {utc_timestamp}
链名称:{chain_name} | 钱包地址:{wallet_address} | 状态:{status} 时间戳:{utc_timestamp}
Transaction Details
交易详情
| Field | Value |
|---|---|
| From | {from_address} |
| To | {to_address} |
| Value | {value} ETH |
| Gas Used | {gas_used} |
| Transaction Hash | {tx_hash} |
| Block Number | {block_number} |
Block Explorer: View Transaction
| 字段 | 值 |
|---|---|
| 转出地址 | {from_address} |
| 转入地址 | {to_address} |
| 金额 | {value} ETH |
| 使用Gas | {gas_used} |
| 交易哈希 | {tx_hash} |
| 区块编号 | {block_number} |
区块浏览器:查看交易
Summary
摘要
{transaction_summary}
- Executed At: {utc_timestamp}
Generated by PubFi WalletConnect Transactions
undefined{transaction_summary}
- 执行时间:{utc_timestamp}
由 PubFi WalletConnect Transactions 生成
undefinedExample Output
示例输出
markdown
undefinedmarkdown
undefinedWalletConnect Transaction Report
WalletConnect 交易报告
Chain: Ethereum Mainnet | Wallet: 0x742d...8a9c | Status: SUCCESS Timestamp: 2026-02-09T10:30:45Z
链名称:Ethereum主网 | 钱包地址:0x742d...8a9c | 状态:成功 时间戳:2026-02-09T10:30:45Z
Transaction Details
交易详情
| Field | Value |
|---|---|
| From | 0x932460072495a5eaa5029289b342c6186715f5a0 |
| To | 0x932460072495a5eaa5029289b342c6186715f5a0 |
| Value | 0.0001 ETH |
| Gas Used | 21000 |
| Transaction Hash | 0xabc123...def456 |
| Block Number | 19123456 |
Block Explorer: View Transaction
| 字段 | 值 |
|---|---|
| 转出地址 | 0x932460072495a5eaa5029289b342c6186715f5a0 |
| 转入地址 | 0x932460072495a5eaa5029289b342c6186715f5a0 |
| 金额 | 0.0001 ETH |
| 使用Gas | 21000 |
| 交易哈希 | 0xabc123...def456 |
| 区块编号 | 19123456 |
区块浏览器:查看交易
Summary
摘要
Successfully executed transaction on Ethereum Mainnet
- Executed At: 2026-02-09T10:30:45Z
Generated by PubFi WalletConnect Transactions
undefined已在Ethereum主网成功执行交易
- 执行时间:2026-02-09T10:30:45Z
由 PubFi WalletConnect Transactions 生成
undefinedError Handling
错误处理
| Error Type | Condition | Action |
|---|---|---|
| Missing Project ID | | Return error message with setup instructions |
| Connection Timeout | No wallet connects within timeout period | Return error and suggest checking wallet app |
| User Rejection | User declines connection or signature | Return message indicating user cancelled action |
| Insufficient Balance | Wallet lacks funds for transaction + gas | Return error with current balance and required amount |
| Invalid Address | Recipient address malformed or invalid | Return error and request valid address format |
| Network Mismatch | Wallet on different chain than requested | Prompt user to switch network in wallet |
| Gas Estimation Failed | Cannot estimate gas for transaction | Return error with possible reasons (contract issue, etc.) |
| Transaction Reverted | On-chain transaction failed | Return revert reason and transaction hash for debugging |
| RPC Error | Network connectivity or RPC issues | Return error and suggest checking network connection |
| Unsupported Chain | Requested chain not supported | Return list of supported chains |
| Invalid Transaction | Transaction parameters invalid | Return error with validation details |
| 错误类型 | 触发条件 | 处理动作 |
|---|---|---|
| 缺少项目ID | 未设置 | 返回包含设置说明的错误信息 |
| 连接超时 | 超时时间内无钱包连接 | 返回错误并建议检查钱包应用 |
| 用户拒绝 | 用户拒绝连接或签名 | 返回提示用户已取消操作的信息 |
| 余额不足 | 钱包余额不足以支付交易+Gas费用 | 返回包含当前余额和所需金额的错误 |
| 无效地址 | 接收方地址格式错误或无效 | 返回错误并请求提供有效的地址格式 |
| 网络不匹配 | 钱包所在链与请求的链不一致 | 提示用户在钱包中切换网络 |
| Gas估算失败 | 无法估算交易的Gas费用 | 返回包含可能原因(如合约问题等)的错误 |
| 交易回滚 | 链上交易执行失败 | 返回回滚原因和交易哈希以用于调试 |
| RPC错误 | 网络连接或RPC节点问题 | 返回错误并建议检查网络连接 |
| 不支持的链 | 请求的链未被支持 | 返回支持的链列表 |
| 无效交易 | 交易参数无效 | 返回包含验证详情的错误 |
Supported Operations
支持的操作
This skill accepts any valid ethers.TransactionRequest, supporting:
- ETH Transfers: Simple value transfers
- Contract Interactions: Any contract call via field
data - ERC20 Operations: Token transfers, approvals (user provides encoded data)
- DeFi Interactions: Any protocol interaction (user provides encoded data)
- Custom Transactions: Any Ethereum-compatible transaction
本技能接受任何有效的ethers.TransactionRequest,支持:
- ETH转账:简单的价值转移
- 合约交互:通过字段调用任何合约
data - ERC20操作:代币转账、授权(用户提供编码数据)
- DeFi交互:任何协议交互(用户提供编码数据)
- 自定义交易:任何兼容Ethereum的交易
Security Considerations
安全注意事项
- Never Store Private Keys: All key management handled by user's wallet
- Verify Addresses: Always display full addresses before signing
- Gas Limits: Set reasonable limits to prevent excessive costs
- Contract Verification: Only interact with verified contracts
- Amount Validation: Double-check amounts to prevent decimal errors
- 绝不存储私钥:所有密钥管理由用户的钱包处理
- 验证地址:签名前始终显示完整地址
- Gas限额:设置合理的限额以避免过高成本
- 合约验证:仅与已验证的合约交互
- 金额验证:仔细检查金额以避免小数错误
Dependencies
依赖项
- @walletconnect/sign-client: WalletConnect v2 SDK
- ethers: Ethereum library for transaction building
- qrcode-terminal: Display QR codes in CLI
- dotenv: Environment variable management
- @walletconnect/sign-client:WalletConnect v2 SDK
- ethers:用于构建交易的Ethereum库
- qrcode-terminal:在CLI中显示二维码
- dotenv:环境变量管理工具
Implementation Notes
实现说明
- This skill requires Node.js runtime (v16+ recommended)
- Scripts are written in TypeScript and compiled to JavaScript
- Users must have a WalletConnect-compatible wallet (MetaMask, Rainbow, etc.)
- Session can persist for multiple transactions until disconnected
- All timestamps are in UTC with ISO 8601 format
- Transaction encoding/preparation is handled by the caller
- The skill focuses on core WalletConnect connection and transaction signing
- 本技能需要Node.js运行环境(推荐v16+)
- 脚本使用TypeScript编写并编译为JavaScript
- 用户必须拥有兼容WalletConnect的钱包(如MetaMask、Rainbow等)
- 会话可保持活跃以支持多笔交易,直到断开连接
- 所有时间戳均为UTC时区,采用ISO 8601格式
- 交易编码/准备工作由调用方处理
- 本技能专注于核心的WalletConnect连接和交易签名功能
Usage Example
使用示例
typescript
import { WalletConnectTransactionManager } from './walletconnect_transactions';
import { ethers } from 'ethers';
const manager = new WalletConnectTransactionManager('ethereum');
// Connect wallet
await manager.connect();
// Send ETH
const tx: ethers.TransactionRequest = {
to: '0x932460072495a5eaa5029289b342c6186715f5a0',
value: ethers.parseEther('0.0001')
};
const result = await manager.sendTransaction(tx);
// Generate report
const report = manager.generateReport(result, tx);
console.log(report);
// Disconnect
await manager.disconnect();typescript
import { WalletConnectTransactionManager } from './walletconnect_transactions';
import { ethers } from 'ethers';
const manager = new WalletConnectTransactionManager('ethereum');
// 连接钱包
await manager.connect();
// 发送ETH
const tx: ethers.TransactionRequest = {
to: '0x932460072495a5eaa5029289b342c6186715f5a0',
value: ethers.parseEther('0.0001')
};
const result = await manager.sendTransaction(tx);
// 生成报告
const report = manager.generateReport(result, tx);
console.log(report);
// 断开连接
await manager.disconnect();