As our first project, we're going to build and store polls on the chain. Its functionality is as follows:
- Any user can create a poll.
- Any user can vote on a poll.
- Polls can have different options.
For a textual example I will talk through a scenario with some users:
- User A can create a poll for example:
- What Cosmos coin is your favorite?
- Juno
- Osmosis
- Cosmos Hub
- What Cosmos coin is your favorite?
- User A decides to vote on their own poll, they vote for
Juno
- User B can also vote on the poll, they vote for
Cosmos Hub
- After a certain amount of time User A (as the owner of the poll) can close the poll. User A closes the poll
- User C attempts to vote on a closed poll. They cannot
- The poll results are now visible for everyone to see on the chain
This is a template to build smart contracts in Rust to run inside a Cosmos SDK module on all chains that enable it. To understand the framework better, please read the overview in the cosmwasm repo, and dig into the cosmwasm docs. This assumes you understand the theory and just want to get coding.
Assuming you have a recent version of rust and cargo (v1.58.1+) installed (via rustup), then the following should get you a new repo to start a contract:
Install cargo-generate and cargo-run-script. Unless you did that before, run this line now:
cargo install cargo-generate --features vendored-openssl
cargo install cargo-run-script
Now, use it to create your new contract. Go to the folder in which you want to place it and run:
Latest: 1.0.0-beta6
cargo generate --git https://github.com/CosmWasm/cw-template.git --name PROJECT_NAME
Older Version
Pass version as branch flag:
cargo generate --git https://github.com/CosmWasm/cw-template.git --branch <version> --name PROJECT_NAME
Example:
cargo generate --git https://github.com/CosmWasm/cw-template.git --branch 0.16 --name PROJECT_NAME
You will now have a new folder called PROJECT_NAME
(I hope you changed that to something else)
containing a simple working contract and build system that you can customize.