Skip to main content

Overview

This guide demonstrates how to integrate CCTP into your smart contracts using hooks, message handlers, and relayers.

Core Interfaces

CCTP provides several interfaces for integration:

IMessageHandler

Implement IMessageHandler to receive cross-chain messages:
Parameters:
  • sourceDomain: The source chain’s domain ID
  • sender: The message sender address as bytes32
  • messageBody: The message payload
Returns:
  • true if message handling succeeded

IReceiver

The IReceiver interface is implemented by MessageTransmitter:
This validates incoming messages and forwards them to the appropriate handler.

IRelayer

The IRelayer interface is implemented by MessageTransmitter for sending messages:

Implementation Examples

Basic Message Handler

Implement a simple contract that receives cross-chain messages:

Cross-Chain Token Bridge

Build a custom token bridge on top of CCTP:

Hook Execution Pattern

CCTP V2 supports hooks that execute custom logic after message receipt.

Hook Data Format

CCTPHookWrapper Example

The CCTPHookWrapper demonstrates hook integration:

Custom Hook Handler

Implement a contract that receives hook callbacks:

Integration Best Practices

1. Access Control

Always verify the message sender:

2. Message Validation

Validate message format and data:

3. Reentrancy Protection

Protect against reentrancy attacks:

4. Error Handling

Handle errors gracefully:

5. Gas Optimization

Optimize gas usage:

Automated Relaying

Implement automated message relaying:

Testing Integration

Test your integration thoroughly:

Next Steps