Skip to main content

NFT

The NFT Contract represents an individual NFT within a collection.

It manages the state and behavior of a single NFT, including ownership, metadata, storage, pricing, and permissions. The contract provides functionality for updating NFT properties with proofs and permissions, transferring ownership, selling and buying NFTs, upgrading the verification key, and pausing or resuming the NFT.

Hierarchy

  • SmartContract
    • NFT

Implements

Index

Constructors

externalconstructor

  • new NFT(address: PublicKey, tokenId?: Field): NFT
  • Parameters

    • externaladdress: PublicKey
    • externaloptionaltokenId: Field

    Returns NFT

Properties

events

events: { buy: typeof BuyEvent; ownershipChange: typeof OwnershipChangeEvent; pause: typeof PauseEvent; resume: typeof PauseEvent; sell: typeof SellEvent; transfer: typeof TransferEvent; update: typeof UpdateEvent; upgradeVerificationKey: typeof UpgradeVerificationKeyEvent } = ...

Events emitted by the NFT contract.


Type declaration

metadata

metadata: State<Field> = ...

The metadata associated with the NFT (Field).

metadataVerificationKeyHash

metadataVerificationKeyHash: State<Field> = ...

The hash of the verification key used for metadata proofs (Field).

name

name: State<Field> = ...

The name of the NFT (Field).

owner

owner: State<PublicKey> = ...

The current owner of the NFT (PublicKey).

packedData

packedData: State<Field> = ...

A packed field containing additional NFT data and flags (Field).

storage

storage: State<Storage> = ...

Holds off-chain storage information, e.g., IPFS hash (Storage).

Methods

buy

  • buy(price: UInt64, buyer: PublicKey): Promise<BuyEvent>
  • Purchases the NFT, transferring ownership and handling payment.


    Parameters

    • price: UInt64

      The price at which to buy the NFT (UInt64).

    • buyer: PublicKey

      The public key of the buyer (PublicKey).

    Returns Promise<BuyEvent>

    An event emitted after the NFT is purchased (BuyEvent).

ensureOwnerSignature

  • ensureOwnerSignature(): Promise<AccountUpdate>
  • Ensures that the transaction is authorized by the current owner.


    Returns Promise<AccountUpdate>

    A signed account update for the owner.

pause

  • pause(): Promise<void>
  • Pauses the NFT, disabling certain actions.


    Returns Promise<void>

    A promise that resolves when the NFT is paused.

resume

  • resume(): Promise<void>
  • Resumes the NFT, re-enabling actions.


    Returns Promise<void>

    A promise that resolves when the NFT is resumed.

sell

  • sell(price: UInt64, seller: PublicKey): Promise<SellEvent>
  • Lists the NFT for sale at a specified price.


    Parameters

    • price: UInt64

      The price at which to sell the NFT (UInt64).

    • seller: PublicKey

      The public key of the seller (PublicKey).

    Returns Promise<SellEvent>

    An event emitted after the NFT is listed for sale (SellEvent).

transfer

  • transfer(from: PublicKey, to: PublicKey): Promise<PublicKey>
  • Transfers ownership of the NFT from one user to another.


    Parameters

    • from: PublicKey

      The public key of the current owner (PublicKey).

    • to: PublicKey

      The public key of the new owner (PublicKey).

    Returns Promise<PublicKey>

    The public key of the old owner (PublicKey).

update

  • Updates the NFT's state with provided proofs and permissions.


    Parameters

    • input: NFTState

      The current state of the NFT (NFTState).

    • output: NFTState

      The desired new state of the NFT (NFTState).

    • creator: PublicKey

      The public key of the creator (PublicKey).

    Returns Promise<Field>

    The hash of the metadata verification key (Field).

upgradeVerificationKey

  • Upgrades the verification key used by the NFT contract.


    Parameters

    • vk: VerificationKey

      The new verification key (VerificationKey).

    • sender: PublicKey

      The public key of the sender (PublicKey).

    Returns Promise<UpgradeVerificationKeyEvent>

    An event emitted after the verification key is upgraded (UpgradeVerificationKeyEvent).