ClawSkills logoClawSkills

Abstract Onboard

在 Abstract (ZK Stack L2) 上部署智能合约并桥接资产。当智能体需要在 Abstract 上部署合约、将 ETH/代币桥接到 Abstract、进行交易

介绍

# Abstract Onboard

AI 代理在 Abstract (ZK Stack L2) 上运行所需的一切。

## 🚀 新手代理?从这里开始

```bash # Check if you're ready to operate node scripts/quick-start.js check <your-wallet-address>

# Or get the full setup guide node scripts/quick-start.js ```

## 快速开始

### 创建 Abstract Global Wallet (AGW) AGW 是一种可以在 Abstract 上赚取 XP 的智能合约钱包。对代理至关重要!

**⚠️ 关键:首先了解这 3 层:** ``` Private Key → EOA (signer) → AGW (smart contract wallet) ```

**正确的资金流向:** ``` 1. Fund EOA with small ETH (for gas) 2. Create/deploy AGW (EOA pays gas for first tx) 3. Fund AGW with your main balance 4. Everything runs through AGW from now on ```

```bash export WALLET_PRIVATE_KEY=0x... node scripts/create-agw.js ```

您的 EOA 成为签名者,AGW 是一个独立的智能合约地址。

**⚠️ 版本警告:** 不同的 `agw-client` 版本可能会计算出不同的 AGW 地址!请务必固定您的版本。有关详细信息,请参阅 `references/agw.md`。

### 检查余额 ```bash node scripts/check-balances.js <wallet> all ```

### 跨链 ETH 到 Abstract ```bash export WALLET_PRIVATE_KEY=0x... node scripts/relay-bridge.js --from base --amount 0.01 ```

### 部署合约 ```bash export WALLET_PRIVATE_KEY=0x... node scripts/deploy-abstract.js ./artifacts/MyContract.json "constructor-arg" ```

### 转账代币 ```bash export WALLET_PRIVATE_KEY=0x... node scripts/transfer.js --to 0x... --amount 0.01 # ETH node scripts/transfer.js --to 0x... --amount 100 --token USDC # Token ```

### 兑换代币 ```bash export WALLET_PRIVATE_KEY=0x... export DEX_ROUTER=0x... # Set DEX router address node scripts/swap-tokens.js --from ETH --to USDC --amount 0.01 ```

### DEX 交易 (Kona & Aborean)

Abstract 拥有多个 DEX。使用特定协议的脚本以获得最佳效果:

```bash # Kona Finance (V2) - USDC → ETH export WALLET_PRIVATE_KEY=0x... node scripts/swap-kona.js

# Aborean (Velodrome-style) - when router is available node scripts/swap-aborean.js

# Generic Uniswap V2 node scripts/swap-uniswap-v2.js ```

有关合约地址和支持的交易池,请参阅 `references/dex.md`。

### Myriad 预测市场

在 Myriad Markets 上交易 — Abstract 上最大的预测市场(41.5 万+ 用户,1 亿美元+ 交易量)。

```bash # List open markets node scripts/myriad-trade.js list

# Get market details node scripts/myriad-trade.js info <marketId>

# Buy shares (place a prediction) export WALLET_PRIVATE_KEY=0x... node scripts/myriad-buy-direct.js <marketId> <outcomeId> <amount>

# Example: $1 USDC.e on "Yes" for market 765 node scripts/myriad-buy-direct.js 765 0 1 ```

有关合约地址、ABI 详细信息和代币信息,请参阅 `references/myriad.md`。

### 调用任意合约 ```bash # Read node scripts/call-contract.js --address 0x... --abi ./abi.json --function balanceOf --args 0x1234

# Write export WALLET_PRIVATE_KEY=0x... node scripts/call-contract.js --address 0x... --abi ./abi.json --function transfer --args 0x1234,100 --write ```

### 铸造 NFT ```bash # Deploy SimpleNFT.sol first, then mint export WALLET_PRIVATE_KEY=0x...

# Mint to existing contract node scripts/mint-nft.js --contract 0x... --image QmIPFShash --to 0xRecipient --name "My NFT" ```

有关基本 NFT 合约模板,请参阅 `references/SimpleNFT.sol`。

### USDC 操作 ```bash # Check USDC balance node scripts/usdc-ops.js balance <wallet>

# Transfer USDC export WALLET_PRIVATE_KEY=0x... node scripts/usdc-ops.js transfer <to> <amount>

# Approve spender node scripts/usdc-ops.js approve <spender> <amount>

# Check allowance node scripts/usdc-ops.js allowance <owner> <spender> ```

### 估算 Gas ```bash # Get current gas prices node scripts/estimate-gas.js

# Estimate transfer cost node scripts/estimate-gas.js transfer <to> <amount>

# Estimate deployment cost node scripts/estimate-gas.js deploy <bytecodeSize> ```

### 监听事件 ```bash # Watch new blocks node scripts/watch-events.js blocks

# Watch ETH transfers to/from wallet node scripts/watch-events.js transfers <wallet>

# Watch ERC20 transfers node scripts/watch-events.js erc20 <token> <wallet>

# Watch contract events node scripts/watch-events.js contract <address> ```

### 测试网设置 ```bash # Get faucet instructions node scripts/testnet-setup.js faucet

