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.
§Quick Start (V1)
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?;§Quick Start (V2)
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?;§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
- 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 behaviorCctpErrorandResult- Error types for error handling- Contract wrappers for direct contract interaction:
Modules§
- 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
- 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
- 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
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 MessageTransmitter address (Mainnet)
- CCTP_
V2_ MESSAGE_ TRANSMITTER_ TESTNET - CCTP V2 MessageTransmitter address (Testnet)
- CCTP_
V2_ TOKEN_ MESSENGER_ MAINNET - CCTP V2 TokenMessenger address (Mainnet)
- CCTP_
V2_ TOKEN_ MESSENGER_ TESTNET - CCTP V2 TokenMessenger address (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_ checks - Batch check token allowance and balance in parallel RPC calls.
- batch_
token_ state - Batch check token state (balance and allowance) returning a structured result.
- 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