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:
Copy 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:
La siguiente es una forma m谩s sencilla de obtener el Id. de c贸digo de la respuesta
Copy CODE_ID=$(echo $RES | jq -r '.logs[0].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
Puede ver la lista de contratos instanciados utilizando el CODE_ID generado anteriormente ejecutando el siguiente comando:
Copy 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.
Copy {"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:
Copy 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:
Copy /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:
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
Copy 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
Copy 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"}}