Source Code


;; Crystals - SIP-010 Fungible Token
;; Generated by Charisma Launchpad

(impl-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait)

;; Error codes
(define-constant ERR-OWNER-ONLY (err u100))
(define-constant ERR-NOT-AUTHORIZED (err u403))

;; Constants
(define-constant DEPLOYER tx-sender)
(define-constant TOTAL-SUPPLY u1000000000000000)

;; Token definition
(define-fungible-token CRYS TOTAL-SUPPLY)
(define-data-var token-uri (optional (string-utf8 256)) none)



;; SIP-010 Standard Functions

(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))
    (begin
        (asserts! (or (is-eq tx-sender sender) (is-eq contract-caller sender)) ERR-NOT-AUTHORIZED)
        (if (is-some memo)
            (print memo)
            none)
        (ft-transfer? CRYS amount sender recipient)
    )
)

(define-read-only (get-name) 
    (ok "Crystals")
)

(define-read-only (get-symbol) 
    (ok "CRYS")
)

(define-read-only (get-decimals) 
    (ok u6)
)

(define-read-only (get-balance (who principal))
    (ok (ft-get-balance CRYS who))
)

(define-read-only (get-total-supply)
    (ok (ft-get-supply CRYS))
)

(define-read-only (get-token-uri)
    (ok (var-get token-uri))
)

;; Additional Functions



(define-public (set-token-uri (value (string-utf8 256)))
    (begin
        (asserts! (is-eq tx-sender DEPLOYER) ERR-OWNER-ONLY)
        (ok (var-set token-uri (some value)))
    )
)

;; Batch Transfer Function
(define-public (send-many (recipients (list 200 { to: principal, amount: uint, memo: (optional (buff 34)) })))
    (fold check-err (map send-token recipients) (ok true))
)

(define-private (check-err (result (response bool uint)) (prior (response bool uint)))
    (match prior ok-value result err-value (err err-value))
)

(define-private (send-token (recipient { to: principal, amount: uint, memo: (optional (buff 34)) }))
    (send-token-with-memo (get amount recipient) (get to recipient) (get memo recipient))
)

(define-private (send-token-with-memo (amount uint) (to principal) (memo (optional (buff 34))))
    (let ((transferOk (try! (transfer amount tx-sender to memo))))
        (ok transferOk)
    )
)



;; Initialize token URI with metadata endpoint
(var-set token-uri (some u"https://charisma-metadata.vercel.app/api/v1/metadata/SP2ZNGJ85ENDY6QRHQ5P2D4FXKGZWCKTB2T0Z55KS.crystals"))

;; Initial mint to deployer
(ft-mint? CRYS TOTAL-SUPPLY DEPLOYER)

Functions (12)

FunctionAccessArgs
transferpublicamount: uint, sender: principal, recipient: principal, memo: (optional (buff 34
get-nameread-only
get-symbolread-only
get-decimalsread-only
get-balanceread-onlywho: principal
get-total-supplyread-only
get-token-uriread-only
set-token-uripublicvalue: (string-utf8 256
send-manypublicrecipients: (list 200 { to: principal, amount: uint, memo: (optional (buff 34
check-errprivateresult: (response bool uint
send-tokenprivaterecipient: { to: principal, amount: uint, memo: (optional (buff 34
send-token-with-memoprivateamount: uint, to: principal, memo: (optional (buff 34