This document explains how to deploy contracts on two chains using LayerZero's OFT (for ERC20) and ONFT (for ERC721) with oftadapter
and onftadapter
- check here for Layerzero v2 documentation. These commands allow deploying two contracts on two separate blockchains for ERC20 and ERC721 tokens.
In the future, Layerzero will deploy also the adapter and the oft for ERC1155s, so for now, ERC1155 cannot be bridged with the lz-v2.
- Install dependencies
- Before starting
- Using the CLI to deploy an ERC20 bridge
- Deploying an OFT Bridge (ERC20)
- Deploying an ONFT Bridge (ERC721)
- Deployed Examples
- Coverage
To start, install the dependencies running npm i
ERC721 are not ready yet. For now only ERC20 are ok to go
This tool DOES NOT USES .env FILES TO STORE PRIVATE KEYS because it's so dangerous.
Instead, please import a wallet using cast (need to install foundry first).
This way, your private key will be secure in a keystore and you'll use your account using a password.
Below the steps to import a wallet using cast:
cast wallet import <name of account> --interactive
*** put your pwd***
// now your pk is secure in a keystore
IMPORTANT: Probabaly redundant to mention, but the password will be needed during the deployment scripts so don't forget/lose it!
Before you begin with calling the print scripts, create an .env file in the root of the project (see .env.example for reference).
For the ETHERSCAN_API_KEY set the value to your own API Key. Get one from: https://etherscan.io/register
You need to have Python installed on your system and install the required dependencies. Here's how to do it:
- Install Python: Ensure you have Python installed. You can download it from python.org if it's not already installed.
- Install Dependencies: Navigate to the directory containing your Python scripts and install the dependencies by running:
pip install -r requirements.txt
- Print the command to deploy bridge
python3 print_deploy_command.py
After running this command, you'll have printed a
make
command to be executed, like this:make deploy-oft-bridge ACCOUNT_NAME=beam-test-1 NAME=TESTEN SYMBOL=TTEN DELEGATE=0x7f50CF0163B3a518d01fE480A51E7658d1eBeF87 PERCENTAGE=10000000000000000 IS_PERMIT=false RPC_URL_A=https://build.onbeam.com/rpc/testnet CHAIN_ID_A=13337 RPC_URL_B=https://ethereum-sepolia-rpc.publicnode.com CHAIN_ID_B=11155111 TOKEN=0x779877A7B0D9E8603169DdbD7836e478b4624789
- Execute the printed make command eg:
`make deploy-oft-bridge ACCOUNT_NAME=beam-test-1 NAME=TESTEN SYMBOL=TTEN DELEGATE=0x7f50CF0163B3a518d01fE480A51E7658d1eBeF87 PERCENTAGE=10000000000000000 IS_PERMIT=false RPC_URL_A=https://build.onbeam.com/rpc/testnet CHAIN_ID_A=13337 RPC_URL_B=https://ethereum-sepolia-rpc.publicnode.com CHAIN_ID_B=11155111 TOKEN=0x779877A7B0D9E8603169DdbD7836e478b4624789`
- Print the command to wire the bridge
python3 print_wire_bridge_command.py
- Execute the printed make command
make wire-bridge ACCOUNT_NAME=beam-test-1 RPC_URL_A=https://build.onbeam.com/rpc/testnet CHAIN_ID_A=13337 RPC_URL_B=https://ethereum-sepolia-rpc.publicnode.com CHAIN_ID_B=11155111 PEER_A=0x22D8346837BaF22Ade1502a66fa60b4810b2d2b5 PEER_B=0x9667d750C1A554C5D81E191a46C67991A923B841
At this point you should have succesfully deploy the bridge.
This command deploys two contracts on two chains using the LayerZero OFT standard for ERC20 tokens with oftadapter
.
Commands for Deploying an OFT Bridge (ERC20)
make deploy-oft-bridge RPC_URL_A=<RPC url of chain where to deploy the oft token> CHAIN_ID_A=<chain id a> ACCOUNT_NAME=<your account> NAME=<name> SYMBOL=<symbol> DELEGATE=<the owner of the bridge> RPC_URL_B=<RPC url of chain where to deploy the adapter> CHAIN_ID_B=<chain id a> TOKEN=<address of token to wrap>
then run
make wire-bridge RPC_URL_A=<RPC url of chain where you deployed the oft token> CHAIN_ID_A=<chain id a> ACCOUNT_NAME=<your account> RPC_URL_B=<RPC url of chain whereyou deployed the oft adapter> CHAIN_ID_B=<chain id b> PEER_A=<contract deployed on chain A> PEER_B=<contract deployed on chain B>
make test-bridge RPC_URL=<RPC of the chain where I want to initiate the bridge> ACCOUNT_NAME=<your account> CONTRACT=<the contract of the OFT or OFTAdapter> CHAIN_ID=<Chain id of the network>
This command deploys two contracts on two chains using the LayerZero ONFT standard for ERC721 tokens with onftadapter
.
Commands for Deploying an ONFT Bridge (ERC721)
make deploy-onft-bridge RPC_URL_A=<RPC url of chain where to deploy the onft token> CHAIN_ID_A=<chain id a> ACCOUNT_NAME=<your account> NAME=<name> SYMBOL=<symbol> DELEGATE=<the owner of the bridge> RPC_URL_B=<RPC url of chain where to deploy the onft adapter> CHAIN_ID_B=<chain id a> TOKEN=<address of NFT token to wrap>
then run
make wire-bridge RPC_URL_A=<RPC url of chain where you deployed the onft token> CHAIN_ID_A=<chain id a> ACCOUNT_NAME=<your account> RPC_URL_B=<RPC url of chain whereyou deployed the onft adapter> CHAIN_ID_B=<chain id b> PEER_A=<contract deployed on chain A> PEER_B=<contract deployed on chain B>
That is coming soon
- deployed a mock NFT on sepolia: 0x75163daF35891308c3298F5d5898B1d09c7aC5F3
- onft on beam: 0xF5e30876DB81A0BFee35048c0F69b53Fc1f30660
- onft adapter on sepolia: 0x1b39C6BD162bfd0C1d8F8184fc2b4198a99ff56F
- beam oft: 0x8310D1b3eDD1fdC579733b522e3315f0EE8f4Da4
- sepolia oft adapter: 0xbab0169B7985F3f33b9e2d780Dd8f334E777aDE8
to run test coverage:
make run-coverage
current coverage:
File | % Lines | % Statements | % Branches | % Funcs |
---|---|---|---|---|
contracts/ERC20/BeamOFT.sol | 100.00% (14/14) | 100.00% (16/16) | 100.00% (5/5) | 100.00% (3/3) |
contracts/ERC20/BeamOFTAdapter.sol | 100.00% (14/14) | 100.00% (16/16) | 100.00% (5/5) | 100.00% (3/3) |
contracts/ERC20/base/BaseBeamBridge.sol | 100.00% (7/7) | 100.00% (8/8) | 100.00% (1/1) | 100.00% (3/3) |
Total | 100.00% (35/35) | 100.00% (40/40) | 100.00% (11/11) | 100.00% (9/9) |