L
a
y
e
r
Z
e
r
o
A
I
R
D
R
O
P

LayerZero is conducting an airdrop of their ETH tokens to the community.
This is a decentralized infrastructure for building scalable and secure Ethereum applications.

Don't miss your chance to participate in this exciting opportunity to receive free tokens and join the LayerZero ecosystem!

Core Concept of LayerZero

LayerZero is a User Application (UA) configurable on-chain endpoint that runs a ULN. LayerZero relies on two parties to transfer messages between on-chain endpoints: the Oracle and the Relayer.

When a UA sends a message from chain A to chain B, the message is routed through the endpoint on chain A. The endpoint then notifies the UA specified Oracle and Relayer of the message and it's destination chain.

The Oracle forwards the block header to the endpoint on chain B and the Relayer then submits the transaction proof. The proof is validated on the destination chain and the message is forwarded to the destination address.

Funds

Binance Labs
SINO Global Capital
Multicoin Capital
Fantom
Avalanche
UNISWAP Labs
a16z
Sequoia
Paypal Ventures
Polygon
Coinbase Ventures
DeFiance Capital
Robot Ventures
Spartan
Binance Labs
SINO Global Capital
Multicoin Capital
Fantom
Avalanche
UNISWAP Labs
a16z
Sequoia
Paypal Ventures
Polygon
Coinbase Ventures
DeFiance Capital
Robot Ventures
Spartan
Binance Labs
SINO Global Capital
Multicoin Capital
Fantom
Avalanche
UNISWAP Labs
a16z
Sequoia
Paypal Ventures
Polygon
Coinbase Ventures
DeFiance Capital
Robot Ventures
Spartan
Echelon Capital
Delphi Digital
Zokyo
Exponent
Gemini
Genblock Capital
GHAF Capital Partners
imToken
Kronos
Protocol Ventures
matrixport
Animoca
MC Ventures
Operator
Blockdaemon
OSAZ
cFund
CoinFund
Space Whale Capital
Dapper Labs
Tiger Global
Ethernity
Volt Capital
Hypersphere Ventures
Echelon Capital
Delphi Digital
Zokyo
Exponent
Gemini
Genblock Capital
GHAF Capital Partners
imToken
Kronos
Protocol Ventures
matrixport
Animoca
MC Ventures
Operator
Blockdaemon
OSAZ
cFund
CoinFund
Space Whale Capital
Dapper Labs
Tiger Global
Ethernity
Volt Capital
Hypersphere Ventures
Echelon Capital
Delphi Digital
Zokyo
Exponent
Gemini
Genblock Capital
GHAF Capital Partners
imToken
Kronos
Protocol Ventures
matrixport
Animoca
MC Ventures
Operator
Blockdaemon
OSAZ
cFund
CoinFund
Space Whale Capital
Dapper Labs
Tiger Global
Ethernity
Volt Capital
Hypersphere Ventures
LayerZero - trustless, omnichain interoperability protocol

Develop with LayerZero

endpoint.send() has six parameters. Here is an explanation of the arguments:

1// endpoint send()
2
3function send(
4  uint16 _chainId,                   // the destination chainId
5  bytes calldata _destination,       // the destination contract address
6  bytes calldata _payload,           // the raw bytes of your payload
7  address payable _refundAddress,    // where additional gas is refunded
8  address paymentAddr,               // optional
9  bytes calldata txParameters        // airdrop native gas
10)
1import "../interfaces/ILayerZeroReceiver.sol";
2import "../interfaces/ILayerZeroEndpoint.sol";
3
4contract Example is ILayerZeroReceiver {
5
6  // the LayerZero endpoint address
7  ILayerZeroEndpoint public endpoint;
8
9  constructor(address _endpoint)  {
10    endpoint = ILayerZeroEndpoint(_endpoint);
11  }
12
13  // Use the endpoint to send a message to another chain.
14  // This function should be payable, and you should send
15  // additional gas to make sure the message delivery is paid for
16  // on the destination chain.
17  function sendYourMessage(uint16 _chainId, bytes calldata _endpoint) public payable {
18    endpoint.send{value:msg.value}(_chainId, _endpoint, bytes(""), msg.sender, address(0x0), bytes(""));
19  }
20
21  // receiving message interface method.
22  function lzReceive(uint16 _srcChainId, bytes memory _fromAddress, bytes memory _payload)
23  override external {}
24}
1// an endpoint is the contract which has the send() function
2ILayerZeroEndpoint public endpoint;
3
4// call send() to send a message/payload to another chain
5endpoint.send{value:msg.value}(10001, destUaAddr, bytes("hello"), msg.sender, address(this), bytes(""));
1mapping(address => uint) public addrCounter;
2// override from ILayerZeroReceiver.sol
3
4function lzReceive(uint16 _srcChainId, bytes memory _fromAddress, uint _nonce, bytes memory _payload)
5override external {
6  require(msg.sender == address(endpoint));
7  address fromAddress;
8  assembly {
9    fromAddress := mload(add(_fromAddress, 20))
10  }
11  addrCounter[fromAddress] += 1;
12}

Examples

01/OmniCounter.sol

A LayerZero User Application example to demonstrate message sending.

1pragma solidity 0.8.4;
2pragma abicoder v2;
3
4import "../lzApp/NonblockingLzApp.sol";
5
6contract OmniCounter is NonblockingLzApp {
7    uint public counter;
8
9    constructor(address _lzEndpoint) NonblockingLzApp(_lzEndpoint) {}
10
11    function _nonblockingLzReceive(uint16, bytes memory, uint64, bytes memory) internal override {
12        counter += 1;
13    }
14
15    function incrementCounter(uint16 _dstChainId) public payable {
16        _lzSend(_dstChainId, bytes(""), payable(msg.sender), address(0x0), bytes(""));
17    }
18}

02/PingPong.sol

An example to demonstrate estimateFees() and a recursive call within lzReceive()

1pragma solidity 0.8.4;
2pragma abicoder v2;
3
4import "@openzeppelin/contracts/security/Pausable.sol";
5import "../lzApp/NonblockingLzApp.sol";
6
7contract PingPong is NonblockingLzApp, Pausable {
8    // event emitted every ping() to keep track of consecutive pings count
9    event Ping(uint pings);
10
11    // constructor requires the LayerZero endpoint for this chain
12    constructor(address _endpoint) NonblockingLzApp(_endpoint) {}
13
14    // disable ping-ponging
15    function enable(bool en) external {
16        if (en) {
17            _pause();
18        } else {
19            _unpause();
20        }
21    }
22  

03/LZEndpointMock.sol

A mock LayerZero endpoint contract for local testing.

1pragma solidity ^0.8.4;
2pragma abicoder v2;
3
4import "../interfaces/ILayerZeroReceiver.sol";
5import "../interfaces/ILayerZeroEndpoint.sol";
6
7contract LZEndpointMock is ILayerZeroEndpoint {
8    mapping(address => address) public lzEndpointLookup;
9
10    uint16 public mockChainId;
11    address payable public mockOracle;
12    address payable public mockRelayer;
13    uint public mockBlockConfirmations;
14    uint16 public mockLibraryVersion;
15    uint public mockStaticNativeFee;
16    uint16 public mockLayerZeroVersion;
17    uint public nativeFee;
18    uint public zroFee;
19    bool nextMsgBLocked;
20
21    struct StoredPayload {
22        uint64 payloadLength;
23        address dstAddress;
24        bytes32 payloadHash;
25    }
26
27    struct QueuedPayload {
28        address dstAddress;
29        uint64 nonce;
30        bytes payload;
31    }
32	
View more code examples on githubView more code examples on github