This steps are based on https://docs.junonetwork.io/smart-contracts-and-junod-development/tumerlinal-erc-20
- Compile wasm
Clone erc20 contract in RUST and compile it. The result is .wasm
file.
Take an example of erc20 contract from here - https://github.com/InterWasm/cw-contracts/tree/main/contracts/erc20
- Upload wasm
Upload compile wasm contract to the chain.
merlind tx wasm store cw_erc20.wasm --from validator --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.merlind/ -y
This command will return a code number which starts from 1
.
- instantiate
Create a contract from uploaded wasm. This will use the code number generated at upload step.
merlind tx wasm instantiate 1 'instantiate message' --amount 50000umerlin --label "merlin erc20" --from validator --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.merlind/ --no-admin -y
merlind tx wasm instantiate 1 '{"name":"Nxtpop Coin","symbol":"NPOP","decimals":6,"initial_balances":[{"address":"pop1...","amount":"12345678000"}]}' --amount 50000umerlin --label "merlin erc20" --from validator --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.merlind/ --no-admin -y
This command will return a contract address.
- query contract
Query contract info by address. Use above generated contract address to check contract info.
merlind query wasm contract "contract address"
merlind query wasm contract pop1.....
- query balance
Query balance of an address. At first, try to check the address with initial balances.
merlind query wasm contract-state smart "contract address" '{"balance":{"address":"user address"}}'
merlind query wasm contract-state smart pop1... '{"balance":{"address":"pop1..."}}'
- transfer cw20 token
Transfer cw20 token to an address.
merlind tx wasm execute "contract address" 'transfer message' --from initial --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.merlind/ -y
merlind tx wasm execute "contract address" '{"transfer":{"amount":"amount","owner":"from address","recipient":"receiver address"}}' --from initial --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.merlind/ -y
merlind tx wasm execute pop1... '{"transfer":{"amount":"200","owner":"pop1...","recipient":"pop1..."}}' --from initial --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.merlind/ -y
Try to test balance changes after transfer using merlind query wasm contract-state smart
command in step 5
.