Skip to main content
Version: 1.0.0

Class: CCIPAPIClient

Defined in: api/index.ts:129

Client for interacting with the CCIP REST API.

Can be used standalone or injected into Chain classes.

Examples

TypeScript
const api = CCIPAPIClient.fromUrl()
const latency = await api.getLaneLatency(sourceSelector, destSelector)
console.log(`Latency: ${latency.totalMs}ms`)
TypeScript
const api = CCIPAPIClient.fromUrl('https://custom.api.url', {
logger: myLogger,
fetch: myCustomFetch,
})
TypeScript
try {
const latency = await api.getLaneLatency(sourceSelector, destSelector)
} catch (err) {
if (err instanceof CCIPHttpError) {
console.error(`API error ${err.context.status}: ${err.context.apiErrorMessage}`)
if (err.isTransient) {
// Retry after delay
}
}
}

Constructors

Constructor

new CCIPAPIClient(baseUrl?: string, ctx?: CCIPAPIClientContext): CCIPAPIClient

Defined in: api/index.ts:151

Creates a new CCIPAPIClient instance.

Parameters

ParameterTypeDescription
baseUrl?stringBase URL for the CCIP API (defaults to DEFAULT_API_BASE_URL)
ctx?CCIPAPIClientContextOptional context with logger and custom fetch

Returns

CCIPAPIClient

Properties

baseUrl

readonly baseUrl: string

Defined in: api/index.ts:131

Base URL for API requests


logger

readonly logger: Logger

Defined in: api/index.ts:133

Logger instance


timeoutMs

readonly timeoutMs: number

Defined in: api/index.ts:135

Request timeout in milliseconds

Methods

getExecutionInput()

getExecutionInput(messageId: string): Promise<ExecutionInput & Lane<CCIPVersion> & { offRamp: string; }>

Defined in: api/index.ts:479

Fetches the execution input for a given message by id. For v2.0 messages, returns { encodedMessage, verifications }. For pre-v2 messages, returns { message, offchainTokenData, proofs, ... } with merkle proof.

Parameters

ParameterTypeDescription
messageIdstringThe CCIP message ID (32-byte hex string)

Returns

Promise<ExecutionInput & Lane<CCIPVersion> & { offRamp: string; }>

Execution input with offRamp address and lane info

Throws

CCIPMessageIdNotFoundError when message not found (404)

Throws

CCIPTimeoutError if request times out

Throws

CCIPHttpError on other HTTP errors

Example

TypeScript
const api = CCIPAPIClient.fromUrl()
const execInput = await api.getExecutionInput('0x1234...')
// Use with dest.execute():
const { offRamp, ...input } = execInput
await dest.execute({ offRamp, input, wallet })

getLaneLatency()

getLaneLatency(sourceChainSelector: bigint, destChainSelector: bigint): Promise<LaneLatencyResponse>

Defined in: api/index.ts:251

Fetches estimated lane latency between source and destination chains.

Parameters

ParameterTypeDescription
sourceChainSelectorbigintSource chain selector (bigint)
destChainSelectorbigintDestination chain selector (bigint)

Returns

Promise<LaneLatencyResponse>

Promise resolving to LaneLatencyResponse with totalMs

Throws

CCIPLaneNotFoundError when lane not found (404)

Throws

CCIPTimeoutError if request times out

Throws

CCIPHttpError on other HTTP errors with context:

  • status - HTTP status code (e.g., 500)
  • statusText - HTTP status message
  • apiErrorCode - API error code (e.g., "INVALID_PARAMETERS")
  • apiErrorMessage - Human-readable error message from API

Examples

TypeScript
const latency = await api.getLaneLatency(
5009297550715157269n, // Ethereum mainnet
4949039107694359620n, // Arbitrum mainnet
)
console.log(`Estimated delivery: ${Math.round(latency.totalMs / 60000)} minutes`)
TypeScript
try {
const latency = await api.getLaneLatency(sourceSelector, destSelector)
} catch (err) {
if (err instanceof CCIPHttpError && err.context.apiErrorCode === 'LANE_NOT_FOUND') {
console.error('This lane does not exist')
}
}

getMessageById()

