Nerif Bridge: cross-chain bridge powered by Nerif Network

Roman Behma
3 min readMay 4, 2023

This article describes step-by-step instructions on how to create your own cross-chain bridge powered by Nerif Network. Two chains are going to be used for setting up the bridge: Goerli and Mumbai.

DO NOT USE FOR PRODUCTION PURPOSES. This bridge setup does not have proper security mechanisms, billing, and many other things that are needed for production use. The current state of Nerif Bridge shows a high-level overview of the bridging architecture using Nerif Network and can be used for demos only.

Requirements

  • Ethereum wallet with some funds on it. Goerli and Mumbai chains are going to be used.
  • Remix or hardhat CLI for smart contracts deployment and interaction with them.
  • Funded account within Nerif Network. Feel free to submit a request for early access to Nerif App: https://nerif.network/waitlist

Contracts deployment

Environment set-up instructions could be found in the bridge repository: https://github.com/begmaroman/nerif-bridge

Shortly, the bridge setup requires 3 different contracts to be deployed including the test receiver contract:

Gateway

Gateway contract is required by Nerif Network in order to secure the network and its users. The Gateway contract belongs to the customer and can be used as a trusted source of all transactions. This contract checks that the given transaction coming from the registry was made by the correct workflow created by the correct user.

This contract should be deployed on Polygon Mumbai network and registered per Registry.

Feel free to contact Nerif Network team in order to get an actual registry address.

This is my gateway contract: https://mumbai.polygonscan.com/address/0xaDF8D2685bDed7DF8Faf482d6FE729F4e8d9C6a6#readContract

NerifBridge

The simple bridge contract for sending and receiving messages. Should be deployed on both Goerli and Mumbai.

These are my NerifBridge contracts:

TestReceiver

The test receiver contract that is needed to test the bridge and receive a test message coming from Goerli to Mumbai via Nerif Network -> Registry -> Gateway -> NerifBridge -> TestReceiver.

The contract implements INerifBridgeReceiver interface in order to be compatible with NerifBridge:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

// INerifBridgeReceiver represents the behaviour of the Nerif Bridge receiver contract.
interface INerifBridgeReceiver {
// @notice Nerif Bridge will invoke this function to deliver the message on the destination.
// @param chainId is the chain ID of the sender contract.
// @param sender is the message sender address.
// @param payload is the bytes has encoded to be sent.
function nbReceive(
uint256 chainId,
address sender,
bytes calldata payload
) external;
}

This is my TestReceiver contract: https://mumbai.polygonscan.com/address/0x4AF67E3bFdA703E9Ec37c1BAaA3E545d7672DDa3

Nerif Network Workflow

After deploying and configuring all required contracts, the proper Nerif Network workflow should be created in order to power these contracts.

The workflow logic is very simple:

  1. Trigger the workflow when the specific event comes to the blockchain from the bridge contract. The event contains all the needed information/payload. Goerli is used as a sender network.
 event Send(uint256 chainId, address target, bytes payload, uint256 gasAmount, address sender)
  1. Check the chain ID and send a transaction to the bridge contract deployed on the Mumbai chain with the given payload.

Once the workflow is activated, the first test message could be sent out. It can be done by sending a direct transaction to send function of the bridge contract deployed on Goerli network or using the CLI command described in the official repository: https://github.com/begmaroman/nerif-bridge#test

Don’t forget to keep your balance funded within Nerif Network in order to don’t experience downtimes of your bridge.

Follow me on twitter for more insights: https://twitter.com/behmarom

--

--

Roman Behma

Designing decentralized future | Software architect | Blockchain expert | Entrepreneur | Building a more connected and equitable world through innovation