Skip to main content

Overview

In this section, we walk you through how to implement the Chainrails Intent Broadcaster in your smart contracts on EVM-compatible chains.

Step 1 — Import the Interface

First, create and import the IIntentBroadcaster interface into your contract.
Import

Step 2 — Define the required types

Next, define the BroadcastedIntent, Chain and TokenAmount objects in your contract. These are used to structure the data for broadcasting an intent.
Types

Step 3 — Create a util function to encode token address

Encode to bytes32

Step 4 — Create the Intent Broadcaster Instance

Create an instance of the IIntentBroadcaster interface in your contract, pointing to the deployed IntentBroadcaster contract address.
Intent Broadcaster Instance

Step 5 — Broadcast an Intent

Now you can create a function in your contract to broadcast an intent using the broadcastIntent function from the IIntentBroadcaster interface. This function will take in the necessary parameters, structure the BroadcastedIntent object, and call the broadcaster to broadcast the intent.
Broadcast Intent

Cancellation and Refunds

Cancellation and refunds of broadcasted intents are handled automatically like a normal intent after the intent expiration (typically in 1 hour after broadcasting). You can also choose to implement a function in your contract to allow users to manually cancel their broadcasted intents before expiration by calling the cancelBroadcast function from the IIntentBroadcaster interface.
Cancel Broadcast
NB: Only the broadcasting contract can manually cancel a broadcast before expiration, if it has not been executed. Once cancelled, the escrowed funds for that intent will be automatically refunded to the specified refundAddress.

Github Example

Find the full implementation of the above example in the GitHub repository.