Coder Social home page Coder Social logo

cw20-sale-contract's Introduction

CW20 Sale Contract

This contract enables the sale of CW20 tokens for native tokens. CW20 tokens are deposited and a price in native tokens is set by the instantiator of the contract. The insantiator can change price and withdraw remaining CW20 tokens at any time. Funds used to purchase tokens are automatically transferred to the instantiator's bank balance.

Using the contract

Instantiate

wasmd tx wasm instantiate <code_id> '{"cw20_address":"<cw20_contract_address>", "denom":"<denom>", "price":"<price>"}' --from <address> --label="<label>" --gas="auto" --chain-id="<chain_id>"

Deposit CW20 Tokens

wasmd tx wasm execute <cw20_contract_address> '{"send":{"amount":"<amount>","contract":"<sale_contract_address>","msg":""}}' --from <address> --chain-id="<chain_id>"

Set Price

Can only be called by the instantiator.

wasmd tx wasm execute <sale_contract_address> '{"set_price":{"price":"<amount>","denom":"<denom>"}}' --amount "<funds (ie 1uatom)>" --from <creator address> --chain-id="<chain_id>"

Get Price

wasmd query wasm contract-state smart <sale_contract_address> '{"get_price":{}}' --chain-id="<chain_id>"

Get CW20 Token Balance

wasmd query wasm contract-state smart <sale_contract_address> '{"get_balance":{}}' --chain-id="<chain_id>"

Buy

Please check price and CW20 token balance before making a purchase.

The contract determines correct quantity of CW20 tokens to transfer to the buyer based off the price and amount of native tokens sent. After a purchase, the native token funds are automatically transferred to the creators bank balance.

wasmd tx wasm execute <sale_contract_address> '{"buy":{}}' --amount "<funds (ie 1uatom)>" --from <address> --chain-id="<chain_id>"

Withraw Tokens

Can only be called by the instantiator.

wasmd tx wasm execute <sale_contract_address> '{"withdraw_all":{}}' --from <creator address> --chain-id="<chain_id>"

cw20-sale-contract's People

Contributors

ben2x4 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.