Giter Club home page Giter Club logo

cw20's Introduction

Atomic Swaps + TS-codegen

@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.

This is a contract that allows users to execute atomic swaps. It implements one side of an atomic swap. The other side can be realized by an equivalent contract in the same blockchain or, typically, on a different blockchain.

Each side of an atomic swap has a sender, a recipient, a hash, and a timeout. It also has a unique id (for future calls to reference it). The hash is a sha256-encoded 32-bytes long phrase. The timeout can be either time-based (seconds since midnight, January 1, 1970), or block height based.

The basic function is, the sender chooses a 32-bytes long phrase as preimage, hashes it, and then uses the hash to create a swap with funds. Before the timeout, anybody that knows the preimage may decide to release the funds to the original recipient. After the timeout (and if no release has been executed), anyone can refund the locked tokens to the original sender. On the other side of the swap the process is similar, with sender and recipient exchanged. The hash must be the same, so the first sender can claim the funds, revealing the preimage and triggering the swap.

See the IOV atomic swap spec for details.

Token types

Currently native tokens are supported; an upcoming version will support CW20 tokens.

Running this contract

You will need Rust 1.44.1+ with wasm32-unknown-unknown target installed.

You can run unit tests on this via:

cargo test

Once you are happy with the content, you can compile it to wasm via:

RUSTFLAGS='-C link-arg=-s' cargo wasm
cp ../../target/wasm32-unknown-unknown/release/cw20_atomic_swap.wasm .
ls -l cw20_atomic_swap.wasm
sha256sum cw20_atomic_swap.wasm

Or for a production-ready (optimized) build, run a build command in the the repository root: https://github.com/CosmWasm/cw-plus#compiling.

cw20

cw20's People

Watchers

 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.