Skip to content

ChihuahuaChain/Chiwawasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chiwawasm

Rust

 

This repository is a collection of smart contracts built with the cosmwasm framework.

The repo's organization is relatively simple. The top-level directory is just a placeholder and has no real code. And we use workspaces to add multiple contracts below. This allows us to compile all contracts with one command.

 

Usage

The following contracts are available for use. For each of the contracts in ./contracts, you can view the source code under src

 

Burn-Contract

A basic contract to burn token balances.

 

Tokens-Manger

The cw20 tokens manager allow users to pay a token_creation_fee to mint cw20 tokens managed by this contract.

 

Token-Swap

A constant product (AMM) implementation that allows the trading of any CW20 or IBC tokens quoted against the base token (HUAHUA).

 

Preparing for merge

Before you merge the code, make sure it builds and passes all tests using the command below.

$ cargo test

 

Release builds

You can build release artifacts manually like this, which creates a reproducible optimized build for each contract and saves them to the ./artifacts directory:

$ 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.12.6

 

Working with smart contracts (chihuahuad)

(See instructions on how install chihuahuad)

 

View chihuahuad config variables

$ open ~/.chihuahua/config/config.toml

 

Generate a new cosm-wasm project from template

$ cargo install cargo-generate --features vendored-openssl

$ cargo generate --git <https://github.com/CosmWasm/cosmwasm-template.git> --name my-first-contract

 

Testnet block explorers

https://testnet.ping.pub/chihuahua

https://testnet.explorer.erialos.me/chihuahua

 

Add test accounts

$ chihuahuad keys add <wallet_name> --recover

 

List test accounts

$ chihuahuad keys list

 

Export variables for use in terminal (zsh)

$ source ~/.profile

$ export CHAIN_ID="chitestnet-5"

$ export RPC="https://chihuahua-testnet-rpc.polkachu.com:443"

$ export NODE=(--node $RPC)

$ export TXFLAG=($NODE --chain-id $CHAIN_ID --gas-prices 0.25stake --gas auto --gas-adjustment 1.3)

$ export TXFLAG_LOCAL=(--gas-prices 0.25stake --gas auto --gas-adjustment 1.3 --keyring-backend test)

 

Query balances

$ chihuahuad query bank total $NODE

$ chihuahuad query bank balances $(chihuahuad keys show -a palingram) $NODE

 

Send funds to other account

$ chihuahuad tx bank send <sender_account_name> <receiver_address> <amount><denom> $TXFLAG

 

See the list of code uploaded to the testnet

$ chihuahuad query wasm list-code $NODE

 

Store the contract on the blockchain and get the <CODE_ID>

$ export RES=$(chihuahuad tx wasm store artifacts/<contract_name.wasm> --from <account_name> $TXFLAG -y --output json -b block)

$ export CODE_ID=$(echo $RES | jq -r '.logs[0].events[-1].attributes[0].value')

$ echo $CODE_ID

 

Get a list of contracts instantiated for <CODE_ID>

$ chihuahuad query wasm list-contract-by-code $CODE_ID $NODE --output json

 

Prepare the json message payload

$ export INIT='{}'

 

Instantiate the contract

$ chihuahuad tx wasm instantiate $CODE_ID "$INIT" --from <account_name> --label "BURN TEST CONTRACT" $TXFLAG -y --no-admin

 

Get the latest contract instantiated for contract with $CODE_ID

$ export CONTRACT=$(wasmd query wasm list-contract-by-code $CODE_ID $NODE --output json | jq -r '.contracts[-1]')

$ echo $CONTRACT

 

Check the contract details

$ chihuahuad query wasm contract $CONTRACT $NODE

 

Check the contract balance

$ chihuahuad query bank balances $CONTRACT $NODE

 

query the entire contract state

$ chihuahuad query wasm contract-state all $CONTRACT $NODE

 

query the data for a storage key in the contract-state directly

$ chihuahuad query wasm contract-state raw $CONTRACT 636F6E666967 $NODE  --output "json" | jq -r '.data' | base64 -d

 

Calling execute methods

$ export E_PAYLOAD='{"burn_contract_balance":{}}'

$ chihuahuad tx wasm execute $CONTRACT "$E_PAYLOAD" --amount 1000000000stake --from palingram $NODE $TXFLAG -y

 

calling query methods

$ export Q_PAYLOAD='{"query_list":{}}'

$ chihuahuad query wasm contract-state smart $CONTRACT "$Q_PAYLOAD" $NODE --output json

About

ChihuahuaChain CosmWasm contracts repository

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages