In this section, we will learn how to pack multiple values into a single message.
We can use abi.encode() to encode multiple values into a single byte array:
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:
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().