Overview
The Chainrails Intent Broadcaster enables contract-level integrations with Chainrails. It allows protocols to create intents directly from their smart contracts instead of via API calls, with funds escrowed on-chain and processed automatically.How It Works
The diagram above illustrates the flow:
- Your contract broadcasts an intent
- Your integration contract calls
broadcast_intent. - Chainrails escrows the funds and emits
IntentBroadcastedwith abroadcastId.
- Chainrails picks the best route
- The event is indexed and sent to the backend.
- Chainrails validates the caller and computes the best executable route.
- Chainrails executes on-chain
- The backend calls
startBroadcastedIntentwith route data for on-chain execution.
- Intent settles and completes
- Funds are fulfilled to the destination based on the selected route.
Broadcasting an Intent
To broadcast an intent from your contract, you simply need to interface with theIntentBroadcaster contract on the source chain.
Method name depends on your chain:
- EVM:
broadcastIntent - Starknet/Solana:
broadcast_intent
- The broadcasted intent payload (
sourceChain,destinationChain,bridgeTokenOutOptions,sender,refundAddress,destinationRecipient) deposits— an array of tokens and amounts to be escrowed for the intent.maxFeeBudget— the maximum fee budget for the intent, which can be used to cover execution fees on the destination chain. Leave this as 0 to use paymaster for fee payment.isLive— A boolean indicating if it’s a production intent or a test intent. We currently only support production intents, so this should be set totrue.
- Solidity Example
- Cairo Example
- Rust example (coming soon)
Whitelisting Contracts
To ensure security and prevent unauthorized use, only whitelisted contracts can broadcast intents for a particular client. To whitelist your contract, you need to:- Sign up for a Chainrails account on the Chainrails Dashboard.
- Head to Settings -> Whitelisted Contracts
- Add the chain and contract address of your integration contract.
Notes
TheIntentBroadcaster currently only supports the USDC token. Support for additional tokens is coming soon.
