Create a Cross-EVM bridge using Solidity, Typescript, Hardhat & ethers.js

By akohad Dec5,2023

[ad_1]

Create your own bridge in 30 minutes!

If you’re reading this I assume you know what EVM, bridging, smart contracts and bots are. So without wasting time, I would like to get straight into the weeds. For this tutorial, we will be using sepolia and mumbai testnets. A prerequisite for you to follow along is that you have installed Node.js and npm on your computer.

This is how our Bridging infrastructure will look like:

If you know what you’re doing and would like to get straight to the source code, you can find it here: https://github.com/AngSin/cross-evm-bridge. But if you would like to follow along step by step, let’s get to it!

Let’s create the directory we will be working in:

mkdir cross-evm-bridge
cd cross-evm-bridge
npm init -y
npm install --save-dev hardhat

Then we can initialize the hardhat project by:

npx hardhat init

Go down and pick the Create a TypeScript Projectoption, because we love TypeScript😄.

We will need a sample ERC20 token contract to test out our bridge with. To do this, let’s install OpenZeppelin, which will give us the base for our ERC20 token contract:

npm i @openzeppelin/contracts

OpenZeppelin uses 0.8.20 version of Solidity, so let’s also go to our hardhat.config.ts file and change the version there like so:

// hardhat.config.ts
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
solidity: "0.8.20",
};

export default config;

Our set up for OpenZeppelin is now complete. We can now use it to quickly create a basic ERC20 token like so:

// contracts/MyToken.sol
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
constructor() ERC20("MyToken", "MTK") {
_mint(msg.sender, 2_000 ether);
}
}

[ad_2]

Source link

By akohad

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *