Giter VIP home page Giter VIP logo

crosschain's Introduction

Cross Chain Transaction

About

Create token bridge between Ethereum & Binance Smart Chain, allow to transfer token between 2 chains by destorying (burn) one token on one chain and recreating (mint) same token on other chain.

Architecture:

  1. Bridge contracts for each chain
  2. Bridge API in between to listen event emit and operate accordingly
  3. TokenBase.sol : an ERC20 token contract which has mint and burn function
  4. TokenEth.sol , TokenBsc.sol : tokens on both Ethereum and BSC which inherit TokenBase
  5. BridgeBase.sol : bridge base contract inherit by bridge contract for both chain
  6. eth-bsc-bridge.js : bridge API

Example : Transfer token from Ethereum to BSC:

  1. Send the token to bridge contract of Ethereum which burns the token
  2. Event is emitted with the details of the transfer including recipient on BSC and amount
  3. Bridge API receive the transfer event singal and send a transaction to the bridge contract of BSC
  4. Mint the same token with the same amount and send it to the recipient address

Avoid common attack

Build a re-entrancy guard with an array which store boolean value of a variable nonce. It is false when the transfer was initalized. It is set to true once the transfer is executed. It makes sure each transfer can be performed only once.

Pre-requisites and programs used versions:

  • Truffle v5.1.7 (core: 5.1.7)
  • Solidity v0.8.0 (solc-js)
  • Node v10.17.0
  • npm 6.11.3
  • Openzeppelin

Setting up the development environment

  1. Install Truffle:

    npm install -g truffle

  2. Install Openzepplin

    npm install @openzeppelin/[email protected]

  3. Install npm

    npm install

  4. From infura.io, get the rinkeby websocket testnet address

  5. Use an ethereum address, get some rinkeby Eth from Rinkeby Authenticated Faucet site

  6. Use an ethereum address, get some BNB from BSC Faucet site

Testing

  1. Migrate to ETH and BSC testnet
    • truffle migrate --reset --network ethTestnet
    • truffle migrate --reset --network bscTestnet
  2. Check inital balances:
    • truffle exec scripts/eth-token-balance.js --network ethTestnet , ETH balance should have 1000
    • truffle exec scripts/bsc-token-balance.js --network bscTestnet , BSC balance should be 0
  3. Open a new terminal A and run the bridge API
    • truffle exec
    • node scripts/eth-bsc-bridge.js
  4. On other terminal B and transfer 1000 from ETH to BSC:
    • truffle exec scripts/eth-bsc-transfer.js --network ethTestnet
    • In Terminal A, bridge API detects an event and trigger the mint function, process the transfer
  5. Check new balance:
    • truffle exec scripts/eth-token-balance.js --network ethTestnet , ETH balance should have 0
    • truffle exec scripts/bsc-token-balance.js --network bscTestnet , BSC balance should be 1000

Project developed by : Solidity, smart contract, web3, node.js

Refrences

Web3: https://youtube.com/playlist?list=PLS5SEs8ZftgXXPYBH6rDk4TKnDOvinwJr

Crosschain : https://docs.symbolplatform.com/concepts/cross-chain-swaps.html , https://andrecronje.medium.com/deploying-your-own-cross-chain-token-101-240420efd0d9 , https://www.binance.com/en/blog/421499824684901059/The-Panama-Project-Making-OneClick-CrossChain-Connection-Possible

Bridge between the tokens : https://forum.openzeppelin.com/t/how-to-make-a-bridge-token-between-ethereum-and-binance-smart-chain/4628 , https://medium.com/the-liquidapps-blog/cross-chain-bridge-guide-for-experts-947210576668

For reference : https://github.com/rsksmart/tokenbridge , https://github.com/oraclesorg/treasury

crosschain's People

Contributors

preeti13456 avatar preetjecrc avatar

Stargazers

 avatar Pwntr0n avatar

Watchers

James Cloos avatar  avatar

Forkers

cloverpatchcore

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.