Here we can see how the function abi.encode() is used to turn multiple values (someString, someNumber & someAddress) of various types (string, uint & address) into a single value of the type bytes called message. This bytearray can then be sent to the destination chain using the Teleporter.
The receiving contract can then decode the byte array back into its original values:
function receiveTeleporterMessage( bytes32 originChainID, address originSenderAddress, bytes calldata message) external { // Only the Interchain Messaging receiver can deliver a message. if (msg.sender != address(teleporterMessenger)) { revert Unauthorized(); } // Decoding the function parameters // ( string someString, uint256 someNumber, address someAddress ) = abi.decode(message, (string, uint256, address)); // Calling the internal function _someFunction(someString, someNumber, someAddress)}function _someFunction(string someString, uint256 someNumber, address someAddress) private { // Do something}
Here we are using abi.decode() to unpack the three values (someString, someNumber & someAddress) from the parameter message of the type bytes. As you can see, we need to provide the message as well as the types of values encoded in the message. It is important to note the types must be the same order as parameters to abi.decode().