@chainlink/ccip-sdk

中文文档
1.16.1发布于 2026/10/18MITTypeScriptES Module构建来源已验证近 30 天下载 1.8万

与 CCIP 互动的 SDK/图书馆

中文使用文档
文档目录11 节
  1. 安装
  2. 链类
  3. 共同任务
  4. 跟踪 CCIP 信件
  5. 获取收费估计
  6. 发送 Cross- Chin 信件
  7. 钱包配置
  8. 未签名的交易
  9. 支持的链条
  10. 相关
  11. 许可证

@ 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.Signernew Wallet(privateKey, provider)
索拉纳anchor.Walletnew Wallet(Keypair.fromSecretKey(...))
自动aptos.AccountAccount.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支助
自动AptosChainaptos-ts-sdk (英语)支助
苏SuiChain@mysten/sui (英语)部分(手工执行)
顿TONChain@ ton/ ton部分(没有签名池/登记查询)
广CantonChain州长JSON API部分( 发送 + 手动执行; 需要) CantonConfig(中文(简体) )

许可证

麻省理工学院

版本与发布记录

@chainlink/ccip-sdk 共发布 45 个版本,首次发布于 2025/11/26;过去 12 个月发布了 45 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.16.1latest2026/10/1822 天前
1.16.02026/10/1030 天前
1.15.02026/10/011 个月前
1.14.02026/09/261 个月前
1.13.02026/08/262 个月前
1.12.02026/08/202 个月前

关于 @chainlink/ccip-sdk 的常见问题

@chainlink/ccip-sdk 是什么?

与 CCIP 互动的 SDK/图书馆

如何安装 @chainlink/ccip-sdk?

在项目目录运行 npm install @chainlink/ccip-sdk,或使用 pnpm add / yarn add / bun add。

@chainlink/ccip-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@chainlink/ccip-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@chainlink/ccip-sdk 可以商用吗?

@chainlink/ccip-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@chainlink/ccip-sdk 的下载量有多少?

根据 npm 官方下载统计,@chainlink/ccip-sdk 在 2026/10/10 – 2026/11/08 这 30 天内被下载 18,216 次,日均约 607 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@chainlink/ccip-sdk 还在维护吗?

最新版本 1.16.1 发布于 2026/10/18(22 天前);至今共发布 45 个版本,其中过去 12 个月发布了 45 个;首次发布于 2025/11/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。