Expand description
§cctp-rs
A production-ready Rust SDK for Circle’s Cross-Chain Transfer Protocol (CCTP).
This library provides a safe, ergonomic interface for bridging USDC across multiple blockchain networks using Circle’s CCTP infrastructure.
§Choosing an API
| Task | Type |
|---|---|
| Bridge USDC (recommended) | CctpV2Bridge |
| Bridge USDC on a v1-only legacy chain | Cctp |
| Self-relay safely against permissionless relayers | CctpV2Bridge::mint_if_needed |
| Wait for any relayer (cheapest happy path) | CctpV2Bridge::wait_for_receive |
| Inspect a v2 message as serializable JSON | ParsedV2MessageSummary |
| Look up chain config without a provider | CctpV1 / CctpV2 traits |
| Drive contracts directly | TokenMessengerV2Contract etc. |
For longer-form guidance and the full list of footguns see AGENTS.md in
the repository.
§Quick Start (V2, recommended)
use cctp_rs::{CctpV2Bridge, CctpError, PollingConfig};
use alloy_chains::NamedChain;
use alloy_primitives::FixedBytes;
// V2 bridge with fast transfer support
let eth_provider = ProviderBuilder::new().connect("http://localhost:8545").await?;
let linea_provider = ProviderBuilder::new().connect("http://localhost:8546").await?;
let bridge = CctpV2Bridge::builder()
.source_chain(NamedChain::Mainnet)
.destination_chain(NamedChain::Linea)
.source_provider(eth_provider)
.destination_provider(linea_provider)
.recipient("0x742d35Cc6634C0532925a3b844Bc9e7595f8fA0d".parse()?)
.fast_transfer(true) // Enable sub-30 second settlement
.build();
// V2 uses transaction hash directly and returns both message and attestation
let burn_tx_hash = FixedBytes::from([0u8; 32]);
let (message, attestation) = bridge.get_attestation(
burn_tx_hash,
PollingConfig::fast_transfer(), // Optimized for fast transfers
).await?;§Quick Start (V1, legacy v1-only chains)
use cctp_rs::{Cctp, CctpError, PollingConfig};
use alloy_chains::NamedChain;
use alloy_primitives::FixedBytes;
// Set up providers and create bridge
let eth_provider = ProviderBuilder::new().connect("http://localhost:8545").await?;
let arb_provider = ProviderBuilder::new().connect("http://localhost:8546").await?;
let bridge = Cctp::builder()
.source_chain(NamedChain::Mainnet)
.destination_chain(NamedChain::Arbitrum)
.source_provider(eth_provider)
.destination_provider(arb_provider)
.recipient("0x742d35Cc6634C0532925a3b844Bc9e7595f8fA0d".parse()?)
.build();
// Get message from burn transaction, then fetch attestation
let burn_tx_hash = FixedBytes::from([0u8; 32]);
let (message, message_hash) = bridge.get_message_sent_event(burn_tx_hash).await?;
let attestation = bridge.get_attestation(message_hash, PollingConfig::default()).await?;§Direct Contract Access
For advanced use cases, you can use the contract wrappers directly:
use cctp_rs::{TokenMessengerV2Contract, MessageTransmitterV2Contract};
use alloy_primitives::address;
use alloy_provider::ProviderBuilder;
let provider = ProviderBuilder::new().connect("http://localhost:8545").await?;
let contract_address = address!("9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5");
// Create contract wrapper
let token_messenger = TokenMessengerV2Contract::new(contract_address, provider);§Features
- Type-safe contract interactions using Alloy
- Multi-chain support for mainnet and testnet networks
- Comprehensive error handling with detailed error types
- Builder pattern for intuitive API usage
- Agent-friendly protocol inspection with serializable v2 message parsing
- Extensive test coverage ensuring reliability
§Public API
AttestationResponseandAttestationStatus- Circle’s Iris API attestation typesCctpandCctpV2Bridge- Core CCTP bridge implementations for v1 and v2CctpV1andCctpV2- Traits for chain-specific configurationsPollingConfig- Configuration for attestation polling behaviorParsedV2MessageandParsedV2MessageSummary- Parse canonical v2 messages into serializable structsParseMessageError- Error type for canonical v2 message parsingInvalidDomainIdandInvalidFinalityThreshold- Errors returned byTryFrom<u32>forDomainId/FinalityThresholdCctpErrorandResult- Error types for error handling- Contract wrappers for direct contract interaction:
sol!-generated modules for decoding raw event logs against the canonical ABI:
For example, to decode a v2 DepositForBurn event log:
use cctp_rs::TokenMessengerV2::DepositForBurn;
use alloy_sol_types::SolEvent;
let _topic = DepositForBurn::SIGNATURE_HASH;
let _decoded = DepositForBurn::decode_log(log)?;Modules§
- Message
Transmitter - Generated by the following Solidity interface…
- Message
Transmitter V2 - Generated by the following Solidity interface…
- Token
Messenger - Generated by the following Solidity interface…
- Token
Messenger V2 - Generated by the following Solidity interface…
- spans
- OpenTelemetry span helpers for CCTP operations
Structs§
- Attestation
Response - Represents the response from the attestation service
- Burn
Message V2 - CCTP v2 Burn Message Body
- Cctp
- CCTP v1 bridge implementation
- Cctp
V2Bridge - CCTP v2 bridge implementation
- Erc20
Contract - ERC20 contract wrapper for approval operations
- Invalid
Domain Id - Error returned when attempting to convert an invalid u32 to a
DomainId - Invalid
Finality Threshold - Error returned when attempting to convert an invalid u32 to a
FinalityThreshold - Message
Header - CCTP v2 Message Header
- Message
Transmitter Contract - The CCTP v1 Message Transmitter contract wrapper
- Message
Transmitter V2Contract - The CCTP v2 Message Transmitter contract wrapper
- Parse
Message Error - Error returned when parsing a canonical CCTP v2 message fails.
- Parsed
V2Message - Parsed representation of a canonical CCTP v2 transfer message.
- Parsed
V2Message Summary - JSON-friendly summary of a canonical CCTP v2 transfer message.
- Polling
Config - Configuration for attestation polling behavior.
- Provider
Config - Configuration for creating production-ready providers.
- Provider
Config Builder - Builder for
ProviderConfig - Token
Messenger Contract - The CCTP v1 Token Messenger contract wrapper
- Token
Messenger V2Contract - The CCTP v2 Token Messenger contract wrapper
- Token
State - Token state containing balance and allowance information.
- V2Attestation
Response - Represents the response from the CCTP v2 attestation API
- V2Message
- Represents a single message in the v2 attestation response
Enums§
- Attestation
Failure Kind - Categorical reasons an attestation poll can fail.
- Attestation
Status - Represents the status of the attestation.
- Cctp
Error - Domain
Id - CCTP domain identifier for blockchain networks
- Finality
Threshold - Finality threshold for CCTP v2 messages
- Mint
Result - Result of attempting to mint on the destination chain
Constants§
- CCTP_
V2_ MESSAGE_ TRANSMITTER_ MAINNET - CCTP V2
MessageTransmitteraddress (Mainnet) - CCTP_
V2_ MESSAGE_ TRANSMITTER_ TESTNET - CCTP V2
MessageTransmitteraddress (Testnet) - CCTP_
V2_ TOKEN_ MESSENGER_ MAINNET - CCTP V2
TokenMessengeraddress (Mainnet) - CCTP_
V2_ TOKEN_ MESSENGER_ TESTNET - CCTP V2
TokenMessengeraddress (Testnet) - DEFAULT_
GAS_ BUFFER_ PERCENT - Default gas buffer percentage (20%)
- DEFAULT_
RETRY_ ATTEMPTS - Default number of retry attempts
- DEFAULT_
TIMEOUT_ SECS - Default request timeout in seconds
Traits§
- Cctp
Bridge - Common trait interface for CCTP bridge implementations (v1 and v2)
- CctpV1
- Trait for chains that support CCTP bridging
- CctpV2
- CCTP v2 chain configuration trait
Functions§
- batch_
token_ state - Fetch token balance and allowance in parallel and return them as a
TokenState. - calculate_
gas_ price_ with_ buffer - Helper to calculate gas price with a tip buffer for EIP-1559 transactions.
- estimate_
gas_ with_ buffer - Estimate gas for a transaction with an optional safety buffer.
Type Aliases§
- Attestation
Bytes - The bytes of the attestation.
- Result