# Running the Application

## Contract Messages

The way you interact with contracts on a blockchain is by sending **contract  messages***. A* message contains the JSON description of a specific action that should be taken on behalf of the sender, and in most Rust smart contracts they are defined in the `msg.rs` file.

In our `msg.rs` file, there are two enums: `ExecuteMsg`, and `QueryMsg`. They are enums because each variant of them represents a different message which can be sent. For example, the `ExecuteMsg::Increment` corresponds to the `try_increment` message in our `contract.rs` file.

In the previous section, we compiled, uploaded and instantiated our counter smart contract. Now we are going to query the contract and also execute messages to update the contract state. Let's start by querying the counter contract we instantiated.

### Query Message

A **Query Message** is used to request information from a contract; unlike `execute messages`, query messages do not change contract state, and are used just like database queries. You can think of queries as questions you can ask a smart contract.

Let's query our counter smart contract to return the current count. It should be 1, because that was the count we instantiated in the previous section. We query the count by calling the Query Message `get_count {}`, which is defined in our msg.rs file.

{% code overflow="wrap" %}

```bash
secretcli query compute query <your-contract-address> '{"get_count": {}}' --chain-id pulsar-3 --node https://pulsar.rpc.secretnodes.com 
```

{% endcode %}

The query returns:

```json
{"count": "1"}
```

Great! Now that we have queried the contract's starting count, let's execute an `increment{}` message to modify the contract state.

### Execute Message

An **Execute Message** is used for handling messages which modify contract state. They are used to perform actual actions.

{% hint style="info" %}
**Did you know?** Messages aren't free! Each transaction costs a small fee, which represents how many resources were required to complete it. This cost is measured in ***gas*** units.
{% endhint %}

The counter contract consists of two execute messages: `increment{}`, which increments the count by 1, and `reset{}`, which resets the count to any `i32` you want. The current count is 1, let's call the Execute Message `increment{}` to increase the contract count by 1:

```bash
secretcli tx compute execute <your-contract-address> '{"increment": {}}' --from <your-wallet> --chain-id pulsar-3 --node https://pulsar.rpc.secretnodes.com --fees=70000uscrt
```

{% hint style="success" %}
**Pro Tip:** SecretCLI automatically encrypts transactions. Only the transaction sender can see the data being sent (and the result). You can think of this as how HTTPS protects your data in transit when accessing a web page.
{% endhint %}

SecretCLI will ask you to confirm the transaction before signing and broadcasting. Upon successful confirmation of the transaction, the terminal will return a `transaction hash` representing your transaction:

<figure><img src="https://1849345700-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgF1LuzRcRVxJ2tTkh299%2Fuploads%2FgvuEcMpTqqfuhIg0gQj0%2FLocalSecret%20-%20transaction%20hash.png?alt=media&#x26;token=65193360-50e1-467e-83f2-1e730c0f6e26" alt=""><figcaption><p>confirming a transaction using SecretCLI</p></figcaption></figure>

Nice work! Now we can query the contract once again to see if the contract state was successfully incremented by 1:

{% code overflow="wrap" %}

```bash
secretcli query compute query <your-contract-address> '{"get_count": {}}' --chain-id pulsar-3 --node https://pulsar.rpc.secretnodes.com 
```

{% endcode %}

The query returns:

```json
{"count": "2"}
```

Now, we will call one final execute message, `reset{}`. This will reset the count to an `i32` that we specify. I am going to reset the count to 0 by running the following code in SecretCLI:

{% code overflow="wrap" %}

```bash
 secretcli tx compute execute <your-contract-address> '{"reset": {"count": 0}}' --from <your-wallet> --chain-id pulsar-3 --node https://pulsar.rpc.secretnodes.com --fees=70000uscrt
```

{% endcode %}

{% hint style="warning" %}
Make sure your JSON message is formatted properly!

**`` '{"reset": {"count": 0}}` ``**
{% endhint %}

The query returns:

```json
{"count": "0"}
```

Way to go! You have now successfully interacted with a Secret Network smart contract using SecretCLI.

### Next Steps

Congratulations! You completed the tutorial and successfully compiled, uploaded, deployed and executed a Secret Contract! The contract is the business logic that powers a blockchain application, but a full application contains other components as well. If you want to learn more about Secret Contracts, or explore what you just did more in depth, feel free to explore these awesome resources:

* [Millionaire's problem breakdown](https://docs.scrt.network/secret-network-documentation/development/secret-by-example/millionaires-problem) - explains how a Secret Contract works
* [CosmWasm Documentation](https://book.cosmwasm.com/) - everything you want to know about CosmWasm
* [Secret.JS](https://docs.scrt.network/secret-network-documentation/development/secretjs/templates) - Building a web UI for a Secret Contract
