Fasani / solidity-examples

example contracts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple LayerZero omni chain contracts

Setup the project

npm install

Run tests

npx hardhat test

NOTE: You must add a .env with a MNEMONIC that is funded on testnets !

configure an .env file to have the values of .env.example and test deploy! (Use a real LayerZero endpoint in place of 0x0000..)

Testing Cross Chain Messages

  1. Deploy both OmniCounters:
npx hardhat --network fuji deploy
npx hardhat --network mumbai deploy 
  1. Set the remote addresses, so each contract can receive messages
npx hardhat --network mumbai omniCounterSetRemote --target-network fuji
npx hardhat --network fuji omniCounterSetRemote --target-network mumbai
  1. Send a cross chain message from mumbai to fuji !
npx hardhat --network mumbai omniCounterIncrementCounter --target-network fuji

Optionally use this command in a separate terminal to watch the counter increment in real-time.

npx hardhat --network fuji omniCounterPoll    

Testing Multiple Cross Chain Messages

  1. Deploy both OmniCounters:
npx hardhat --network mumbai deploy 
npx hardhat --network fuji deploy
npx hardhat --network bsc-testnet deploy 
npx hardhat --network fantom-testnet deploy 
  1. Set the remote addresses, so each contract can receive messages
npx hardhat --network mumbai omniCounterSetRemote --target-network fuji
npx hardhat --network fuji omniCounterSetRemote --target-network mumbai

npx hardhat --network mumbai omniCounterSetRemote --target-network bsc-testnet
npx hardhat --network bsc-testnet omniCounterSetRemote --target-network mumbai

npx hardhat --network mumbai omniCounterSetRemote --target-network fantom-testnet
npx hardhat --network fantom-testnet omniCounterSetRemote --target-network mumbai
  1. Send a cross chain message from mumbai to fuji !
npx hardhat --network mumbai omniCounterIncrementMultiCounter --target-networks fuji,bsc-testnet,fantom-testnet

Optionally use this command in a separate terminal to watch the counter increment in real-time.

npx hardhat --network fuji omniCounterPoll
npx hardhat --network bsc-testnet omniCounterPoll
npx hardhat --network fantom-testnet omniCounterPoll

For further reading, and a list of endpoint ids and deployed LayerZero contract addresses please take a look at the Gitbook here: https://layerzero.gitbook.io/

Read the currently set Oracle

npx hardhat --network mumbai omniCounterGetOracle --target-network fantom-testnet

Set a custom Oracle for the deployed OmniCounter

npx hardhat --network mumbai omniCounterSetOracle --target-network mumbai --oracle 0xORACLE_ADDR

See some examples in /contracts 🙌

Many of the example contracts make use of LayerZeroEndpointMock.sol which is a nice way to test LayerZero locally!

Most recently tested with node version 16.13.1

About

example contracts


Languages

Language:Solidity 58.4%Language:JavaScript 41.5%Language:Shell 0.1%