Deploying Smart contracts on Oraichain

Deploying smart contract involves a lot of steps let’s uncover those steps and deploy our cosmwasm smart contract on the oraichain.

#️⃣ Steps we will be following to deploy our smart contract are :

  1. Install all the prerequisites we need before deploying our smart contract

  2. Build a contract using cwtools

  3. Instantiate the contract using cosmwasm-ide

  4. Deploy the smart contract .

🦀 For this tutorial we will be deploying a smart contract I have written beforehand , so you can clone this repo if you are following along . ✌

#️⃣ Installing the pre-requisites for deploying our contract

For deploying our contract on Oraichain we need to have below listed tools :

  • Cosmwasm IDE : A vs code extension crafted by the oraichain team , it makes really easy for us to deploy our cosmwasm smart contracts to Oraichain and interact with them to test their functionality .

  • cw-tools : A npm package which helps us to build our smart contract into wasm files and even generates schemas for us .

Now let’s understand how to setup each of these tools

#️⃣ Installing cosmwasm IDE

For installing cosmwasm ide simply install it from this link .after installing it locally into your machine you should be having something like this

and at explorer tab you should be having

let us understand each button is used for :

  • Build CosmWasm button will build the smart contract to the .wasm file based on the file you open in VS Code.

  • Deploy Cosmwasm button will deploy your contract onto a network that you choose on the CosmWasm IDE explorer.

  • Upload CosmWasm button will upload your smart contract code.

  • Instantiate CosmWasm button will instantiate your smart contract given a code id.

🦀 Right now Build Cosmwasm button is not able to compile down our smart contract ,so we are gonna use the cw-tools for building the wasm file and schema of our contract .

With this you have installed cosmwasm ide in your vs code . now let us install cw-tools

#️⃣ Install cw-tools npm package

For installing cw-tools simply enter the command

For npm users :

npm install -g @oraichain/cwtools

For yarn users :

yarn global add @oraichain/cwtools

🗒️ To install cwtools package you need to have node js ≥16.0.0 installed in your system

To check whether we have successfully installed the package enter the command

cwtools -h

After entering the command you should be getting

#️⃣ Get some tokens from the testnet faucet

To get some tokens simply go to the oraichain faucet and enter your wallet address , For setting up the wallet for Oraichain you can follow the previous section .

Congrats!! now you have got 5 orai tokens

Now let’s build our contract and deploy it to oraichain testnet .

#️⃣ Building our contract using cw-tools

Building your contract basically means to generate your wasm binary file and store it to the artifacts folder of our smart contract project .

🗒️ artifacts folder contains all the stuff that is required for interacting with the network such as wasm file and schemas .

To build your contract using cw-tools simply enter

cwtools build hello

you should get

You can see that a new folder is created in our smart contract project named artifacts . you can check it’s files .

Hurray !! we have created our wasm binary , now let us create the schema for our contract . To create the schema for contract enter

cwtools gents code/cw-starter -o src/contracts

then you should be having response like below

let us check the artifacts folder again

So now we have generated the json schema and wasm binary for our smart contract now let us Instantiate it using the cw-ide .

🗒️ Instantiating basically means to set the default parameters for contract , for our smart contract we are having admin param only so we will only set it to instantiate our contract .

#️⃣ Instantiating the smart contract using cosmwasm-ide

To instantiate your smart contract first upload the smart contract code to cosmwasm-ide by clicking the Upload CosmWasm button , but make sure to open the contract.rs file in your code editor .

Wait for it to finish it will take a couple of seconds .

Then you should be having

Now let us understand what to enter in each field one by one

  • Input label : This field contains what are the input labels basically it is for our user to understand what kind of inputs our contract will accept

  • Gas price : The gas fees we need to pay for deploying our contract by default it is 0.0025 orai tokens but depending on traffic in blockchain it can be adjusted .

  • Code Id : Auto generated by the cw-ide for identifying the smart contracts .

  • Contract Admin : Here you declare the owner address of the contract .

  • Instantiate Message : Has the field of the input parameters required to initialize our contract in our contract we only need admin parameter so let’s enter the admin address , you should enter your wallet address here .

Now after entering all the values click on instantiate and you will be having some thing like this

Once instantiated you will be prompted to deploy your contract , but make sure you have created a .env file where your mnemonic is stored

the .env file should be in the root directory where Cargo.toml file exists . an example of a .env file

make sure to have no extra spaces , otherwise you will face error while deploying .

#️⃣ Let’s deploy the contract

To deploy the contract simply click on Deploy Cosmwasm to deploy your smart contract your wallet is accessed through the .env file mnemonic and after clicking you should be getting some thing like this

This means we have successfully compiled and deployed our smart contract using cw-tools and cosmwasm-ide now you can play around with the contract by executing messages and querying the messages . With this we have come to an end for this tutorial. In further tutorials we will be diving deep into the Oraichain development process till then stay tuned , happy hacking ✌️.

Last updated