# Check testnet balance node scripts/testnet-setup.js check <wallet>

# Verify testnet setup node scripts/testnet-setup.js verify <wallet> ```

## 关键信息

| 项目 | 值 | |------|-------| | Chain ID | 2741 | | RPC | https://api.mainnet.abs.xyz | | Explorer | https://abscan.org | | Bridge | https://relay.link/bridge/abstract | | USDC | `0x84A71ccD554Cc1b02749b35d22F684CC8ec987e1` | | WETH | `0x3439153EB7AF838Ad19d56E1571FBD09333C2809` | | Kona Router | `0x441E0627Db5173Da098De86b734d136b27925250` | | Uniswap V2 Router | `0xad1eCa41E6F772bE3cb5A48A6141f9bcc1AF9F7c` | | Myriad PM Contract | `0x3e0F5F8F5Fb043aBFA475C0308417Bf72c463289` | | Myriad PTS Token | `0x0b07cf011B6e2b7E0803b892d97f751659940F23` | | Myriad API | `https://api-v2.myriadprotocol.com` |

## 脚本

| 脚本 | 用途 | |--------|---------| | `quick-start.js` | **从这里开始** - 设置指南和健康检查 | | `create-agw.js` | 创建 Abstract Global Wallet(赚取 XP!) | | `check-balances.js` | 检查 ETH 和代币余额 | | `relay-bridge.js` | 从其他链跨链 ETH | | `bridge-usdc-relay.js` | 通过 Relay API 跨链 USDC | | `deploy-abstract.js` | 将合约部署到 Abstract(带验证!) | | `verify-contract.js` | 验证合约是否具有字节码(安全检查) | | `transfer.js` | 发送 ETH 或代币 | | `usdc-ops.js` | USDC 转账、授权、额度 | | `swap-tokens.js` | 通过 DEX 交易代币(通用) | | `swap-kona.js` | 在 Kona Finance 上兑换 (V2) ✅ | | `swap-aborean.js` | 在 Aborean 上兑换(Velodrome 风格) | | `swap-uniswap-v2.js` | 在 Uniswap V2 上兑换 | | `myriad-trade.js` | 列出市场,获取信息(Myriad API) | | `myriad-buy-direct.js` | 在 Myriad 上下注预测(链上) ✅ | | `call-contract.js` | 调用任意合约函数 | | `mint-nft.js` | 向现有合约铸造 NFT | | `estimate-gas.js` | 交易前估算 Gas 费用 | | `watch-events.js` | 实时监控链上事件 | | `testnet-setup.js` | 设置并验证测试网访问 |

## 参考资料

| 文件 | 内容 | |------|----------| | `agw.md` | Abstract Global Wallet 指南(XP、激活) | | `dex.md` | DEX 合约和兑换模式(Kona、Aborean) | | `myriad.md` | Myriad 预测市场合约、ABI 和交易 | | `hardhat.config.js` | 适用于 Abstract 的 Hardhat 配置 | | `addresses.md` | 关键合约地址 | | `troubleshooting.md` | 常见错误和修复方法 | | `SimpleNFT.sol` | 基本 NFT 合约模板 |

## ⚠️ 关键:合约部署

Abstract 是一条基于 zkSync 的链。标准的 EVM 部署方法不起作用。

### 什么方法有效 ✅ ```javascript // Use zksync-ethers (NOT viem, NOT standard ethers) const { ContractFactory } = require("zksync-ethers"); const factory = new ContractFactory(abi, bytecode, wallet); const contract = await factory.deploy(args);

// ALWAYS verify bytecode after deploy const code = await provider.getCode(address); if (code === '0x') throw new Error("Deploy failed!"); ```

### 什么方法无效 ❌ ```javascript // DON'T use viem's deployContract await walletClient.deployContract({...}); // Returns success but NO BYTECODE

// DON'T use standard ethers ContractFactory // DON'T trust transaction success alone ```

### 部署清单 - [ ] 使用 zksolc 编译(而非标准 solc) - [ ] 使用 `zksync-ethers` ContractFactory - [ ] 部署后验证 `eth_getCode != 0x` - [ ] 发送代币前测试合约功能

## 常见问题

1. **Gas 估算失败** → 使用 Hardhat,不要用 foundry-zksync 2. **编译器错误** → 使用 Solidity 0.8.x 配合 zksolc 3. **交易卡住** → 检查 Gas 价格,在 abscan.org 上验证 4. **部署成功但没有字节码** → 使用 zksync-ethers,不要用 viem 5. **代币发送到空地址** → 务必先验证字节码!

有关详细解决方案,请参阅 `references/troubleshooting.md`。

## 依赖项

```bash # Core dependencies npm install ethers zksync-ethers viem

# For contract deployment npm install @matterlabs/hardhat-zksync

# For AGW (Abstract Global Wallet) - PIN THE VERSION! # Different versions compute different AGW addresses npm install @abstract-foundation/[email protected] ```

**⚠️ agw-client 版本警告:** 较新的版本可能使用不同的工厂合约,为相同的 EOA 计算出不同的 AGW 地址。如果您更改版本,请在发送资金之前验证您的 AGW 地址是否未发生更改!

更多产品