55 releases (6 stable)

2.0.0 Mar 26, 2024
1.1.2 Nov 23, 2023
1.1.0 Jun 20, 2023
1.0.1 Dec 19, 2022
0.1.0 Jul 7, 2020

#1 in #cw20

Download history 4616/week @ 2024-07-21 3735/week @ 2024-07-28 2294/week @ 2024-08-04 5213/week @ 2024-08-11 2643/week @ 2024-08-18 3107/week @ 2024-08-25 3738/week @ 2024-09-01 3379/week @ 2024-09-08 2900/week @ 2024-09-15 3148/week @ 2024-09-22 2821/week @ 2024-09-29 2636/week @ 2024-10-06 3995/week @ 2024-10-13 3804/week @ 2024-10-20 3617/week @ 2024-10-27 2888/week @ 2024-11-03

14,507 downloads per month
Used in 126 crates (104 directly)

Apache-2.0

165KB
3.5K SLoC

CW20 Basic

This is a basic implementation of a cw20 contract. It implements the CW20 spec and is designed to be deployed as is, or imported into other contracts to easily build cw20-compatible tokens with custom logic.

Implements:

  • CW20 Base
  • Mintable extension
  • Allowances extension

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_base.wasm .
ls -l cw20_base.wasm
sha256sum cw20_base.wasm

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

Importing this contract

You can also import much of the logic of this contract to build another ERC20-contract, such as a bonding curve, overiding or extending what you need.

Basically, you just need to write your handle function and import cw20_base::contract::handle_transfer, etc and dispatch to them. This allows you to use custom ExecuteMsg and QueryMsg with your additional calls, but then use the underlying implementation for the standard cw20 messages you want to support. The same with QueryMsg. You could reuse instantiate as it, but it is likely you will want to change it. And it is rather simple.

Look at cw20-staking for an example of how to "inherit" all this token functionality and combine it with custom logic.

Dependencies

~4–7.5MB
~153K SLoC