---
# System prepended metadata

title: 'Deploy, init and interact with cw20 using wasmd'

---

# Deploy, init and interact with cw20 using wasmd
#### Upload cw20 contract
`$ RES=$(wasmd tx wasm store artifacts/cw20_base.wasm --from wallet $TXFLAG -y --output json -b block)`
>gas estimate: 2344339

`$ CODE_ID=$(echo $RES | jq -r '.logs[0].events[-1].attributes[0].value')`
#### Setting wallet address as owner
`$ OWNER="wasm120zfx98pk3fd469hps4rgf0que4lgraz02035c"`
#### Set init parameters
`$ INIT=$( jq -n --arg address $OWNER '{ "name": "BTOK", "symbol": "BTOK", "decimals": 6, "initial_balances": [ { "address": $address, "amount": "1000000" } ], "mint": { "minter": $address, "cap": "99900000000" } }' | tee /dev/tty )`
>{
  "name": "BTOK",
  "symbol": "BTOK",
  "decimals": 6,
  "initial_balances": [
    {
      "address": "wasm120zfx98pk3fd469hps4rgf0que4lgraz02035c",
      "amount": "1000000"
    }
  ],
  "mint": {
    "minter": "wasm120zfx98pk3fd469hps4rgf0que4lgraz02035c",
    "cap": "99900000000"
  }
}

#### Initialize smart contract
`$ wasmd tx wasm instantiate $CODE_ID "$INIT" --from wallet --label "CW20" --no-admin $TXFLAG -y`
> gas estimate: 208817
logs: []
raw_log: '[]'
txhash: 97599DBF9E4625090F48329E0DAD1B6152F1B315022AB767A27382144297844E

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

#### Check the contract state
`$ wasmd query wasm contract $CONTRACT $NODE`
>address: wasm17r53vvjedjycurxr3l4qfuchwxgdk0qlz2d0gvzvffj76weejmeqkj38ld
contract_info:
  code_id: "1293"
  creator: wasm120zfx98pk3fd469hps4rgf0que4lgraz02035c
  label: CW20

### Examples of interaction
`$ wasmd keys add alice`
>\- name: alice
  type: local
  address: wasm1ec80a28dggwt6zkpu6j4l3akqs55gcp2gnncjn
  pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A2eYajnny7IXlM89Q9dhRz/BSM5ABUZf/aBMw2nPDU2X"}'
  mnemonic: ""
**Important** write this mnemonic phrase in a safe place.

`$ wasmd keys add bob`
>\- name: bob
  type: local
  address: wasm1e24lgetlul0ercjwglfvrxtd46lp4k2mmkeupu
  pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A/ipwcnFO+/x7i+CUhDGuTj0ohEx4hpkBSJN6AayeCGA"}'
  mnemonic: ""
**Important** write this mnemonic phrase in a safe place.

`$ ALICE=$( wasmd keys show -a alice | tee /dev/tty | tail -1 | tr -d '\r' )`
wasm1ec80a28dggwt6zkpu6j4l3akqs55gcp2gnncjn

`$ BOB=$( wasmd keys show -a bob | tee /dev/tty | tail -1 | tr -d '\r' )`
wasm1e24lgetlul0ercjwglfvrxtd46lp4k2mmkeupu

#### Mint CW20 tokens
#### Mint 1M tokens to Bob:

`$ MINT=$( jq -n --arg recipient $BOB '{ "mint": { "recipient": $recipient, "amount": "1000000" } }' | tee /dev/tty )`
>{
  "mint": {
    "recipient": "wasm1c7lxt5x2zfpsrllw3p06xlt6yanpm2xcmm5wy4",
    "amount": "1000000"
  }
}

`$ wasmd tx wasm execute $CONTRACT "$MINT" --from wallet $TXFLAG -y`
Example of expected output results:

>gas estimate: 159916
logs: []
raw_log: '[]'
txhash: 2B4F9C345E7CBF0A3BDD4443B3DA22ADDE2DBCC283C4302E8DF2C5A4384E423B
#### Check the current balance of Bob:

`$ BALANCE_OF_BOB=$( jq -n --arg address $BOB '{ "balance": { "address": $address } }' | tee /dev/tty )`
$ `wasmd query wasm contract-state smart $CONTRACT "$BALANCE_OF_BOB" $NODE`
>data:
  balance: "1000000"
#### Transfer CW20 tokens
#### Transfer 10k tokens from owner to Alice:

`$ TRANSFER_TO_ALICE=$( jq -n --arg recipient $ALICE '{ "transfer": { "recipient": $recipient, "amount": "10000" } }' | tee /dev/tty )`
Example of expected output results:

>{
  "transfer": {
    "recipient": "wasm1ec80a28dggwt6zkpu6j4l3akqs55gcp2gnncjn",
    "amount": "10000"
  }
}
#### execute the transfer contract:

`$ wasmd tx wasm execute $CONTRACT "$TRANSFER_TO_ALICE" --from wallet $TXFLAG`
#### Now check the current balance of owner and Alice:

`$ BALANCE_OF_OWNER=$( jq -n --arg address $OWNER '{ "balance": { "address": $address } }' | tee /dev/tty )`
`$ wasmd query wasm contract-state smart $CONTRACT "$BALANCE_OF_OWNER" $NODE`
>data:
  balance: "990000"

`$ BALANCE_OF_ALICE=$( jq -n --arg address $ALICE '{ "balance": { "address": $address } }' | tee /dev/tty )`
`$ wasmd query wasm contract-state smart $CONTRACT "$BALANCE_OF_ALICE" $NODE`
>data:
  balance: "10000"