relevant tag icon
Layer Zero Message Example
copy icon
BraverElliot
• version 1.0.0
layerzero
crosschain
moonbeam

Layer Zero Message Example

This is a straightforward demonstration of how to achieve cross-chain communication between Goerli and Optimism Goerli using LayerZero. You can easily transfer strings between the two networks by following these steps: 1. Edit the provided code into Remix. 2. Deploy the code on both LayerZero Optimism Goerli and LayerZero Goerli networks using the provided lzEndpoints in the constructor argument. 3. Approve the other contract address on both deployed contracts using the trustAddress(address _otherContract) function. 4. Once approved, you can send messages between the two contracts using the send("Hello World") function. Remember to include some funds by adding a value amount.

*Visit desktop site to download or deploy

Version

1.0.0

Last Publish

2/27/2023
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
_nonblockingLzReceive(uint16,,uint64,) :
This function is an internal override of the _nonblockingLzReceive function. It decodes the payload passed to it as a parameter using the ABI (Application Binary Interface) and stores the result in the data variable. The payload is expected to be a string. (autogenerated documentation)
send(string) :
This function sends a message to a destination chain ID. It takes a string as an argument and encodes it into a byte array. It then calls the _lzSend function, passing in the destination chain ID, the encoded message, the address of the sender, an address of 0x0, an empty byte array, and the value of the message. The _lzSend function is responsible for sending the message to the destination chain. (autogenerated documentation)
trustAddress(address) :
This function allows the owner of the contract to trust a specific address. It takes in an address of another contract as an argument and stores it in the trustedRemoteLookup mapping. The mapping is indexed by the destChainId and stores the address of the other contract and the address of the current contract. The data is encoded using the abi.encodePacked function. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i Layer-Zero-Message-Examp
copy icon

Last Publish

2/27/2023

Version

1.0.0

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.