Token Balance Store – Clarity Code Typing Test
Stores simple token balances with read, credit, and debit functions.
- 12 lines
- 344 chars
- ≈ 1m 43s at 40 WPM
Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
(define-map balances principal int)
(define-public (credit user amount)
(begin
(map-set balances user (+ (default-to 0 (map-get? balances user)) amount))
(ok true)))
(define-public (debit user amount)
(let ((bal (default-to 0 (map-get? balances user))))
(if (>= bal amount)
(begin (map-set balances user (- bal amount)) (ok true))
(err u100))))Coding works best on desktop or with an external keyboard.