Despliegue e interacción

Ya tienes listo el binario wasm. Es hora de desplegarlo en la red de pruebas de Archway (Constantine) y comenzar a interactuar con tu contrato inteligente. Puedes usar archwayd CLI, Archway Developer CLI, o arch3.js, dependiendo de tu preferencia.

Desplegar contrato

En la página Compilar contrato, generamos un ejecutable binario wasm. Puedes subir el código a la blockchain y, una vez completado el proceso, puedes descargar el bytecode para verificarlo.

Despliegue con archwayd

Ahora almacenará el bytecode wasm del contrato cw_namespace en cadena y obtendrá el id de código. Este id de código se utilizará más tarde para crear una instancia del contrato cw_namespace.

Cambia mywallet por el nombre del monedero que creaste en la página Configuración del entorno. Ejecuta los siguientes comandos para almacenar el contrato en cadena:

Mainnet
RES=$(archwayd tx wasm store artifacts/cw_nameservice.wasm --from mywallet --node https://rpc.mainnet.archway.io:443 --chain-id archway-1 --gas auto --gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.mainnet.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') --gas-adjustment 1.3 -y --output json -b block)

Testnet
RES=$(archwayd tx wasm store artifacts/cw_nameservice.wasm --from mywallet --node https://rpc.constantine.archway.tech:443 --chain-id constantine-3 --gas auto --gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.constantine.archway.tech:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') --gas-adjustment 1.3 -y --output json -b block)

La respuesta contiene el Código Id del binario wasm cargado:

echo $RES

La siguiente es una forma más sencilla de obtener el Id. de código de la respuesta

CODE_ID=$(echo $RES | jq -r '.logs[0].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
echo $CODE_ID

Puede ver la lista de contratos instanciados utilizando el CODE_ID generado anteriormente ejecutando el siguiente comando:

Mainnet
archwayd query wasm list-contract-by-code $CODE_ID --node https://rpc.mainnet.archway.io:443 --output json

Testnet
archwayd query wasm list-contract-by-code $CODE_ID --node https://rpc.constantine.archway.tech:443 --output json

La respuesta debe ser una lista vacía, ya que aún no se ha instanciado ningún contrato.

{"contracts":[],"pagination":{"next_key":null,"total":"0"}}

Antes de instanciar un contrato utilizando el Code Id e interactuar con él, vamos a verificar si el código almacenado en la blockchain es efectivamente el binario cw_namespace.wasm que subiste.

Descarga el binario wasm de la cadena y compáralo con el original:

Mainnet
archwayd query wasm code $CODE_ID --node https://rpc.mainnet.archway.io:443 download.wasm --chain-id archway-1

Testnet
archwayd query wasm code $CODE_ID --node https://rpc.constantine.archway.tech:443 download.wasm --chain-id constantine-3

Los dos binarios deben ser idénticos:

/diff artifacts/cw_nameservice.wasm download.wasm

Si el comando diff produce una salida vacía, esto indica que los dos archivos comparados son idénticos.

Despliegue con archway developer cli

Si tu contrato fue creado usando el comando archway new, puedes desplegar el contrato usando el siguiente comando:

archway store

Para obtener más información sobre cómo crear un proyecto CosmWasm con la CLI de Archway Developer, consulte Creación de un proyecto.

Instanciación del contratio

Ya puedes crear una instancia del contrato wasm. Después de la instanciación, puede realizar consultas y ejecutar transacciones.

Instanciar usando archwayd

Mainnet
# Prepare the instantiation message
INIT='{"purchase_price":{"amount":"100","denom":"aconst"},"transfer_price":{"amount":"999","denom":"aconst"}}'
# Instantiate the contract
archwayd tx wasm instantiate $CODE_ID "$INIT" --from mywallet --label "name service" --node https://rpc.mainnet.archway.io:443 --chain-id archway-1 --gas auto --gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.mainnet.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') --gas-adjustment 1.3 -y --no-admin
# Check the contract details and account balance
archwayd query wasm list-contract-by-code $CODE_ID --node https://rpc.mainnet.archway.io:443 --output json
CONTRACT=$(archwayd query wasm list-contract-by-code $CODE_ID --node https://rpc.mainnet.archway.io:443 --output json | jq -r '.contracts[-1]')
echo $CONTRACT
# See the contract details
archwayd query wasm contract $CONTRACT --node https://rpc.mainnet.archway.io:443 --chain-id archway-1
# Check the contract balance
archwayd query bank balances $CONTRACT --node https://rpc.mainnet.archway.io:443 --chain-id archway-1
# Upon instantiation the cw_nameservice contract will store the instatiation message data in the contract's storage with the storage key "config".
# Query the entire contract state
archwayd query wasm contract-state all $CONTRACT --node https://rpc.mainnet.archway.io:443 --chain-id archway-1

Testnet
# Prepare the instantiation message
INIT='{"purchase_price":{"amount":"100","denom":"aconst"},"transfer_price":{"amount":"999","denom":"aconst"}}'
# Instantiate the contract
archwayd tx wasm instantiate $CODE_ID "$INIT" --from mywallet --label "name service" --node https://rpc.constantine.archway.tech:443 --chain-id constantine-3 --gas auto --gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.constantine.archway.tech:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') --gas-adjustment 1.3 -y --no-admin
# Check the contract details and account balance
archwayd query wasm list-contract-by-code $CODE_ID --node https://rpc.constantine.archway.tech:443 --output json
CONTRACT=$(archwayd query wasm list-contract-by-code $CODE_ID --node https://rpc.constantine.archway.tech:443 --output json | jq -r '.contracts[-1]')
echo $CONTRACT
# See the contract details
archwayd query wasm contract $CONTRACT --node https://rpc.constantine.archway.tech:443
# Check the contract balance
archwayd query bank balances $CONTRACT --node https://rpc.constantine.archway.tech:443
# Upon instantiation the cw_nameservice contract will store the instatiation message data in the contract's storage with the storage key "config".
# Query the entire contract state
archwayd query wasm contract-state all $CONTRACT --node https://rpc.constantine.archway.tech:443

Interacción con el contrato

Ahora que el contrato está instanciado, puede registrar un nombre y transferirlo a otra dirección pagando la tasa de transferencia.

Interactúa con archwayd

Mainnet
# Register a name for the wallet address
REGISTER='{"register":{"name":"fred"}}'
archwayd tx wasm execute $CONTRACT "$REGISTER" --amount 100aconst --from mywallet --node https://rpc.mainnet.archway.io:443 --chain-id archway-1 --gas auto --gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.mainnet.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') --gas-adjustment 1.3 -y
# Query the owner of the name record
NAME_QUERY='{"resolve_record": {"name": "fred"}}'
archwayd query wasm contract-state smart $CONTRACT "$NAME_QUERY" --node https://rpc.mainnet.archway.io:443  --chain-id archway-1 --output json
# {"data":{"address":"archway1hlsd2tgjxalap5gslxz4g4t0f0yr9nwne98uyu"}}
# Transfer the ownership of the name record to wallet2 (change the "to" address to wallet2 address generated during environment setup)
archwayd keys list
TRANSFER='{"transfer":{"name":"fred","to":"archway1htum43he4n46gdmvuzr72ahsyvau4ummdgeytv"}}'
archwayd tx wasm execute $CONTRACT "$TRANSFER" --amount 999aconst --from mywallet --node https://rpc.mainnet.archway.io:443 --chain-id archway-1 --gas auto --gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.mainnet.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') --gas-adjustment 1.3 -y
# Query the record owner again to see the new owner address:
NAME_QUERY='{"resolve_record": {"name": "fred"}}'
archwayd query wasm contract-state smart $CONTRACT "$NAME_QUERY" --node https://rpc.mainnet.archway.io:443 --output json
# {"data":{"address":"archway1htum43he4n46gdmvuzr72ahsyvau4ummdgeytv"}}

Testnet
# Register a name for the wallet address
REGISTER='{"register":{"name":"fred"}}'
archwayd tx wasm execute $CONTRACT "$REGISTER" --amount 100aconst --from mywallet --node https://rpc.constantine.archway.tech:443 --chain-id constantine-3 --gas auto --gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.constantine.archway.tech:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') --gas-adjustment 1.3 -y
# Query the owner of the name record
NAME_QUERY='{"resolve_record": {"name": "fred"}}'
archwayd query wasm contract-state smart $CONTRACT "$NAME_QUERY" --node https://rpc.constantine.archway.tech:443 --output json
# {"data":{"address":"archway1hlsd2tgjxalap5gslxz4g4t0f0yr9nwne98uyu"}}
# Transfer the ownership of the name record to wallet2 (change the "to" address to wallet2 address generated during environment setup)
archwayd keys list
TRANSFER='{"transfer":{"name":"fred","to":"archway1htum43he4n46gdmvuzr72ahsyvau4ummdgeytv"}}'
archwayd tx wasm execute $CONTRACT "$TRANSFER" --amount 999aconst --from mywallet --node https://rpc.constantine.archway.tech:443 --chain-id constantine-3 --gas auto --gas-prices $(archwayd q rewards estimate-fees 1 --node 'https://rpc.constantine.archway.tech:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)') --gas-adjustment 1.3 -y
# Query the record owner again to see the new owner address:
NAME_QUERY='{"resolve_record": {"name": "fred"}}'
archwayd query wasm contract-state smart $CONTRACT "$NAME_QUERY" --node https://rpc.constantine.archway.tech:443 --output json
# {"data":{"address":"archway1htum43he4n46gdmvuzr72ahsyvau4ummdgeytv"}}

Last updated