Skip to main content
Version: Endpoint V1

OmniCounter.sol

A LayerZero User Application example to demonstrate message sending.

The OmniCounter

OmniCounter is a contract that increments a counter -- but there's a twist. This OmniCounter increments the counter on another chain.

The Details

To send cross chain messages, contracts will use an endpoint to send() from the source chain and lzReceive() to receive the message on the destination chain. Here you may find a table of the Testnet Endpoints.

OmniCounter.sol can send and receive LayerZero messages. Let's highlight the two important features of this contract:

  • _lzSend() is overridden and called within incrementCounter() to send the message to another chain.
  • _nonblockingLzReceive() is overridden and it will be called on the destination chain which receives the message when receiving a message.

If you want to deploy and try this contract yourself you will need to construct it with an Endpoint address. And will need the two interfaces.

Take a look at the simplest usage of LayerZero: the OmniCounter.

Clone the github repo, take a look at the README, and deploy your own OmniCounters.

If you were to deploy this contract, you would need to do so on at least 2 chains. Once deployed, call incrementCounter to increment the counter on a destination chain!

tip

Use LayerZero Scan to track your omnichain message after calling incrementCounter!