Cross L1 bridge PoC
Check .env.example
for required environment variables and fill them in your own .env
.
Wallet:
WALLET_PRIVATE_KEY
: Wallet private key shared for L1
RPC:
KOVAN_RPC_URL
: Kovan rpc urlRINKEBY_RPC_URL
: Rinkeby rpc url
This project is aim for EVM-compatible chains, currently it supports
Kovan
andRinkeby
. Chains can be expanded easily, please refer to Expand Chain for more details.
You need to get ETH to the wallet set in environment for chains you want to operate.
- Kovan faucet: https://github.com/kovan-testnet/faucet
- Rinkeby faucet: https://faucet.rinkeby.io
yarn install
yarn build
yarn migration:up
Start a L1 bridge with following command:
yarn execute bridge/L1
This command will spin up a watcher and a worker:
- Watcher: Wait for withdraws and record them.
- Worker: Confirm and finalize withdraws and deposit them to destination on other chain.
After bridge starts, you can mint TKN
, which is our test token, on specific chain by below command:
yarn execute scripts/mint.ts --help
Options:
--version Show version number [boolean]
-c, --chain Chain name or id [string] [required]
-h, --help Show help [boolean]
# mint 100 TKN for Rinkeby
yarn execute scripts/mint.ts -c 4
# mint 100 TKN for Kovan
yarn execute scripts/mint.ts -c 42
With enough TKN
, you can withdraw them cross chains with below command:
yarn execute scripts/withdraw.ts --help
Options:
--version Show version number [boolean]
-f, --from From chain name or id [string] [required]
-t, --to To chain name or id [string] [required]
-h, --help Show help [boolean]
# withdraw 10 TKN from Rinkeby to Kovan
yarn execute scripts/withdraw.ts -f 4 -t 42
Go and check the terminal running bridge or logger/logger.log
to see what is happening.
To support new EVM-compatible chain, here are the steps:
- Add
{CHAIN}_RPC_URL
to environment variable. - Add new chain to
network/chain.ts
. - Add new chain network to
hardhat.config.ts
. - Deploy
TKN
to that chain viahardhat --network {chain} deploy --no-compile
. - Register new deployed
TKN
contract tonetwork/contract.ts
.
That's it. You can withdraw TKN
to this new chain.