This steps are based on https://docs.junonetwork.io/smart-contracts-and-junod-development/tutorial-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.
teritorid tx wasm store cw_erc20.wasm --from validator --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.teritorid/ -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.
teritorid tx wasm instantiate 1 'instantiate message' --amount 50000utori --label "teritori erc20" --from validator --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.teritorid/ --no-admin -y
teritorid tx wasm instantiate 1 '{"name":"Nxtpop Coin","symbol":"NPOP","decimals":6,"initial_balances":[{"address":"pop1...","amount":"12345678000"}]}' --amount 50000utori --label "teritori erc20" --from validator --chain-id testing --gas auto --gas-adjustment 1.3 -b block --keyring-backend=test --home=$HOME/.teritorid/ --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.
teritorid query wasm contract "contract address"
teritorid query wasm contract pop1.....
- query balance
Query balance of an address. At first, try to check the address with initial balances.
teritorid query wasm contract-state smart "contract address" '{"balance":{"address":"user address"}}'
teritorid query wasm contract-state smart pop1... '{"balance":{"address":"pop1..."}}'
- transfer cw20 token
Transfer cw20 token to an address.
teritorid 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/.teritorid/ -y
teritorid 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/.teritorid/ -y
teritorid 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/.teritorid/ -y
Try to test balance changes after transfer using teritorid query wasm contract-state smart
command in step 5
.