Deploy and interact
Deploy a smart contract project
Now let's try to deploy the contract we have built.
Prepare your network env
### testnet demo
export CHAIN_ID="gotabit-dev-1"
export RPC="https://rpc-testnet.gotabit.dev"
export NODE=(--node $RPC)
export TXFLAG=($NODE --chain-id $CHAIN_ID --gas-prices 0.05ugtb --gas auto --gas-adjustment 1.3)
Preparing account
gotabitd keys add wallet
Upload the smart contract to the testnet
RES=$(gotabitd tx wasm store ./artifacts/demo-contract.wasm --from wallet $TXFLAG -y)
HASH=$(echo $RES | jq '.txhash' | tr -d '"')
CODE_ID=$($BINARY query tx --type=hash $HASH --output=json |jq '.logs[0].events[1].attributes[1].value')
echo $CODE_ID
Initialize smart contract
Set InstantiateMsg parameters
INIT={}
gotabitd tx wasm instantiate $CODE_ID $NODE "$INIT" --from wallet --label "demo-contract" --no-admin $TXFLAG -y
Lookup contract address
CONTRACT=$(gotabitd query wasm list-contract-by-code $CODE_ID $NODE --output json | jq -r '.contracts[0]')
Query contract
gotabitd query wasm contract $CONTRACT_ADDR $NODE
Interact contract
Execute Update Nonce
gotabitd tx wasm execute $CONTRACT $NODE "{"call":{}}" --from wallet $TXFLAG -y
gas estimate: 149730
logs: []
raw_log: '[]'
txhash: 9B55D4B7655CF76BCC7DAC7D53994841DE9553BDDC87D485122C2994D2606E3D
Query for the update
gotabitd query wasm contract-state smart $CONTRACT '{}' $NODE
data:
nonce: 1
Check contract state
gotabitd query wasm contract-state all $CONTRACT $NODE --output "json" | jq -r '.models[0].value' | base64 -d
{"index":0,"ptoken_address":"wasm1f8wwvs7sl3zemdw50m2g3hncvdj6tcn6army4unqc5x8ujyfktfqud5u5t","asset_type":"native","max_loan_to_value":"0.4","liquidation_threshold":"0.5","liquidation_bonus":"0.15","reserve_factor":"0.01","interest_rate_model":{"linear":{"params":{"optimal_utilization_rate":"0.8","base":"0.02","slope_1":"0.07","slope_2":"3"}}},"borrow_index":"1","liquidity_index":"1","borrow_rate":"0.01","liquidity_rate":"0","indexes_last_updated":1655820422,"debt_total_scaled":"0","active":true,"deposit_enabled":true,"borrow_enabled":true}%