This site requires Javascript to be enabled.

Deploy and instantiate contracts on-chain

Only optimized wasm files can be stored on-chain. Now that you have the wasm binary ready, it's time to deploy it to the Archway blockchain so that you can start interacting with your smart contract. You have the option of using the archwayd daemon, the Archway Developer CLI if the contract structure is compatible.

Additional prerequisites

To execute some of the commands on this page, you will need to have the following command line tools installed:

Account creation

To execute a transaction on-chain, you need to have an account. In the Project Setup guide, we walked through setting up an account using the Archway Developer CLI. For setting up an account with archwayd, please follow this guide.

Access native tokens

To execute a transaction, you need the chain's native token to pay the transaction fee. For our Testnet, you can obtain free CONST tokens to cover transaction fees by using the faucet available on our Discord. For the Mainnet, you will need to acquire ARCH tokens, which can be done through our Archway Connect platform.

Deploy contract

Store contract using archway developer cli

If your contract was created using the Archway Developer CLI, you can deploy the contracts in your project using the following command:

archway contracts store

If you only want to store one contract from your project, you would set the contract name as shown in the following command, substituting CONTRACT with the name of your contract.

archway contracts store [CONTRACT]

For details on how to create a CosmWasm project with the Archway Developer CLI, see Creating a project.

Store contract using archwayd

Now you will store the wasm binary of the cw_namespace contract on-chain and obtain its Code ID. This Code ID will be used later to create an instance of the cw_namespace contract, which will then generate a contract address.

Make sure to update the following in the command:

  • Change mywallet to the name of the wallet you created via the Archwayd daemon page.
  • It is assumed that you are executing the command in the same directory as the artifacts directory and that the name of the wasm file is cw_nameservice.wasm. If this is not the case, you should change artifacts/cw_nameservice.wasm to the actual location of the file to be stored on-chain.

Execute the following commands to store the contract on-chain:

mainnet

testnet

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

The following is an example of the output:

{"height":"0","txhash":"7DA7D9091FC874BBB590E24397324DBBC25944730D41B34099E2340776849996","codespace":"","code":0,"data":"","raw_log":"[]","logs":[],"info":"","gas_wanted":"0","gas_used":"0","tx":null,"timestamp":"","events":[]}

Now copy the txhash and do a search on https://www.mintscan.io and you should find the Code ID on the page. The following is an example of the URL if the transaction was done on Testnet: https://www.mintscan.io/archway-testnet/tx/7DA7D9091FC874BBB590E24397324DBBC25944730D41B34099E2340776849996?height=7130816.

An unlimited number of contracts can be instantiated using a Code ID. You can see the list of contracts instantiated using a Code ID by executing the following command, making sure to change $CODE_ID to the actual number:

mainnet

testnet

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

The response should be an empty list since no contracts have been instantiated yet.

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

Before you instantiate a contract using the Code Id and interact with it, let's verify if the code stored on the blockchain is indeed the cw_namespace.wasm binary you uploaded.

Download the wasm binary from the chain and compare it to the original binary:

mainnet

testnet

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

The two binaries should be identical. For this action you need to have the diff command installed:

diff artifacts/cw_nameservice.wasm download.wasm

If the diff command yields an empty output, this indicates that the two files being compared are identical.

Instantiating the contract

Now that you have stored your contract on-chain and obtained the Code ID, you can create an instance of the smart contract using this Code ID. Once the contract is instantiated, you will receive a smart contract address that will allow you to execute transactions and perform queries on your contract.

Instantiate using archwayd

You will need to set the $CODE_ID value with the Code ID generated from storing the contract on-chain. In the commands below the following actions are being performed:

  • Set the initialization message (INIT) for the smart contract. It specifies the parameters purchase_price and transfer_price in JSON format, where the price is defined in terms of amount and denom (denomination, e.g., aconst). It uses the --no-admin to not set an admin which means that contract cannot be updated and no rewards metadata cannot be set.
  • Execute the actual command that instantiates the smart contract using the stored CODE_ID and the INIT message.
  • Lists all contracts instantiated from the specified CODE_ID and outputs the details in JSON format.

mainnet

testnet

# Set the code idCODE_ID=''# Prepare the instantiation messageINIT='{"purchase_price":{"amount":"100","denom":"aconst"},"transfer_price":{"amount":"999","denom":"aconst"}}'# Instantiate the contractarchwayd 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 balancearchwayd query wasm list-contract-by-code $CODE_ID --node https://rpc.mainnet.archway.io:443 --output jsonCONTRACT=$(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 detailsarchwayd query wasm contract $CONTRACT --node https://rpc.mainnet.archway.io:443 --chain-id archway-1# Check the contract balancearchwayd 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 statearchwayd query wasm contract-state all $CONTRACT --node https://rpc.mainnet.archway.io:443 --chain-id archway-1