Skip to main content

Overview

In this section, we walk you through how to implement the Chainrails Intent Broadcaster in your Cairo contracts on Starknet.

Step 1 — Import required interfaces and types

Import the broadcaster dispatcher, ERC20 dispatcher, and shared types.
Imports

Step 2 — Define your contract interface

Expose functions for broadcasting, canceling, and querying execution/escrow status.
Contract Interface

Step 3 — Add utility for token address encoding

Chainrails token representation uses u256, so convert Starknet ContractAddress to u256.
Address Utils

Step 4 — Store broadcaster address and initialize it

Persist the broadcaster address in storage and validate it in constructor.
Storage and Constructor

Step 5 — Broadcast an intent

Create a function that escrows funds, approves broadcaster spend, builds BroadcastedIntent + deposits, and calls broadcast_intent.
Broadcast Intent

Cancellation and Refunds

Cancellation and refunds of broadcasted intents are handled automatically after intent expiration (typically around 1 hour after broadcasting). You can also support manual cancel from your broadcasting contract:
Cancel Broadcast
NB: Only the broadcasting contract can manually cancel a broadcast before expiration, if it has not been executed. Once cancelled, escrowed funds for that broadcast are refunded to the configured refund_address.

Github Example

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