Learn how to create a simple counter contract using Clarinet.
In this quickstart guide, you will write a simple counter contract with Clarity. Throughout this tutorial, you'll learn how to generate a new project, create a smart contract, and validate your smart contract code using the Clarinet CLI.
To follow this quickstart guide, you will need to have Clarinet installed on your machine.
brew install clarinet
If you need more installation options, check out the installation guide.
Generate your counter project
Start by creating a new Clarinet project. This command will create a new directory named counter and set up a basic Clarinet project inside it.
Terminal
clarinet new counter
Navigate to the newly created directory:
cd counter
You should see the following files and folders:
Devnet.toml
Mainnet.toml
Testnet.toml
.gitignore
Clarinet.toml
package.json
tsconfig.json
vitest.config.js
Create a counter contract
Inside your project, create your first contract. This command will create an empty counter.clar file in the contracts folder as well as a counter.test.ts file in the tests folder.
Terminal
clarinet contract new counter
counter.clar
counter.test.ts
.gitignore
Clarinet.toml
package.json
tsconfig.json
vitest.config.js
It also updates the Clarinet.toml file inside your project with the necessary settings.