pubfi-walletconnect-transactions

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PubFi WalletConnect Transactions

PubFi WalletConnect 交易

Connect wallet via QR code and execute blockchain transactions with WalletConnect
通过二维码连接钱包,使用WalletConnect执行区块链交易

Overview

概述

This skill enables users to:
  1. Connect their crypto wallet by scanning a WalletConnect QR code
  2. Execute blockchain transactions using standard ethers.TransactionRequest format
  3. Sign and broadcast transactions for any Ethereum-compatible operations
  4. Receive transaction confirmations with block explorer links
The skill uses WalletConnect v2 protocol for secure wallet connections and supports Ethereum and EVM-compatible chains.
该技能支持用户:
  1. 通过扫描WalletConnect二维码连接加密货币钱包
  2. 使用标准ethers.TransactionRequest格式执行区块链交易
  3. 为任何兼容Ethereum的操作签名并广播交易
  4. 接收带有区块浏览器链接的交易确认信息
本技能采用WalletConnect v2协议实现安全的钱包连接,支持Ethereum及兼容EVM的区块链。

Rules

规则

  1. No Mock Data: All transactions must be real blockchain operations
  2. User Confirmation Required: Never auto-sign; always request user signature approval
  3. Network Validation: Verify wallet is connected to the correct network before transaction
  4. Gas Estimation: Always estimate gas and show costs before signing
  5. Real-time Data: All transaction data must be current (prices, balances, etc.)
  6. Security First: Never request or store private keys; WalletConnect handles key management
  1. 禁止模拟数据:所有交易必须为真实区块链操作
  2. 需用户确认:绝不自动签名;始终请求用户批准签名
  3. 网络验证:交易前验证钱包是否连接到正确的网络
  4. Gas估算:签名前始终估算Gas并显示成本
  5. 实时数据:所有交易数据必须是最新的(价格、余额等)
  6. 安全优先:绝不请求或存储私钥;密钥管理由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:
      ethereum
      (mainnet)
    • Supported:
      ethereum
      ,
      polygon
      ,
      arbitrum
      ,
      optimism
      ,
      base
  • chain:区块链网络
    • 默认值:
      ethereum
      (主网)
    • 支持的网络:
      ethereum
      ,
      polygon
      ,
      arbitrum
      ,
      optimism
      ,
      base

Environment Variables

环境变量

  • WALLETCONNECT_PROJECT_ID (required): WalletConnect Cloud project ID
  • 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会话

  1. Load WalletConnect project ID from environment
  2. Create SignClient instance with metadata
  3. Generate pairing URI and display QR code in terminal
  4. Wait for user to scan QR code with wallet app
  5. Establish session and retrieve connected wallet address
  6. Verify connected chain matches requested chain
  1. 从环境变量加载WalletConnect项目ID
  2. 使用元数据创建SignClient实例
  3. 生成配对URI并在终端显示二维码
  4. 等待用户使用钱包应用扫描二维码
  5. 建立会话并获取连接的钱包地址
  6. 验证连接的链是否与请求的链匹配

Step 2: Prepare Transaction

步骤2:准备交易

  1. Accept standard ethers.TransactionRequest object
  2. Set default values if not provided:
    • from
      : Use connected wallet address
    • chainId
      : Use selected chain ID
    • gasLimit
      : Estimate gas if not provided
    • gasPrice
      or EIP-1559 fees: Fetch current network fees
  3. Validate transaction parameters
  1. 接收标准ethers.TransactionRequest对象
  2. 若未提供则设置默认值:
    • from
      :使用连接的钱包地址
    • chainId
      :使用所选链的ID
    • gasLimit
      :若未提供则估算Gas
    • gasPrice
      或EIP-1559手续费:获取当前网络手续费
  3. 验证交易参数

Step 3: Request Signature

步骤3:请求签名

  1. Format transaction request according to WalletConnect JSON-RPC spec
  2. Display transaction summary to user:
    • From: Connected wallet address
    • To: Recipient or contract address
    • Value: ETH amount
    • Gas Limit: Estimated gas limit
  3. Send
    eth_sendTransaction
    request via WalletConnect
  4. Wait for user to approve/reject in wallet app
  5. Handle user response (approved or rejected)
  1. 根据WalletConnect JSON-RPC规范格式化交易请求
  2. 向用户显示交易摘要:
    • 转出地址:连接的钱包地址
    • 转入地址:接收方或合约地址
    • 金额:ETH数量
    • Gas限额:估算的Gas限额
  3. 通过WalletConnect发送
    eth_sendTransaction
    请求
  4. 等待用户在钱包应用中批准/拒绝
  5. 处理用户响应(批准或拒绝)

