Avatar
0
monkey Enlightened
monkey Enlightened
CosmosSDK: Deploy và khởi tạo contract
CosmosSDK: Deploy và khởi tạo contract thế nào?
  • Answer
cosmos-sdk
Remain: 5
1 Answer
Avatar
monkey Enlightened
monkey Enlightened

Set up biến môi trường:

source <(curl --insecure https://raw.githubusercontent.com/CosmWasm/testnets/master/malaga-420/defaults.env)

Tạo 1 ví:

wasmd keys add wallet

Request 1 ít coin để test:

JSON=$(jq -n --arg addr $(wasmd keys show -a wallet) '{"denom":"umlg","address":$addr}') && curl --insecure -X POST --header "Content-Type: application/json" --data "$JSON" https://faucet.malaga-420.cosmwasm.com/credit

Export wasmd Parameters

export NODE="--node $RPC"
export TXFLAG="${NODE} --chain-id ${CHAIN_ID} --gas-prices 0.25${FEE_DENOM} --gas auto --gas-adjustment 1.3"

Kiểm tra bank total

wasmd query bank total $NODE

Kiểm tra wallet balance

wasmd query bank balances $(wasmd keys show -a wallet) $NODE

// deploy byte code lên blockchain và nhận về Code Id

RES=$(wasmd tx wasm store government.wasm --from wallet $TXFLAG -y --output json -b block)
CODE_ID=$(echo $RES | jq -r '.logs[0].events[-1].attributes[0].value')

Khởi tạo contract:

INIT='{"purchase_price":{"amount":"100","denom":"umlg"},"transfer_price":{"amount":"999","denom":"umlg"}}'
wasmd tx wasm instantiate $CODE_ID "$INIT" --from wallet --label "name service" $TXFLAG -y --no-admin

Kiểm tra contract detail:

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

Chi tiết tham khảo tại: https://docs.cosmwasm.com/docs/1.0/getting-started/interact-with-contract

  • 0
  • Reply