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
2
3
Write your contract code
;; 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))
)Last updated
Was this helpful?