Quickstart

Make an API call to the Stacks API and handle the response.

You will learn the following:

  • Generate a new project with the clarinet CLI
  • Create a smart contract with Clarity
  • Verify and debug your smart contract in your terminal

Install clarinet

Hiro's Clarinet package comes with several helpful commands to get you up and running with your project.

To get started, install the package on your machine:

Terminal
brew install clarinet

Generate a new hello-world project

Navigate to a directory in your terminal where you want to create your project. Then in your terminal, run the following command:

Terminal
clarinet new hello-world

The result should be a new hello-world directory resembling the following:

Devnet.toml
Mainnet.toml
Testnet.toml
.gitignore
Clarinet.toml
package.json
tsconfig.json
vitest.config.js

Create a say-hello contract

  1. Navigate to your project by running cd hello-world.
  2. Inside your project, use the clarinet contract new command to generate a new contract.
Terminal
clarinet contract new say-hello

This will add 2 files to your project: say-hello.clar and say-hello.test.ts.

say-hello.clar
say-hello.test.ts
.gitignore
Clarinet.toml
package.json
tsconfig.json
vitest.config.js

It also updates the Clarinet.toml file with your new contract.

Clarinet.toml
[contracts.say-hello]
path = 'contracts/say-hello.clar'
clarity_version = 2
epoch = 2.4

Create a read-only function called say-hi

Now that we have our say-hello.clar file generated, let's create a read-only function that prints out Hello World.

say-hello.clar
(define-read-only (say-hi)
  (print "Hello World")
)

Verify your contracts

In order to verify that our code is valid, we can run clarinet check inside of our project directory to ensure our say-hi function is valid.

Terminal
clarinet check
 1 contract checked

Next steps

Last updated on