Skip to content

xionspace/dw-contracts

Repository files navigation

DripVerse Smart Contracts for COSMOS

NOTE: Derived from CW721 contracts. All customisations follows on top of it.

Build

Prepare System:

  1. Install Rust
  2. Install Wasm rust compiler backend: rustup target add wasm32-unknown-unknown
  3. Install Golang
  4. Setup wasmd:
git clone git@github.com:CosmWasm/wasmd.git
cd ./wasmd
make install

In case of any other chain specific binary, install that. For example, setup xiond for Xion Chain.

  1. [Optional] Setup cosmwasm-check utiltiy:
cargo install cosmwasm-check

Check if the installation worked:

cosmwasm-check --version

Verify setup with cw-plus.

Build WASM

cargo wasm

Built wasm file can be found as in: ./target/wasm32-unknown-unknown/release/dw_721.wasm We'll use this to deploy.

Now we upload the code on chain:

xiond tx wasm store ./target/wasm32-unknown-unknown/release/dw_721.wasm \
    --chain-id xion-testnet-1 \
    --gas-adjustment 1.3 \
    --gas-prices 0uxion \
    --gas auto \
    --node https://rpc.xion-testnet-1.burnt.com:443 \
    --from wallet

[Optional] Optimise Compilation

If your code is too big or spread out, it's always a good idea to optimise it. Easiest way is to use this docker image:

docker run --rm -v "$(pwd)":/code \
    --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
    --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
    cosmwasm/rust-optimizer:0.15.0

The optimised code will be in ./artifacts. Now, deploy this:

xiond tx wasm store ./artifacts/dw_721.wasm \
    --chain-id xion-testnet-1 \
    --gas-adjustment 1.3 \
    --gas-prices 0uxion \
    --gas auto \
    --node https://rpc.xion-testnet-1.burnt.com:443 \
    --from wallet
xiond tx wasm store ./artifacts/cw20_base.wasm \
    --chain-id xion-testnet-1 \
    --gas-adjustment 1.3 \
    --gas-prices 0uxion \
    --gas auto \
    --node https://rpc.xion-testnet-1.burnt.com:443 \
    --from genesis

This should upload the contract code on chain. We'll get a CODE_ID which we can use to really deploy it. Or as cosmwasm calls it, instantiate it.

Can also check the list of WASM Contracts currently deployed:

xiond query wasm list-codes

Finally, we are ready to deploy:

set the initial state of the instance

Example for dw-721:

export INIT='{"name": "Xion NFT", "symbol": "XNT", "minter": "xion1gxasu43e4wt89gjpfp4vhm977yf356x786w9c7"}'

Example for cw20-base:

export INIT='{"name":"XionSpace Test","symbol":"XST","decimals":6,"initial_balances":[{"amount":"1000000000000000000","address":"xion1gxasu43e4wt89gjpfp4vhm977yf356x786w9c7"}],"mint":{"minter":"xion1gxasu43e4wt89gjpfp4vhm977yf356x786w9c7"},"marketing":{}}'

instantiate the contract

For dw-721:

xiond tx wasm instantiate $CODE_ID "$INIT" \
    --from wallet \
    --label "Xion NFT" \
    --gas-prices 0uxion \
    --gas auto \
    --gas-adjustment 1.3 \
    -y --no-admin

For cw20-base:

xiond tx wasm instantiate $CODE_ID "$INIT" \
    --from wallet \
    --label "XionSpace Test" \
    --gas-prices 0uxion \
    --gas auto \
    --gas-adjustment 1.3 \
    -y --no-admin

Check the Xion Explorer with txhash as returned in response to verify.

Find the contract address:

xiond query wasm list-contract-by-code $CODE_ID --output json

🎉 And we done.

Cache Clear

cargo install cargo-cache
cargo cache -a

Contributing

If you are working on an NFT project as well and wish to give input, please raise issues and/or PRs. Additional maintainers can be added if they show commitment to the project.

You can also join the #dev-general channel under Developer Zone on DripVerse Discord for more interactive discussion on these themes. You would need a dev role. Either you can set it yourself while joining the server, or just ping one of the Mods to help you out.

About

DripVerse Smart Contracts for COSMOS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •