For the following tutorial we are going to assume you use Foundry. If you are using other frameworks, you may need to copy the relevant interfaces into your repository.
Installation
To install Generalised Incentives as a dependency in your repository, run
This will add Generalised Incentives to your repository and you are now ready to integrate it into your contract.
Integration
Start by adding import statements to your smart contract file. We need to import 2 files:
ICrossChainReceiver: This will ensure you correctly implement the interfaces for the message callbacks
Adding these to your contract will look something like this:
Defining Structures
The integration is less opinionated than other cross-chain endpoint, as we need to define some boilercode. First, lets set our escrow endpoint. Below we present 2 options
Set the escrow explicitly. This defines a single escrow which you may interact in. This may be desired to reduce complexity but also introduces some vendor lock-in.
Define a list of escrow that are allowed. This allows you to pick and choose which AMB is best suited for a certain connection. This introduces some additional complexity but mitigates vendor lock-in.
Callbacks
Generalised Incentives defines 2 callback functions we need to implement:
receiveAck: Called when a message has been processed on the destination.
receiveMessage: Called when you receive a message from the source chain.
Lets add these functions to our contract
We now implemented the reference code for Generalised incentives and is ready for processing messages sent to us.
For more information, check the relevant natspecs.
Sending Messages
We haven’t actually sent any messages yet. Lets do that. For simplicity, this section assumes that you used solution 1.