Step 4: Broadcast and Confirm

步骤4:广播与确认

  1. If approved, receive signed transaction hash from wallet
  2. Broadcast transaction to blockchain network
  3. Monitor transaction status (pending → confirmed)
  4. Wait for transaction confirmation (1+ blocks)
  5. Generate output report with transaction details
  1. 若获得批准,从钱包接收已签名的交易哈希
  2. 向区块链网络广播交易
  3. 监控交易状态(待处理→已确认)
  4. 等待交易确认(至少1个区块)
  5. 生成包含交易详情的输出报告

Step 5: Close Session (Optional)

步骤5:关闭会话(可选)

  1. Keep session active for subsequent transactions
  2. Allow user to disconnect when done
  3. Clean up resources and close WalletConnect client
  1. 保持会话活跃以支持后续交易
  2. 允许用户完成操作后断开连接
  3. 清理资源并关闭WalletConnect客户端

Output Format

输出格式

markdown
undefined
markdown
undefined

WalletConnect Transaction Report

WalletConnect 交易报告

Chain: {chain_name} | Wallet: {wallet_address} | Status: {status} Timestamp: {utc_timestamp}

链名称:{chain_name} | 钱包地址:{wallet_address} | 状态:{status} 时间戳:{utc_timestamp}

Transaction Details

交易详情

FieldValue
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 生成
undefined

Example Output

示例输出

markdown
undefined
markdown
undefined

WalletConnect 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

交易详情

FieldValue
From0x932460072495a5eaa5029289b342c6186715f5a0
To0x932460072495a5eaa5029289b342c6186715f5a0
Value0.0001 ETH
Gas Used21000
Transaction Hash0xabc123...def456
Block Number19123456
Block Explorer: View Transaction

字段
转出地址0x932460072495a5eaa5029289b342c6186715f5a0
转入地址0x932460072495a5eaa5029289b342c6186715f5a0
金额0.0001 ETH
使用Gas21000
交易哈希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 生成
undefined

Error Handling

错误处理

Error TypeConditionAction
Missing Project ID
WALLETCONNECT_PROJECT_ID
not set
Return error message with setup instructions
Connection TimeoutNo wallet connects within timeout periodReturn error and suggest checking wallet app
User RejectionUser declines connection or signatureReturn message indicating user cancelled action
Insufficient BalanceWallet lacks funds for transaction + gasReturn error with current balance and required amount
Invalid AddressRecipient address malformed or invalidReturn error and request valid address format
Network MismatchWallet on different chain than requestedPrompt user to switch network in wallet
Gas Estimation FailedCannot estimate gas for transactionReturn error with possible reasons (contract issue, etc.)
Transaction RevertedOn-chain transaction failedReturn revert reason and transaction hash for debugging
RPC ErrorNetwork connectivity or RPC issuesReturn error and suggest checking network connection
Unsupported ChainRequested chain not supportedReturn list of supported chains
Invalid TransactionTransaction parameters invalidReturn error with validation details
错误类型触发条件处理动作
缺少项目ID未设置
WALLETCONNECT_PROJECT_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
    data
    field
  • 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

安全注意事项

  1. Never Store Private Keys: All key management handled by user's wallet
  2. Verify Addresses: Always display full addresses before signing
  3. Gas Limits: Set reasonable limits to prevent excessive costs
  4. Contract Verification: Only interact with verified contracts
  5. Amount Validation: Double-check amounts to prevent decimal errors
  1. 绝不存储私钥:所有密钥管理由用户的钱包处理
  2. 验证地址:签名前始终显示完整地址
  3. Gas限额:设置合理的限额以避免过高成本
  4. 合约验证:仅与已验证的合约交互
  5. 金额验证:仔细检查金额以避免小数错误

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

实现说明

  1. This skill requires Node.js runtime (v16+ recommended)
  2. Scripts are written in TypeScript and compiled to JavaScript
  3. Users must have a WalletConnect-compatible wallet (MetaMask, Rainbow, etc.)
  4. Session can persist for multiple transactions until disconnected
  5. All timestamps are in UTC with ISO 8601 format
  6. Transaction encoding/preparation is handled by the caller
  7. The skill focuses on core WalletConnect connection and transaction signing
  1. 本技能需要Node.js运行环境(推荐v16+)
  2. 脚本使用TypeScript编写并编译为JavaScript
  3. 用户必须拥有兼容WalletConnect的钱包(如MetaMask、Rainbow等)
  4. 会话可保持活跃以支持多笔交易,直到断开连接
  5. 所有时间戳均为UTC时区,采用ISO 8601格式
  6. 交易编码/准备工作由调用方处理
  7. 本技能专注于核心的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();