Receiver Contract
Create a contract to receive messages with Teleporter.
Now it's time to deploy our receiver contract to our L1. It will implement the callback for the TeleporterMessenger
contract when the message is received, decoding our message and storing the last received string.
Read the Receiver Contract
The following contract is located inside src/0-send-receive
directory. Read through the contract below and and understand what is happening:
The key things to understand:
- Importing Interchain Messaging contracts (L8, L9): We are importing the
ITeleporterMessenger
andITeleporterReceiver
interface we looked at in the previous activity. - Inheriting from ITeleporterReceiver (L11): We are inheriting the interface that will require us to implement the
receiveTeleporterMessage()
function. - Defining the lastMessage variable (L14): Setting the
lastMessage
variable aspublic
, will make that variable readable from the outside without the need of agetValue
function. - Implementing receiveTeleporterMessage (L16): We implement the function that will be called when the message is received. Please note that we are not checking who calls that function for now. So anyone can pretend to deliver messages for now.
- Decode message (L21): We decode the message using
abi.decode(message, (string))
, which takes the bytes array as the first input and a tuple of the types of the encoded data in the message. Since our message only contains a single value, the tuple only has one value.
Deploy Receiver Contract
To deploy a contract using Foundry use the following command:
Save Receiver Contract Address
Then save the receiver contract address in an environment variable: