
;; use the SIP090 interface (testnet)
(impl-trait .nft-trait.nft-trait)

;; define a new NFT
(define-non-fungible-token ME-ME-ME uint)

;; store the last issued 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))

        (match (nft-transfer? ME-ME-ME 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))
    (ok (nft-get-owner? ME-ME-ME 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 "http://thediligent.xyz")))

;; internal - mint new nft
(define-private (mint (new-owner principal))
    (let ((next-id (+ u1 (var-get last-id))))

    (match (nft-mint? ME-ME-ME next-id new-owner)
        success
            (begin
                (var-set last-id next-id)
                (ok true))
        error (err error))))

