Quickstart
In this guide, you'll build a simple counter smart contract and interact with it in a local environment.
What you'll learn
Prerequisites
1
clarinet new counter- counter/
- contracts/
- settings/
- Devnet.toml
- Mainnet.toml
- Testnet.toml
- tests/
- Clarinet.toml
- package.json
- vitest.config.js2
$ cd counter
$ clarinet contract new counter
Created file contracts/counter.clar
Created file tests/counter.test.ts
Updated Clarinet.toml with contract counterFile
Purpose
3
;; Define a map to store counts for each user
(define-map counters principal uint)
;; Increment the count for the caller
(define-public (count-up)
(ok (map-set counters tx-sender (+ (get-count tx-sender) u1)))
)
;; Get the current count for a user
(define-read-only (get-count (who principal))
(default-to u0 (map-get? counters who))
)4
clarinet checkError
Fix
5
clarinet console$ (contract-call? .counter count-up)
(ok true)
$ (contract-call? .counter get-count tx-sender)
u1
$ (contract-call? .counter count-up)
(ok true)
$ (contract-call? .counter get-count tx-sender)
u2Last updated
Was this helpful?