getMessageById(messageId: string): Promise<{ lane: Lane<CCIPVersion>; log: ChainLog; message: CCIPMessage_V1_6_Solana | { ccipReceiveGasLimit: number; ccvAndExecutorHash: string; data: string; destBlob: string; destChainSelector: bigint; encodedMessage: string; executionGasLimit: number; feeToken: string; feeTokenAmount: bigint; finality: number; messageId: string; messageNumber: bigint; offRampAddress: string; onRampAddress: string; receipts: readonly { destBytesOverhead: bigint; destGasLimit: bigint; extraArgs: string; feeTokenAmount: bigint; issuer: string; }[]; receiver: string; sender: string; sequenceNumber: bigint; sourceChainSelector: bigint; tokenAmountBeforeTokenPoolFees: bigint; tokenAmounts: readonly TokenTransferV1[]; verifierBlobs: readonly string[]; } | CCIPMessage_V1_6_Sui | CCIPMessage_V1_6_EVM | { data: string; feeToken: string; feeTokenAmount: bigint; gasLimit: bigint; messageId: string; nonce: bigint; receiver: string; sender: string; sequenceNumber: bigint; sourceChainSelector: bigint; sourceTokenData: readonly string[]; strict: boolean; tokenAmounts: readonly { amount: bigint; token: string; }[]; } | CCIPMessage_V1_5_EVM; metadata: APICCIPRequestMetadata; tx: Omit<ChainTransaction, "logs">; }>

Defined in: api/index.ts:337

Fetches a CCIP message by its unique message ID.

Parameters

ParameterTypeDescription
messageIdstringThe message ID (0x prefix + 64 hex characters, e.g., "0x1234...abcd")

Returns

Promise<{ lane: Lane<CCIPVersion>; log: ChainLog; message: CCIPMessage_V1_6_Solana | { ccipReceiveGasLimit: number; ccvAndExecutorHash: string; data: string; destBlob: string; destChainSelector: bigint; encodedMessage: string; executionGasLimit: number; feeToken: string; feeTokenAmount: bigint; finality: number; messageId: string; messageNumber: bigint; offRampAddress: string; onRampAddress: string; receipts: readonly { destBytesOverhead: bigint; destGasLimit: bigint; extraArgs: string; feeTokenAmount: bigint; issuer: string; }[]; receiver: string; sender: string; sequenceNumber: bigint; sourceChainSelector: bigint; tokenAmountBeforeTokenPoolFees: bigint; tokenAmounts: readonly TokenTransferV1[]; verifierBlobs: readonly string[]; } | CCIPMessage_V1_6_Sui | CCIPMessage_V1_6_EVM | { data: string; feeToken: string; feeTokenAmount: bigint; gasLimit: bigint; messageId: string; nonce: bigint; receiver: string; sender: string; sequenceNumber: bigint; sourceChainSelector: bigint; sourceTokenData: readonly string[]; strict: boolean; tokenAmounts: readonly { amount: bigint; token: string; }[]; } | CCIPMessage_V1_5_EVM; metadata: APICCIPRequestMetadata; tx: Omit<ChainTransaction, "logs">; }>

Promise resolving to APICCIPRequest with message details

Throws

CCIPMessageIdNotFoundError when message not found (404)

Throws

CCIPTimeoutError if request times out

Throws

CCIPHttpError on HTTP errors with context:

  • status - HTTP status code
  • statusText - HTTP status message
  • apiErrorCode - API error code (e.g., "INVALID_MESSAGE_ID")
  • apiErrorMessage - Human-readable error message

Examples

TypeScript
const request = await api.getMessageById(
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
)
console.log(`Status: ${request.metadata.status}`)
console.log(`From: ${request.message?.sender}`)
TypeScript
try {
const request = await api.getMessageById(messageId)
} catch (err) {
if (err instanceof CCIPMessageIdNotFoundError) {
console.error('Message not found, it may still be in transit')
}
}

getMessageIdsInTx()

getMessageIdsInTx(txHash: string): Promise<string[]>

Defined in: api/index.ts:400

Fetches message IDs from a source transaction hash.

Parameters

ParameterTypeDescription
txHashstringSource transaction hash (EVM hex or Solana Base58)

Returns

Promise<string[]>

Promise resolving to array of message IDs

Throws

CCIPMessageNotFoundInTxError when no messages found (404 or empty)

Throws

CCIPUnexpectedPaginationError when hasNextPage is true

Throws

CCIPTimeoutError if request times out

Throws

CCIPHttpError on HTTP errors

Example

TypeScript
const messageIds = await api.getMessageIdsInTx(
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
)
console.log(`Found ${messageIds.length} messages`)

fromUrl()

static fromUrl(baseUrl?: string, ctx?: CCIPAPIClientContext): CCIPAPIClient

Defined in: api/index.ts:182

Factory method for creating memoized CCIPAPIClient. Should be preferred over constructor, to avoid multiple fetch/retry/rate-limits instances, unless that's specifically required.

Parameters

ParameterTypeDescription
baseUrl?stringBase URL for the CCIP API
ctx?CCIPAPIClientContextOptional context

Returns

CCIPAPIClient

New CCIPAPIClient instance