Created
July 18, 2021 11:24
-
-
Save tina1998612/b71a7d23970600f83a4b76b5015e542c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; use the SIP090 interface (testnet) | |
(impl-trait 'ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.nft-trait.nft-trait) | |
;; define a new NFT. Make sure to replace MY-OWN-NFT | |
(define-non-fungible-token MY-OWN-NFT uint) | |
;; Store the last issues token ID | |
(define-data-var last-id uint u0) | |
;; Claim a new NFT | |
(define-public (claim) | |
(mint tx-sender)) | |
;; SIP009: Transfer token to a specified principal | |
(define-public (transfer (token-id uint) (sender principal) (recipient principal)) | |
(if (and | |
(is-eq tx-sender sender)) | |
;; Make sure to replace MY-OWN-NFT | |
(match (nft-transfer? MY-OWN-NFT token-id sender recipient) | |
success (ok success) | |
error (err error)) | |
(err u500))) | |
;; SIP009: Get the owner of the specified token ID | |
(define-read-only (get-owner (token-id uint)) | |
;; Make sure to replace MY-OWN-NFT | |
(ok (nft-get-owner? MY-OWN-NFT token-id))) | |
;; SIP009: Get the last token ID | |
(define-read-only (get-last-token-id) | |
(ok (var-get last-id))) | |
;; SIP009: Get the token URI. You can set it to any other URI | |
(define-read-only (get-token-uri (token-id uint)) | |
(ok (some "https://docs.stacks.co"))) | |
;; Internal - Mint new NFT | |
(define-private (mint (new-owner principal)) | |
(let ((next-id (+ u1 (var-get last-id)))) | |
;; Make sure to replace MY-OWN-NFT | |
(match (nft-mint? MY-OWN-NFT next-id new-owner) | |
success | |
(begin | |
(var-set last-id next-id) | |
(ok true)) | |
error (err error)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment