A simple & secured bridge for EVM-compatible blockchain networks. The bridge consists of two components:
- Smart contracts for the token and the bridge API, deployed on the blockchain networks you wish to link together
- A centralized NodeJS server to subscribe to deployed contracts' events, and trigger actions.
- Simple to implement
- Test cases coverage
- Available scripts to deploy, test, and interact with the deployed contracts
- Currently operates on 3 testnets: Goerli, Rinkeby, and BNB Testnet.
- Clone this repo
- Run
npm install
- Create an
.env
base on.env.example
. Network urls could and project ID should be taken from an Infura project (Infura is provide the layer to communicate with the blockchain. Create an account if you don't have one). Provide private keys for DEPLOYER and BRIDGE_ADMIN and remember to fund these accounts with native token.
The token contract should be very simple and standard. Two essential features to make bridging possible (OpenZeppelin is recommended):
- The ability to mint/burn tokens and
- Access Control to grant Minter/Burner Role
- The bridge contract should be able authorized by the token contract to mint/burn tokens.
- Bridge has an admin to run some centralized actions on the NodeJS server
- Bridge emits events for the server to subscribe to and run the logic
- A NodeJS server with chain configs and bridge admin's private key
- Has scripts to subscribe and trigger actions
- Users wish to "bridge" some tokens from chain A to chain B must transfer tokens to the bridge address (These tokens is withdrawable if the user doesn't want to bridge anymore)
- Everytime an user transfer token to the bridge's address, bridge's admin calls
lock
function to record the transfered amount. - Users call the
burn
function in the bridge's contract with theamount
andchainId
as parameters.amount
of tokens will be burnt from the source chain and aBurn
event is emitted. - Every time
Burn
event is emitted, admin bridge calls themint
function to the target chain (according to thechainId
) to mint the burnt amount to the sender.
- Remove the deployments folder to clear the deployed contract data
- Open terminal, run
npx hardhat --network bsc-testnet deploy --tags deploy-token && npx hardhat --network rinkeby deploy --tags deploy-token && npx hardhat --network goerli deploy --tags deploy-token
to deploy tokens on testnets - After deploying tokens, run
npx hardhat --network bsc-testnet deploy --tags deploy-bridge && npx hardhat --network rinkeby deploy --tags deploy-bridge && npx hardhat --network goerli deploy --tags deploy-bridge
to deploy bridges on testnets - Run
npx hardhat run ./scripts/manage.ts
to authorized bridges' addresses as minter and burner - Run
npx hardhat run ./scripts/antena.ts
to set up the subscribers & action triggers. Leave the terminal running and don't close it. - Open another terminal window, run
npx hardhat run ./scripts/interaction.ts
to run some sample transactions to "transfer tokens to bridge contract" and "bridge token to another chain" - (Optional) run
npx hardhat test
ornpx hardhat coverage
to see test coverage results.