The Scroll Messenger
The Scroll Messenger contracts allow for sending arbitrary messages from L1 to L2 or vice versa. This enables executing functions on another chain in a secure and permissionless way. To send a message from L1 to L2, use
the messenger smart contract deployed on L1, L1ScrollMessenger
. To send a message from L2 to L1, use the contract deployed on L2, L2ScrollMessenger
.
Finalizing transactions on L1
Any upcoming transactions from L2 need to be finalized using the relayMessageWithProof
function on the Scroll Messenger
contract. We call this process “submitting an Execute Withdrawal transaction,” and it is required for both sending arbitrary messages and transferring assets through a gateway or the router. When you use relayMessageWithProof
, you’ll have to provide a Merkle inclusion proof showing your transaction is included in the trie of “withdrawal” messages, along with other parameters. Producing this proof and these values can be done locally and permissionlessly, but at the moment, the easiest way to retrieve these parameters is through our backend APIs:
- Scroll Sepolia API: https://sepolia-api-bridge-v2.scroll.io/api/
- Scroll API: https://mainnet-api-bridge-v2.scroll.io/api/
Supply the address of the EOA or contract responsible for initiating the original transaction on L2 to the /claimable
endpoint. The API backend will provide you with all the necessary information to successfully conclude the transaction on L1.
Take a look at the following example:
The API should return your transaction data in the following format:
The claimInfo
object under the result
json returned has all the information needed to execute your transaction on L1. The
parameters needed by the relayMessageWithProof
are: from
, to
, value
, nonce
, message
and proof
. Supply these to
the relayMessageWithProof
function on L1 to execute and finalize your transaction on L1.
Messenger API
Please visit the npm library for the complete Scroll contract API documentation.
sendMessage
Sends arbitrary data from one chain to another. It allows us to execute functions cross-chain.
Parameter | Description |
---|---|
target | The address of the account that receives the message. The receiver can be either a smart contract or an EOA wallet. |
value | The amount of ether passed when calling the target contract. |
message | The content of the message. This is the arbitrary calldata to be executed. |
gasLimit | Gas limit required to complete the message relay on the corresponding chain. |
refundAddress | The address of the account that will receive the refunded fee. |
relayMessageWithProof
Relay a L2 => L1 message with message proof.
Parameter | Description |
---|---|
from | The address of the sender of the message. |
to | The address of the recipient of the message. |
value | The msg.value passed to the message call. |
nonce | The nonce of the message to avoid replay attack. |
message | The content of the message. |
proof | The proof used to verify the correctness of the transaction. |