6.4 KiB
CCIP API Reference for ChainID 138
Date: 2025-01-27
Network: ChainID 138 (DeFi Oracle Meta Mainnet)
Overview
This document provides API reference for CCIP contracts on ChainID 138.
CCIP Router API
Functions
ccipSend(uint64 destinationChainSelector, EVM2AnyMessage memory message)
Send a message to a destination chain.
Parameters:
destinationChainSelector: Chain selector of destination chainmessage: CCIP message structure
Returns:
bytes32 messageId: Unique message identifieruint256 fees: Fees paid for the message
Example:
IRouterClient.EVM2AnyMessage memory message = IRouterClient.EVM2AnyMessage({
receiver: abi.encode(receiverAddress),
data: messageData,
tokenAmounts: new IRouterClient.TokenAmount[](0),
feeToken: address(0), // Native ETH
extraArgs: ""
});
(bytes32 messageId, uint256 fees) = router.ccipSend{value: fee}(
destinationSelector,
message
);
getFee(uint64 destinationChainSelector, EVM2AnyMessage memory message)
Calculate fee for sending a message.
Parameters:
destinationChainSelector: Chain selector of destination chainmessage: CCIP message structure
Returns:
uint256 fee: Required fee amount
Example:
uint256 fee = router.getFee(destinationSelector, message);
getSupportedTokens(uint64 destinationChainSelector)
Get list of supported tokens for a destination chain.
Parameters:
destinationChainSelector: Chain selector
Returns:
address[] tokens: Array of supported token addresses
addSupportedChain(uint64 chainSelector) (Admin Only)
Add a supported destination chain.
Parameters:
chainSelector: Chain selector to add
removeSupportedChain(uint64 chainSelector) (Admin Only)
Remove a supported destination chain.
addSupportedToken(uint64 chainSelector, address token) (Admin Only)
Add a supported token for a chain.
Parameters:
chainSelector: Chain selectortoken: Token address
updateFees(uint256 baseFee, uint256 dataFeePerByte) (Admin Only)
Update fee configuration.
Parameters:
baseFee: New base feedataFeePerByte: New data fee per byte
CCIPWETH9Bridge API
Functions
sendCrossChain(uint64 destinationChainSelector, address recipient, uint256 amount)
Send WETH9 tokens to another chain.
Parameters:
destinationChainSelector: Destination chain selectorrecipient: Recipient address on destination chainamount: Amount of WETH9 to send
Returns:
bytes32 messageId: Message ID for tracking
Example:
// Approve first
weth9.approve(address(bridge), amount);
// Send
bytes32 messageId = bridge.sendCrossChain(
5009297550715157269, // Ethereum Mainnet
recipientAddress,
amount
);
ccipReceive(Any2EVMMessage calldata message) (Router Only)
Receive WETH9 tokens from another chain. Called by router.
calculateFee(uint64 destinationChainSelector, uint256 amount)
Calculate fee for cross-chain transfer.
Parameters:
destinationChainSelector: Destination chain selectoramount: Transfer amount
Returns:
uint256 fee: Required fee
addDestination(uint64 chainSelector, address receiverBridge) (Admin Only)
Add destination chain configuration.
removeDestination(uint64 chainSelector) (Admin Only)
Remove destination chain.
updateDestination(uint64 chainSelector, address receiverBridge) (Admin Only)
Update destination receiver bridge address.
getDestinationChains()
Get list of configured destination chains.
Returns:
uint64[]: Array of chain selectors
getUserNonce(address user)
Get user's current nonce.
Returns:
uint256: User nonce
CCIPWETH10Bridge API
Same as CCIPWETH9Bridge, but for WETH10 tokens.
Events
Router Events
event MessageSent(
bytes32 indexed messageId,
uint64 indexed destinationChainSelector,
address indexed sender,
bytes receiver,
bytes data,
TokenAmount[] tokenAmounts,
address feeToken,
bytes extraArgs
);
event MessageReceived(
bytes32 indexed messageId,
uint64 indexed sourceChainSelector,
address indexed sender,
bytes data,
TokenAmount[] tokenAmounts
);
Bridge Events
event CrossChainTransferInitiated(
bytes32 indexed messageId,
address indexed sender,
uint64 indexed destinationChainSelector,
address recipient,
uint256 amount,
uint256 nonce
);
event CrossChainTransferCompleted(
bytes32 indexed messageId,
uint64 indexed sourceChainSelector,
address indexed recipient,
uint256 amount
);
event DestinationAdded(uint64 chainSelector, address receiverBridge);
event DestinationRemoved(uint64 chainSelector);
event DestinationUpdated(uint64 chainSelector, address receiverBridge);
Data Structures
EVM2AnyMessage
struct EVM2AnyMessage {
bytes receiver; // Encoded receiver address
bytes data; // Message data
TokenAmount[] tokenAmounts; // Token amounts to transfer
address feeToken; // Fee token address (0 for native)
bytes extraArgs; // Extra arguments
}
Any2EVMMessage
struct Any2EVMMessage {
bytes32 messageId; // Unique message ID
uint64 sourceChainSelector; // Source chain selector
bytes sender; // Encoded sender address
bytes data; // Message data
TokenAmount[] tokenAmounts; // Token amounts received
}
TokenAmount
struct TokenAmount {
address token; // Token address
uint256 amount; // Amount
TokenAmountType amountType; // Fiat or Native
}
Error Codes
Router Errors
CCIPRouter: chain not supportedCCIPRouter: insufficient native token feeCCIPRouter: duplicate messageCCIPRouter: empty receiver
Bridge Errors
CCIPWETH9Bridge: destination not enabledCCIPWETH9Bridge: transfer failedCCIPWETH9Bridge: transfer already processedCCIPWETH9Bridge: invalid amountCCIPWETH9Bridge: zero recipient
Related Documentation
Last Updated: 2025-01-27