Getting Started
Last updated
Last updated
For each sending and receiving chain pair supported by Vea, there is a separate set of Vea contract . For each chain, there is exactly one deployed contract.
Sending Chain: - Manages state of all messages sent through Vea.
Receiving Chain: - Manages optimistic game over inbox state
To integrate Vea, sender and receiver gateway contracts need to be deployed to interface with the Vea inbox and outbox.
_to
The address on the receiving chain to call
_fnSelector
The function selector of the receiving contract to call
_data
The abi encoded calldata to pass with the function call.
e.g. abi.encode(arg1, arg2, arg3. . .)
Notice that the sendMessage(...) call in the Vea Inbox returns a uint64 message id. This id is used to relay the message on the receiving chain. Your dapp will probably want to index these messages with an event like below to later relay the message.
In this example, the sender gateway is sending some uint256 _data. The Vea Inbox contract expects a bytes array encoding the calldata to be passed with the cross-chain call.
The data which you include in the cross-chain message depends on your specific application.
_proof
The merkle inclusion proof
_msgId
The message id to relay
_to
The address to call
_data
The message data to relay
In order to implement a cross-chain call, you need to specify the function selector in the receiver gateway to call. You should define the function stub to call in an interface for the receiver gateway. Here's an example where we define the function stub receiveMessage
.
Note that Vea passes the msg.sender who called the sendMessage(...) function on the sending chain as the first argument of any cross-chain call. This means that the IReceiverGateway interface should always contain the msgSender as the first argument.
Here's a complete example of a ReceiverGateway.
The message sender of a cross-chain call is always the first argument of calldata passed to any receiver gateways.
Cross-chain call authentication requires checking that the msg.sender on the sending chain is the Vea Outbox contract, and checking the first argument of the call is equal to the sender gateway like shown in the modifier onlyFromAuthenticatedVeaSender
.
To support transfer of data types other than uint256 as shown in this example, simply define those custom arguments in the function stub of the IReceiverGateway and encode those data types into a bytes array to pass in the SenderGateway when calling sendMessage(...)
in the Vea Inbox.
For example, to support a call passing data of a string, uint64, and a bytes array, the ISenderGateway would instead implement
and the IReceiverGateway interface would appropriately include a function selector expecting the data types string, uint64, and bytes, with an additional argument in the first position which will always include the message sender (Vea ensures the message sender will be passed in this argument).
Once messages are bridged by Vea, which can take hours to days depending on the sending and receiving chain pairs, the messages can be relayed by providing a merkle proof of message inclusion in the Vea Outbox contract.
For each sending, receiving chain pair supported by Vea, there is a 'Vea Inbox' contract on the sending chain. Contracts send messages through Vea by calling the 'sendMessage(...)' function in the Vea Inbox.
The sender gateway should implement the ISenderGateway .
where the IVeaInbox includes the function stub to send messages through Vea.
To send a message through Vea, the sending gateway should implement a function to call sendMessage(...) in the Vea Inbox. Here is an example .
For each sending, receiving chain pair supported by Vea, there is a 'Vea Outbox' contract on the receiving chain. Receiver gateways receive messages from Vea by receiving calls from the '(...)' function in the Vea Outbox.
The provides utility functions to calculate proofs and fetch message data to relay.
The provides utility functions to calculate merkle inclusion proofs given the msgId. Here is an example of relaying a message given the msgId.