Giter Club home page Giter Club logo

ether-cross-chain-swap's Introduction

README

This Ethereum smart contract demonstrates an 'Atomic cross-chain swap between different blockchain networks' and is based on the NEM cross-chain swap functionality. The blockchains needs to support Hashed TimeLock Contract or HTLC for a trustless environment for swaps. In NEM Blockchain these are described as 'secret lock' and 'secret proof' functionalities. It's possible with Ethereum, Bitcoin, NEM, NEO and several other protocols.

However, whether it is real 'Atomic' is a valid point to discuss. Nevertheless both parties have a strong incentive to fullfill the rules.

How it works

Lets say Alice wants to convert ETH to NEM:XEM and Bob NEM:XEM to Ether.

The steps required are illustrated in the diagram below.

Transaction Network Sender
TX1 secretLock(uint256 _lockTimeSec, bytes32 _hash, address _recipient) Ethereum Rinkeby Testnet Alice
TX2 SecretLockTransaction.create(Deadline.create(), new Mosaic(new MosaicId('nem:xem'), exchangeValue), lockTime, HashType.SHA3_512, secret, aliceNEM.address, NetworkType.MIJIN_TEST) NEM Catapult Private Chain Bob
TX3 SecretProofTransaction.create( Deadline.create(), HashType.SHA3_512, secret, proof, NetworkType.MIJIN_TEST) NEM Catapult Private Chain Alice
TX4 secretProof(bytes32 _hash, bytes _proof) Ethereum Rinkeby Testnet Bob

Hint: Note that the wording in this Ethereum smart contract is a bit different as in the NEM documentation. For some, the NEM naming can be confusing, because secret represents a hash of a proof. However, consider that the hashing algorithm also needs to be revealed for the swap to work and that's why it could be confused with the hash term.

Notes

Web3 version 1.x is installed with NPM. Also Truffle comes with Web3 0.2x. The API of these Web3 are not always compatible.

ether-cross-chain-swap's People

Contributors

dexterslabor avatar kabl avatar

Watchers

 avatar  avatar

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.