Communicating Cross-Chain
This guide covers cross-chain communication between Ethereum (L1) and Aztec (L2) using portal contracts.
Aztec uses an Inbox/Outbox pattern for cross-chain messaging. Messages sent from L1 are inserted into the Inbox contract and later consumed on L2. Messages sent from L2 are inserted into the Outbox contract and later consumed on L1. Portal contracts are L1 contracts that facilitate this communication for your application.
Prerequisites
- An Aztec contract project with
aztec-nrdependency - Access to Ethereum development environment for L1 contracts
- Deployed portal contract on L1 (see token bridge tutorial)
L1 to L2 messaging
Send a message from L1
Use the Inbox contract's sendL2Message function:
| Parameter | Type | Description |
|---|---|---|
_recipient | L2Actor | L2 contract address and rollup version |
_content | bytes32 | Hash of message content (use Hash.sha256ToField) |
_secretHash | bytes32 | Hash of secret for message consumption |
deposit_public
/**
* @notice Deposit funds into the portal and adds an L2 message which can only be consumed publicly on Aztec
* @param _to - The aztec address of the recipient
* @param _amount - The amount to deposit
* @param _secretHash - The hash of the secret consumable message. The hash should be 254 bits (so it can fit in a
* Field element)
* @return The key of the entry in the Inbox and its leaf index
*/
function depositToAztecPublic(bytes32 _to, uint256 _amount, bytes32 _secretHash)
external
returns (bytes32, uint256)
Source code: l1-contracts/test/portals/TokenPortal.sol#L47-L59
Message availability
L1 to L2 messages are not available immediately. The proposer batches messages from the Inbox and includes them in the next L2 block. You must wait for this before consuming the message on L2.