# Deploy WASM Smart Contract

## How to deploy WASM binary file on Titan Chain

Note: This process require some advanced knowledge. This tutorial focuses on smart contract deployment using command line tool. You can explore other methods by yourself.

### Step 1: Prepare the WASM contract file

* Compile your WASM contract, and generate the binary with name `<project_name>.wasm`

### Step 2: Upload the WASM file to Titan Chain

* Execute the upload command:

```
titand tx wasm store <project_name>.wasm --from <account> --gas 10000000 --gas-prices 0.0025uttnt
```

`<account>` is your account name. Please replace it with your actual account name.

* Check if the transaction is on chain and get the code id:

```
titand query tx <tx_hash>
```

`<tx_hash>` is the transaction hash generated from your upload, used for query the transaction status.

* Or get the code id using the following command:

```
titand query wasm list-code
```

Using list-code command, you can view all uploaded contracts and their code id.

### Step 3: Instantiate the WASM contract

* Instantiate the contract:

```
titand tx wasm instantiate <code_id> <json_encoded_init_args> --admin="$(titand keys show <account> -a)" --from <account> --gas 10000000 --gas-prices 0.0025uttnt --label <label>
```

`<code_id>`  *is the code id you get in Step 2*

`<json_encoded_init_args>`*is the parameter required for contract initiation, which should be coded in JSON format.*

`<label>` *is the contract label*

* Check if the transaction is on chain and get the contract address:

```
titand query tx <tx_hash>
```

If successful, you can get the contract address for further operations.

### Step 4: Query the contract state

* Using the command to query cantract state:

```
titand query wasm contract-state smart <contract_address> <query_args>
```

`<contract_address>` *is the contract address you get in Step 3.*

`<query_args>` *is the required parameter for the query, which should be coded in JSON format.*

* View contract state using Titan blockchain browser:
  * You can also use Titan blockchain browser to view your contract status: [Titan Blockchain Browser](https://testnet.titan.explorers.guru/contracts)
  * Key in the contract address in the browser and you can see the details and state of your contract.&#x20;

### Step 5: Execute the contract

* Execute the contract call:

```
titand tx wasm execute <contract_address> <exec_args> --fees 500uttnt --from <account>
```

`<exec_args>` *is the required parameter for contract execution, which should be coded in JSON format.*

#### Hints:

* &#x20;<...> in every step should be replaced by your actual value
* Check the parameters in the command carefully before execute each step to ensure correct deployment and operation of the contract.
