Clarity Contract
Allowing authorized users to issue badges to multiple recipients
;; title: template-batch-endorsements
;; version: 1.0
;; summary: A template for batch minting endorsements as non-fungible tokens (NFTs).
;; description: This contract allows for the minting of endorsement NFTs in batches, with predefined error handling and ownership management.
(impl-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait)
;; traits
;; This contract implements the NFT trait for endorsement tokens.
;; token definitions
(define-non-fungible-token endorsement uint)
;; constants
;; (VAR) changes based on the number of recipients
(define-constant TOTAL u500) ; Total number of tokens to be minted
(define-constant ERROR-NOT-IMPLEMENTED u1) ; Error code for not implemented functionality
(define-constant ERROR-UNAUTHORIZED u1000) ; Error code for unauthorized actions
(define-constant ERROR-ALREADY-MINTED u1001) ; Error code for already minted tokens
;; (VAR) changes based on the collection IPFS hash
(define-constant IPFS-ROOT "ipfs://ipfs/bafybeicvtqlmtj6hoed4ctxbmpxegk7fdhid437qmafbhlweuwgbqtwtky/json/{id}.json")
;; data vars
(define-data-var last-token-id uint u0) ; Variable to track the last minted token ID
;; data maps
(define-map awarded-addresses principal bool) ; Map to track awarded addresses
(define-map minters principal bool) ; Map to track authorized minters
;; public functions
;; Function to mint new NFTs
(define-private (mint (address principal))
(let (
(token-id (+ u1 (var-get last-token-id))) ; Generate the next token ID
)
(var-set last-token-id token-id) ; Update the last token ID
(nft-mint? endorsement token-id tx-sender))) ; Mint the NFT
;; Function to prevent transfer of NFTs
(define-public (transfer (id uint) (sender principal) (recipient principal))
(err ERROR-NOT-IMPLEMENTED)) ; Returns error for transfer attempts
;; Function to burn an NFT
(define-public (burn (id uint))
(let (
(owner (unwrap! (nft-get-owner? endorsement id) (err ERROR-UNAUTHORIZED))) ; Get current owner
)
(asserts! (is-eq owner tx-sender) (err ERROR-UNAUTHORIZED)) ; Ensure caller is the owner
(nft-burn? endorsement id owner))) ; Burn the NFT
;; read-only functions
;; Function to get the last token ID
(define-read-only (get-last-token-id)
(ok TOTAL)) ; Returns the total number of tokens
;; Function to get the owner of a token
(define-read-only (get-owner (id uint))
(ok (nft-get-owner? endorsement id))) ; Returns the owner of the specified token
;; Function to get the token URI
(define-read-only (get-token-uri (token-id uint))
(ok (some IPFS-ROOT))) ; Returns the IPFS URI for the token
;;; Mint calls here just need to change the addresses
(mint 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM) ; Minting for address 1
(mint 'ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5) ; Minting for address 2
(mint 'ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG) ; Minting for address 3Code Breakdown
Last updated