@ chainlink/ cip- sdk
用于集成的脚本 SDK 类型 中华民国 (Cross-Chain互操作性协议) 输入您的应用程序.
[大 这一工具是在麻省理工学院许可证下提供的,只是为了方便和说明目的.
📖 完整的 SDK 文档 - 完整的API参考、先进图案和打树引领.
安装
npm install @chainlink/ccip-sdk
[注] Node.js v20+需要. v24+ 建议开发(native TypeScript execution).
链类
SDK提供统一的 Chain 每个块链家族的类界面。 使用 fromUrl数字 :
import { EVMChain, SolanaChain, AptosChain, CantonChain } from '@chainlink/ccip-sdk'
// EVM chains (Ethereum, Arbitrum, Optimism, etc.)
const evmChain = await EVMChain.fromUrl('https://ethereum-sepolia-rpc.publicnode.com')
// Solana
const solanaChain = await SolanaChain.fromUrl('https://api.devnet.solana.com')
// Aptos
const aptosChain = await AptosChain.fromUrl('https://api.testnet.aptoslabs.com/v1')
// Canton (requires CantonConfig — see Multi-Chain guide)
const cantonChain = await CantonChain.fromUrl('https://ledger.example.com/api/json', {
cantonConfig: {
party: 'sender::1220...',
ccipParty: 'ccip::1220...',
jwt: 'eyJ...',
edsUrl: 'https://eds.example.com',
transferInstructionUrl: 'https://transfer-instruction.example.com',
},
})
共同任务
跟踪 CCIP 信件
import { EVMChain } from '@chainlink/ccip-sdk'
const source = await EVMChain.fromUrl('https://ethereum-sepolia-rpc.publicnode.com')
// Fetch message details from a transaction
const requests = await source.getMessagesInTx(
'0xb8b27d9811509e3c364c9afaf8f14d8ebc65dec06327493981d7f7f4a00f2918'
)
const request = requests[0]
console.log('Message ID:', request.message.messageId)
console.log('Sender:', request.message.sender)
console.log('Destination chain:', request.lane.destChainSelector)
获取收费估计
import { EVMChain, networkInfo } from '@chainlink/ccip-sdk'
const source = await EVMChain.fromUrl('https://ethereum-sepolia-rpc.publicnode.com')
const router = '0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59' // Sepolia Router
const destChainSelector = networkInfo('ethereum-testnet-sepolia-arbitrum-1').chainSelector
const fee = await source.getFee({ router, destChainSelector, message: {
receiver: '0xYourReceiverAddress',
data: '0x48656c6c6f', // "Hello" in hex
extraArgs: { gasLimit: 200_000n }, // Gas limit for receiver's ccipReceive callback
} })
console.log('Fee in native token:', fee.toString())
发送 Cross- Chin 信件
import { EVMChain, networkInfo } from '@chainlink/ccip-sdk'
import { Wallet } from 'ethers'
const source = await EVMChain.fromUrl('https://ethereum-sepolia-rpc.publicnode.com')
const wallet = new Wallet('YOUR_PRIVATE_KEY', source.provider)
const router = '0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59'
const destChainSelector = networkInfo('ethereum-testnet-sepolia-arbitrum-1').chainSelector
// Get fee first
const fee = await source.getFee({ router, destChainSelector, message: {
receiver: '0xYourReceiverAddress',
data: '0x48656c6c6f',
extraArgs: {
gasLimit: 200_000n,
allowOutOfOrderExecution: true, // Don't wait for prior messages from this sender
},
} })
// Send the message
const request = await source.sendMessage({
router,
destChainSelector,
message: {
receiver: '0xYourReceiverAddress',
data: '0x48656c6c6f',
extraArgs: { gasLimit: 200_000n, allowOutOfOrderExecution: true },
fee,
},
wallet,
})
console.log('Transaction hash:', request.tx.hash)
console.log('Message ID:', request.message.messageId)
钱包配置
交易发送方法需要特定链的钱包 :
| 链条 | 钱包类型 | 示例 |
|---|---|---|
| EVM( 视频) | ethers.Signer | new Wallet(privateKey, provider) |
| 索拉纳 | anchor.Wallet | new Wallet(Keypair.fromSecretKey(...)) |
| 自动 | aptos.Account | Account.fromPrivateKey(...) |
| 广 | CantonWallet | 来自配置+可选 Ed25519 外部签名器的政党ID |
未签名的交易
对于自定义签名工作流程(例如浏览器钱包、硬件钱包),请使用 generateUnsigned* 方法:
// Generate unsigned transaction data
const unsignedTx = await source.generateUnsignedSendMessage({
sender, // Your wallet address
router,
destChainSelector,
message
})
// Sign and send with your own logic (EVM example - uses .transactions)
// Solana uses .instructions, Aptos uses .transactions (BCS-encoded), TON uses .body
// Canton uses .commands (Daml JsCommands)
// Sui does not support unsigned transaction generation
for (const tx of unsignedTx.transactions) {
const signed = await customSigner.sign(tx)
await customSender.broadcast(signed)
}
对于浏览器中的EVM链,请从连接的钱包中获取一个签名符:
const signer = await source.provider.getSigner(0)
支持的链条
| 链条家族 | 类 | 图书馆 | 状态 |
|---|---|---|---|
| EVM( 视频) | EVMChain | 乙醚.js v6 (单位:千美元)维姆 可选) | 支助 |
| 索拉纳 | SolanaChain | (原始内容存档于2013-10-12). solana-web3.js | 支助 |
| 自动 | AptosChain | aptos-ts-sdk (英语) | 支助 |
| 苏 | SuiChain | @mysten/sui (英语) | 部分(手工执行) |
| 顿 | TONChain | @ ton/ ton | 部分(没有签名池/登记查询) |
| 广 | CantonChain | 州长JSON API | 部分( 发送 + 手动执行; 需要) CantonConfig(中文(简体) ) |
相关
- SDK API 参考文献 - 完整的SDK文档
- @ chainlink/ ccip- cli - 命令线接口
- CCIP 官方文件 - 礼宾文件
- CCIP 目录 - 路由器地址
许可证
麻省理工学院