To receive a message we need to enable out cross-Subnet dApps to being called by the Teleporter contract.
The Teleporter does not know out contract and what functions it has. Therefore, our dApp on the destination Subnet has to implement the ITeleporterReceiver interface. It is very straight forward and only requires a single method for receiving the message that then can be called by the Teleporter contract:
The function receiveTeleporterMessage has three parameters:
originChainID: The chainID where the message originates from, meaning where the user or contract called the sendCrossChainMessage function of the Teleporter contract
originSenderAddress: The address of the user or contract that called the sendCrossChainMessage function of the Teleporter contract on the origin Subnet
message: The message encoded in bytes
An example for a contract being able to receive Teleporter messages and storing these in a mapping could look like this:
This contract stores the last message and it's sender of each chain it has received. When it is instantiated, the address of the Teleporter contract is supplied to the constructor. The contract implements the ITelepoterReceiver interface and therefore we also implement the receiveTeleporterMessage function.