Set Trusted Remotes

For a contract using LayerZero, a trusted remote is another contract it will accept messages from.

What is a Trusted Remote?

A trusted remote is the 40 bytes (for evm-to-evm messaging) that identifies another contract which you will receive messages from within your LayerZero User Application contract. The 40 bytes object is the packed bytes of the remoteAddress + localAddress
The reason to care about Trusted Remotes is that from a security perspective contracts should only receive messages from known contracts. Hence, contracts are securely connected by "setting trusted remotes".
The team has produced this github repository as an example of how to automate setting trusted remotes.

40 byte Format

for EVM <> EVM, A Trusted Remote is 40 bytes. It is the REMOTE contract address concatenated with the LOCAL contract address.

Solana, Aptos, et al & 32 Byte Addresses

For NON-evm chains with addresses that are not 20 bytes obviously the Trusted Remotes will not be exactly 40 bytes, but we will regularly use "40 byte" Trusted Remotes in the nomenclature.

Generate TrustedRemote Using Ethersjs

// the trusted remote (or sometimes referred to as the path or pathData)
// is the packed 40 bytes object of the REMOTE + LOCAL user application contract addresses
let trustedRemote = hre.ethers.utils.solidityPack(
[remoteContract.address, localContract.address]

Trusted Remote usages:

The Trusted Remote is now used in a few places. Here is a list of which functions expect the trusted remote format:
Is it a trusted remote?

Endpoint hasStoredPayload()

Endpoint forceResumeReceive()

LzApp setTrustedRemote()

LzApp isTrustedRemote()