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.
- Mint Tokens: Mint tokens to a specific address.
- Burn Tokens: Burn tokens and initiate a bridge to another chain.
- Reentrancy Protection: Utilizes OpenZeppelin's
ReentrancyGuardto prevent reentrancy attacks. - Custom Error Handling: Implements custom errors for invalid operations.
- Event Emission: Emits events to track token bridging activities.
- Node.js (>=14.x)
- npm or yarn
- Hardhat (Ethereum development environment)
- OpenZeppelin Contracts
git clone https://github.com/chain-builders/Token-Bridge.git
cd bridgebaseInstall the required npm packages:
npm install
# or
yarn installCompile the smart contracts using Hardhat:
npx hardhat compileDeploy 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).
Run the test cases to ensure everything is working correctly:
npx hardhat test- 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.
function mintTokens(address to, uint256 amount, bytes32 sourceTx)to: Address to mint tokens to.amount: Amount of tokens to mint.sourceTx: Source transaction hash.
function burnTokens(uint256 amount, string memory targetChain)amount: Amount of tokens to burn.targetChain: Target chain identifier.
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.
Error.InvalidTokenAddress(): Thrown when the token address is invalid.Error.InsufficientAmount(): Thrown when the amount is zero.
Setup to get React working in Vite
Currently, two official plugins are available:
- @vitejs/plugin-react uses Babel for Fast Refresh
- @vitejs/plugin-react-swc uses SWC for Fast Refresh
-
Install Dependencies: Ensure you have Node.js installed. Then, navigate to the
Frontenddirectory and run:npm install
-
Start the Development Server: To start the development server, run:
npm run dev
-
Build for Production: To build the project for production, run:
npm run build
-
Preview the Production Build: To preview the production build locally, run:
npm run serve
-
Linting: To run ESLint and check for linting issues, run:
npm run lint
-
Testing: (If applicable) To run tests, use:
npm test
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.
To get started with the backend, follow these steps:
-
Clone the repository:
git clone https://github.com/chain-builders/Token-Bridge.git cd Token-Bridge/Backend -
Install the dependencies:
npm install
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.
To start the backend, run the following command:
node index.jsThe backend will listen to events from the bridge contracts on both Sepolia and Mumbai test networks and handle token bridging between the two networks.
index.js: Main file that sets up the event listeners for the bridge contracts.abis/: Directory containing the ABI files for the bridge contracts.