This site requires Javascript to be enabled.

Deploy and instantiate contracts on-chain

Only optimized wasm files can be stored on chain. If your local project does not have an artifacts folder, or, if the artifacts folder is empty. Go back to the previous guide step for information on producing CosmWasm optimized executables.

Storing contracts on chain

You can obtain free testnet CONST tokens to cover transaction fees on the Constantine testnet by using the faucet available on Discord. For Mainnet you will need to acquire ARCH tokens.

When you are ready to store the wasm executable on chain, execute the following command via the Developer CLI:

archway contracts store CONTRACT [--json] [--log-level debug|error|info|warn] [--instantiate-permission any-of|everybody|nobody] [--allowed-addresses <value>] [--keyring-backend file|os|test] [--keyring-path <value>] [-f <value>] [--fee <value>] [--no-confirm] [--gas-adjustment <value>]

Arguments:

CONTRACT  (required) Name of the contract

Alternatively, you can utilize archwayd:

mainnet

testnet

archwayd tx wasm store artifacts/test_project2.wasm --from my-wallet --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.4

Instantiating the contract

You can then instantiate your contract with the following command substituting <contract-name> with the name of the contract you want to instantiate:

archway contracts instantiate <contract-name> --args '{"my_key":"my value"}'

Since we cloned the Increment starter template, try instantiating with your counter argument set to 0:

For example, if using the archway CLI:

archway contracts instantiate increment --args '{"count":0}'

If you are using archwayd then the following command should work:

mainnet

testnet

archwayd tx wasm instantiate 795 '{"count":0}' --from my-wallet --node https://rpc.mainnet.archway.io:443 --chain-id archway-1 --label testdev --admin archway1c23y29x9fcs4zlfv5tvl4nrq56p6gywq0snrxl --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

In the case of using archwayd, you need to add the Code Id (which you can see by looking at the store transaction data and set the admin address. You can check that information and the contract address on a blockexplorer).

So why are we sending our constructor as {"count":0} and how can we verify it's correct?

From your project files open src/contract.rs. Near the top, is the function pub fn instantiate, which works as a constructor and sets the initial state of the contract:

pub fn instantiate(  deps: DepsMut,  _env: Env,  info: MessageInfo,  msg: InstantiateMsg,) -> Result<Response, ContractError> {  let state = State {    count: msg.count, // Here's our count declaration    owner: info.sender.clone(), // Contract owner is wallet that sent tx  };  STATE.save(deps.storage, &state)?; // Save the state  // More code...}

You will see that the msg parameter is of type InstantiateMsg which is defined in the src/msg.rs file and contains the values that can be submitted in a JSON object format:

...pub struct InstantiateMsg {    pub count: i32,}

In your history you should see that two actions were created:

  • the store transaction happened when the wasm executable was uploaded to the chain
  • The instantiate transaction, which created an instance of the contract with its own state

The following command will historical deployment actions:

archway config deployments

Example output:

Deployments on constantine-3increment2 (0.1.0)MetadataContract: archway1aj4u4qdfqdnenmj4zn99wc8qev09wseytg0xr8eerwk7v0uhsevsqjf6zlOwner address: archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4Rewards address: archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4Transaction: C40C7B55AC2EFF3975DC6F762A06D1B38E5CBDD44EE2F234048E3C4DFBA0958DInstantiateContract: archway1aj4u4qdfqdnenmj4zn99wc8qev09wseytg0xr8eerwk7v0uhsevsqjf6zlAdmin: archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4Transaction: 72CB8910B98370EFE34820A7638C5DB6C01C52E621CB4D0E1B73E9DD357A1697StoreCode ID: 1776Transaction: 1CFFA14C7C34C8793A8DA9D02DE747237C433E7366288635EBC528B91CECBC49

You can also access this historical data from the ".archway" folder, where a respective file for each chain is stored, containing the historical data. For Archway testnet, for example, the file would be constantine-3.json.

Configuring the deployed contract

Now that the dapp is deployed, it's recommended to set its metadata. This will allow you to configure the smart contract to collect rewards.

To set contract metadata, use the command:

archway contracts metadata CONTRACT [--json] [--log-level debug|error|info|warn] [--owner-address <value>] [--rewards-address <value>][--keyring-backend file|os|test] [--keyring-path <value>] [-f <value>] [--fee <value>] [--no-confirm] [--gas-adjustment <value>]

A basic example would be:

archway contracts metadata increment2 --owner-address "archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4"  --rewards-address="archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4"

Arguments:

CONTRACT (required) Name of the contract

Example output:

archway contracts metadata increment2 --owner-address "archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4"  --rewards-address="archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4"✔ Enter the name or address of the account that will send the transaction … archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4Setting metadata for contract increment2  Chain: constantine-3  Contract: archway1aj4u4qdfqdnenmj4zn99wc8qev09wseytg0xr8eerwk7v0uhsevsqjf6zl  Rewards: archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4  Owner: archway12qj4v8jg5pxk6gsqct09sf9szhwql69xmf9fh4  Signer: mywallet✅ Metadata for the contract increment2-0.1.0 updated  Transaction: D7CBE945F9A464ACB6214FA7E710EB9A147983FE052D68A89FB97C0C5A50BE30

Set contract premiums

To set a contract premium the contract must have the rewards metadata already configured. You would use the following command to set the premium:

archway contracts premium CONTRACT --premium-fee <value> [--json] [--log-level debug|error|info|warn] [--keyring-backend file|os|test] [--keyring-path <value>] [-f <value>] [--fee <value>] [--no-confirm] [--gas-adjustment <value>]

A basic example would be:

archway contracts premium increment2 --premium-fee "1000000000000000000aconst" --from "mywallet" 

Arguments:

CONTRACT (required) Name of the contract

Example output:

Setting premium for contract increment2  Chain: constantine-3  Contract: archway1aj4u4qdfqdnenmj4zn99wc8qev09wseytg0xr8eerwk7v0uhsevsqjf6zl  Premium: 1 CONST (1000000000000000000aconst)  Signer: mywallet✅ Premium for the contract increment2-0.1.0 updated  Transaction: 8B5A1E3DB826909F898BC2252721C0FD5879D8E3FCAEF020C549C27A31FC2FC0

Drop Camp is here!

Join the queue and be one of the first to get in!.

Go Camping ↗