Oraichain DAO
  • Introduction
    • About Oraichain
    • Oraichain Architechure
    • Blockchain and AI Powerhouse
    • Applications and use cases
  • Setting up wallet on Oraichain
    • Intro
    • Owallet
    • How to set up Keplr
  • Getting Started
    • Testnet
    • Mainnet
      • Become a Sentry node operator by Docker
      • Build Linux binary from source and become a Sentry Node Operator
      • Running a validator node on Oraichain .
    • Setting up Oraichain dev environment
  • Cosmwasm Quick Start
    • Understanding Cosmwasm File Structure
    • Intro to writing Cosmwasm Smart contract
    • Writing CW-721 NFT Contract
    • Deploying Smart contracts on Oraichain
    • Building a Favourite number dApp
  • RPC and tooling
    • RPC Endpoints
    • Tooling and Infra
    • Developer cheatsheet
  • Welcome to Oraichain DAO
    • Governance
      • Staking to Delegate on Oraichain
      • Selecting a Validator
      • DAO Treasury
    • How to Join
Powered by GitBook
On this page
  • What this tutorial will cover ❔
  • What are all these folders ?
  • ./cargo
  • ./circleci
  • ./github-workflows
  • examples /schema.rs
  • ./schema
  • The src directory 📁
  1. Cosmwasm Quick Start

Understanding Cosmwasm File Structure

PreviousSetting up Oraichain dev environment NextIntro to writing Cosmwasm Smart contract

Last updated 1 year ago

This tutorial will help you understand the Cosmwasm project structure which will simplify your journey as an oraichain smart contract dev so lets start .

🦀 If you are new to oraichain and haven’t set up the smart contract dev environment for oraichain , plz follow for setting it up from scratch .

What this tutorial will cover ❔

  • What are all these folders ?

  • The src directory

  • Contents of src directory .

What are all these folders ?

If you have followed the steps discussed in , you might be having a plethora of folders

in your working directory to overwhelm you , don’t worry by the end of this section you will understand their significance

the significance of each folder is :

./cargo

this has the configuration for all the cargo commands , you can understand it as a library where our command line refers for which cargo commands actually exist and how to give output for them .

./circleci

This folder will not be much of our use , it is for all the devops guys who are working on CI-CD pipelines of the project to keep it up to date and readily available for users .

./github-workflows

It houses the github actions required for the project (Not much of our use) .

examples /schema.rs

it has the logic to generate schemas when we enter cargo schema , the generate schemas are then stored into schema folder . in future articles we will be using this folder for declaring our schemas .

we will discuss how to write schema files like these in future articles .

./schema

This folder stores all the schemas we have generated for our smart contract for example , the below is a voting contract where schemas are generated for the main properties of our contract , later on when we will be building a dApp on oraichain we will be needing these schemas for interacting with our contract in our client .

🦀 For devs who are from EVM dev background , you can understand schemas like ABIs (Abstract binary interfaces ) in EVM world which are used for interacting with our contract by the client side of our application

example of how a schema file looks like

the below flowchart can simplify the concept of schemas for you :)

Now we have discussed the majority of folders in our smart contract project but most of our code resides in ./src . so let’s discuss about it .

The src directory 📁

it is the directory which has all the main logic of our project , the smart contract , the query functions , the execution calls all are in this calls . as an oraichain dev you will be spending most of your time coding in this directory only .

Inside the src directory you should be seeing the similar file structure

let’s discuss about each file and understand their significance .

🦀 You might be thinking that why we can’t just code all of the logic into a single file , the reason is the separation of concerns where we pack our logic into single small modules thus making it easy for us to handle the project and ensures code readability .

The following flowchart will summarize the src directory for you

file structure of src folder in a nutshell .

with this we have understood the files we will be working with when developing on Oraichain , in future tutorials you will be learning the art of writing cosmwasm contracts and actually building dapps out of them .till then stay tuned and happy hacking ✌️.

the example of a file is below

Untitled

: It stores all the logic of our contract , such as query, instantiate and execution .

: it will contain all the errors and their definitions for our contract , we can also declare custom errors such as notLoggedIn (An example where user is not logged in) and much more .

: it has all the modules we will be using in our smart contract , our contract can refer to it for using functionality of the module we have created .

: the module where we will be coding the execution and query logic for our contract .

: module which has information of all the states of our smart contract .

schema.rs
Contract.rs
error.rs
lib.rs
msg.rs
state.rs
this guide
this guide
Untitled
Untitled
Untitled
Untitled
Untitled
file structure of src folder in a nutshell .