name: bridge
description: “使用Wormhole和CCTP进行跨链代币转移”
emoji: “🌉”
gates:
envs:
anyOf:
- SOLANA_PRIVATE_KEY
- EVM_PRIVATE_KEY
Bridge - 完整API参考
使用Wormhole和Circle CCTP协议跨链转移代币。
支持的链
| 链 |
Wormhole |
CCTP (USDC) |
| Solana |
是 |
是 |
| Ethereum |
是 |
是 |
| Polygon |
是 |
是 |
| Arbitrum |
是 |
是 |
| Optimism |
是 |
是 |
| Avalanche |
是 |
是 |
| Base |
是 |
是 |
聊天命令
报价
/bridge quote 100 USDC sol to eth # 报价100 USDC Solana → Ethereum
/bridge quote 1000 USDC arb to base # 报价Arbitrum → Base
/bridge quote 50 USDC eth to sol # 报价Ethereum → Solana
执行转移
/bridge send 100 USDC sol to eth # 发送100 USDC Solana → Ethereum
/bridge send 1000 USDC arb to base # 发送Arbitrum → Base
/bridge send 50 USDC eth to sol --address <dest> # 到特定地址
赎回(索赔)
/bridge redeem <tx-hash> # 索赔已转移的代币
/bridge pending # 列出待处理赎回
状态
/bridge status <tx-hash> # 检查转移状态
/bridge history # 查看转移历史
TypeScript API 参考
Wormhole 桥
import { executeWormholeBridge, executeWormholeRedeem } from 'clodds/bridge/wormhole';
// 获取报价
const quote = await getWormholeQuote({
sourceChain: 'solana',
destChain: 'ethereum',
token: 'USDC',
amount: 100,
});
console.log(`转移100 USDC: Solana → Ethereum`);
console.log(`费用: $${quote.fee}`);
console.log(`预计时间: ${quote.estimatedTime} 秒`);
// 执行转移
const transfer = await executeWormholeBridge({
sourceChain: 'solana',
destChain: 'ethereum',
token: 'USDC',
amount: 100,
// 源钱包
sourcePrivateKey: process.env.SOLANA_PRIVATE_KEY,
// 目标地址(可选,默认为您的地址)
destAddress: '0x1234...',
});
console.log(`转移已启动: ${transfer.txHash}`);
console.log(`VAA: ${transfer.vaa}`);
console.log(`状态: ${transfer.status}`);
// 在目标链上赎回
const redeem = await executeWormholeRedeem({
destChain: 'ethereum',
vaa: transfer.vaa,
destPrivateKey: process.env.EVM_PRIVATE_KEY,
});
console.log(`已赎回: ${redeem.txHash}`);
console.log(`接收金额: ${redeem.amount} USDC`);
CCTP(Circle)桥
import { executeCCTPBridge, redeemCCTP } from 'clodds/bridge/cctp';
// CCTP针对USDC转移进行了优化
const transfer = await executeCCTPBridge({
sourceChain: 'arbitrum',
destChain: 'base',
amount: 1000, // USDC
sourcePrivateKey: process.env.EVM_PRIVATE_KEY,
destAddress: '0x1234...',
});
console.log(`CCTP转移: ${transfer.txHash}`);
console.log(`消息哈希: ${transfer.messageHash}`);
// 等待证明(通常约15分钟)
await waitForAttestation(transfer.messageHash);
// 赎回
const redeem = await redeemCCTP({
destChain: 'base',
messageHash: transfer.messageHash,
destPrivateKey: process.env.EVM_PRIVATE_KEY,
});
检查状态
import { getTransferStatus } from 'clodds/bridge';
const status = await getTransferStatus(txHash);
console.log(`状态: ${status.status}`);
// 'pending' | 'confirming' | 'attesting' | 'redeemable' | 'completed' | 'failed'
console.log(`源确认数: ${status.sourceConfirmations}`);
console.log(`VAA状态: ${status.vaaStatus}`);
console.log(`已赎回: ${status.redeemed}`);
if (status.status === 'redeemable') {
console.log(`准备赎回! VAA: ${status.vaa}`);
}
获取待处理赎回
import { getPendingRedemptions } from 'clodds/bridge';
const pending = await getPendingRedemptions({
chains: ['ethereum', 'solana', 'arbitrum'],
address: myAddress,
});
for (const p of pending) {
console.log(`${p.sourceChain} → ${p.destChain}`);
console.log(` 金额: ${p.amount} ${p.token}`);
console.log(` 状态: ${p.status}`);
console.log(` 时长: ${p.age} 分钟`);
}
转移流程
Wormhole
- 锁定代币在源链上
- 等待确认(因链而异)
- 守护者证明(VAA生成)
- 赎回在目标链上
CCTP
- 燃烧USDC在源链上
- 等待证明(约15分钟)
- 铸造USDC在目标链上
费用与时间
| 路由 |
费用 |
时间 |
| Solana → Ethereum |
~$5 |
15-20 分钟 |
| Ethereum → Solana |
~$20 |
15-20 分钟 |
| Arbitrum → Base (CCTP) |
~$0.50 |
15-20 分钟 |
| Polygon → Arbitrum |
~$1 |
15-20 分钟 |
最佳实践
- 对USDC使用CCTP - 更快更便宜
- 检查燃气价格 - 高燃气可能增加成本
- 保存VAA/消息哈希 - 赎回所需
- 监控待处理转移 - 不要忘记赎回
- 从小额开始 - 大额转移前测试
- 验证目标地址 - 发送前仔细检查