For the complete documentation index, see llms.txt. This page is also available as Markdown.

🤩Getting Started

Integrating Vea

For each sending and receiving chain pair supported by Vea, there is a separate set of Vea contract deployments. For each chain and network, there is exactly one deployed contract.

  • Sending Chain: VeaInbox - Manages state of all messages sent through Vea.

  • Receiving Chain: VeaOutbox - 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.

Vea Integration with Gateways

1. Sender Gateway

For each sending, receiving chain pair supported by Vea, there is a 'Vea Inbox' contract deployed on the sending chain. Contracts send messages through Vea by calling the 'sendMessage(...)' function in the Vea Inbox.

  • _to The address on the receiving chain to call

  • _data The abi encoded calldata to pass with the function call.

    • e.g. abi.encode(arg1, arg2, arg3. . .)

The sender gateway can implement the ISenderGateway interface.

where the IVeaInbox interface 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 mock implementation.

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.

2. Receiver Gateway

For each sending, receiving chain pair supported by Vea, there is a 'Vea Outbox' contract deployed on the receiving chain. Receiver gateways receive messages from Vea by receiving calls in 'receiveMessage(...)' from the 'sendMessage(...)' function in the Vea Outbox.

  • _proof The merkle inclusion proof

  • _msgId The message id to relay

  • _to The address to call

  • _from The sender address from the Vea Inbox chain

  • _data The message data to relay

The Vea SDK provides utility functions to calculate proofs and fetch message data to relay.

IReceiverGateway Function Specification

In order to implement a cross-chain call, you need to implement the receiveMessage of IReceiverGateway interface. Here's an example where we define the function receiveMessage.

Note that Vea passes the msg.sender who called the sendMessage(...) function on the sending chain as the first argument and message data in second argument in receiveMessage function call. So the receiver must implement the receiveMessage function of IReceiverGateway.

Here's a complete example of a ReceiverGateway.

Message Sender Authentication

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.

Customizing the data types sent between gateways

To support transfer of data types other than uint256 as shown in this example, simply 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 implement the receiveMessage function selector to decode the data types string, uint64, and bytes.

3. Relaying your message

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.

Last updated