Skip to content

Token-Bridge is a Solidity smart contract that facilitates token bridging between different blockchains. It allows the minting and burning of tokens, ensuring secure and seamless token transfers.

Notifications You must be signed in to change notification settings

chain-builders/Token-Bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Token-Bridge Smart Contract

Token-Bridge is a Solidity smart contract that facilitates token bridging between different blockchains. It allows the minting and burning of tokens, ensuring secure and seamless token transfers.

Features

  • Mint Tokens: Mint tokens to a specific address.
  • Burn Tokens: Burn tokens and initiate a bridge to another chain.
  • Reentrancy Protection: Utilizes OpenZeppelin's ReentrancyGuard to prevent reentrancy attacks.
  • Custom Error Handling: Implements custom errors for invalid operations.
  • Event Emission: Emits events to track token bridging activities.

Prerequisites

  • Node.js (>=14.x)
  • npm or yarn
  • Hardhat (Ethereum development environment)
  • OpenZeppelin Contracts

Getting Started

1. Clone the Repository

git clone https://github.com/chain-builders/Token-Bridge.git
cd bridgebase

2. Install Dependencies

Install the required npm packages:

npm install
# or
yarn install

3. Compile the Contracts

Compile the smart contracts using Hardhat:

npx hardhat compile

4. Deploy the Contracts

Deploy the contracts to your desired network:

npx hardhat run scripts/deploy.js --network <network-name>

Replace <network-name> with the network to which you want to deploy (e.g., ropsten, mainnet).

5. Run Tests

Run the test cases to ensure everything is working correctly:

npx hardhat test

Project Structure

  • contracts/: Contains the Solidity smart contracts.
    • BridgeBase.sol: Main contract for token bridging.
    • BridgeBaseAbstract.sol: Abstract base contract.
    • library/Errors.sol: Custom error definitions.
    • library/Events.sol: Custom event definitions.
    • tokens/Bbl.sol: BBL token contract.
  • scripts/: Deployment scripts.
  • test/: Test cases for the smart contracts.

Example Usage

Minting Tokens

function mintTokens(address to, uint256 amount, bytes32 sourceTx)
  • to: Address to mint tokens to.
  • amount: Amount of tokens to mint.
  • sourceTx: Source transaction hash.

Burning Tokens

function burnTokens(uint256 amount, string memory targetChain)
  • amount: Amount of tokens to burn.
  • targetChain: Target chain identifier.

Events

  • Event.BridgeFinalized(address to, uint256 amount, bytes32 sourceTx): Emitted when tokens are minted.
  • Event.BridgeInitiated(address from, uint256 amount, string targetChain, bytes32 hash): Emitted when tokens are burned.

Errors

  • Error.InvalidTokenAddress(): Thrown when the token address is invalid.
  • Error.InsufficientAmount(): Thrown when the amount is zero.

Frontend features and framework

React + TypeScript + Vite

Setup to get React working in Vite

Currently, two official plugins are available:

Instructions on How to Run the Frontend Framework

  1. Install Dependencies: Ensure you have Node.js installed. Then, navigate to the Frontend directory and run:

    npm install
  2. Start the Development Server: To start the development server, run:

    npm run dev
  3. Build for Production: To build the project for production, run:

    npm run build
  4. Preview the Production Build: To preview the production build locally, run:

    npm run serve
  5. Linting: To run ESLint and check for linting issues, run:

    npm run lint
  6. Testing: (If applicable) To run tests, use:

    npm test

Token-Bridge Backend

This is the backend description for the Token-Bridge project, which facilitates bridging tokens between Sepolia and Mumbai Ethereum test networks. The backend is implemented using Node.js and the ethers.js library to interact with the Ethereum blockchain.

Installation

To get started with the backend, follow these steps:

  1. Clone the repository:

    git clone https://github.com/chain-builders/Token-Bridge.git
    cd Token-Bridge/Backend
  2. Install the dependencies:

    npm install

Configuration

Create a .env file in the Backend directory and add the following environment variables:

SEPOLIA_RPC=<Your Sepolia RPC URL>
MUMBAI_RPC=<Your Mumbai RPC URL>
PRIVATE_KEY=<Your Wallet Private Key>
BRIDGE_SEPOLIA=<Bridge Contract Address on Sepolia>
BRIDGE_BASE=<Bridge Contract Address on Mumbai>

Replace the placeholders with your actual values.

Usage

To start the backend, run the following command:

node index.js

The backend will listen to events from the bridge contracts on both Sepolia and Mumbai test networks and handle token bridging between the two networks.

Project Structure

  • index.js: Main file that sets up the event listeners for the bridge contracts.
  • abis/: Directory containing the ABI files for the bridge contracts.

About

Token-Bridge is a Solidity smart contract that facilitates token bridging between different blockchains. It allows the minting and burning of tokens, ensuring secure and seamless token transfers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 8