Create a contract to send messages with Teleporter.
Lets start by deploying our sender contract on C-Chain. It will be responsible for calling the the TeleporterMessenger contract, encoding our message and sending it to the destination chain.
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 ITeleporterMessenger (Line 8): We are importing the ITeleporterMessenger Interface we looked at in the previous activity.
Defining teleporterMessenger contract (Line 12): We are defining a the teleporterMessenger contract using the imported interface. It is important to note, that our cross-chain dApp is not implementing the interface itself, but initializes a contract using that interface.
Sending the message (Line 21): We are sending the message by calling the function of our teleporterMessenger. As an input we are defining a TeleporterMessageInput. Make sure to replace the destinationChainId with the one of your Blockchain. We will need to provide the address of the receiving contract on the Avalanche L1 as a parameter to the function, since we have not deployed it yet and don't know the address at this time.
No fees (Line 25): In this exercise we are not providing any fees to the relayer for relaying the message. This is only possible since the relayer we are running here is configured to pick up any message even if it does not provide any rewards.
Encoding the Message (Line 31): The TeleporterMessageInput defines a message as an array of bytes. For now we will just simply encode the string with abi.encode(). In the future activities, you will see how we can encode multiple values of any type in that message.