near_api_types/
nft.rs

1use std::collections::HashMap;
2
3use borsh::{BorshDeserialize, BorshSerialize};
4use serde::{Deserialize, Serialize};
5
6use crate::{json::Base64VecU8, AccountId};
7
8pub type TokenId = String;
9
10#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize, BorshSerialize)]
11pub struct NFTContractMetadata {
12    pub spec: String,              // required, essentially a version like "nft-1.0.0"
13    pub name: String,              // required, ex. "Mosaics"
14    pub symbol: String,            // required, ex. "MOSAIC"
15    pub icon: Option<String>,      // Data URL
16    pub base_uri: Option<String>, // Centralized gateway known to have reliable access to decentralized storage assets referenced by `reference` or `media` URLs
17    pub reference: Option<String>, // URL to a JSON file with more info
18    pub reference_hash: Option<Base64VecU8>, // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
19}
20
21#[derive(
22    Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize, BorshSerialize,
23)]
24pub struct TokenMetadata {
25    pub title: Option<String>, // ex. "Arch Nemesis: Mail Carrier" or "Parcel #5055"
26    pub description: Option<String>, // free-form description
27    pub media: Option<String>, // URL to associated media, preferably to decentralized, content-addressed storage
28    pub media_hash: Option<Base64VecU8>, // Base64-encoded sha256 hash of content referenced by the `media` field. Required if `media` is included.
29    pub copies: Option<u64>, // number of copies of this set of metadata in existence when token was minted.
30    pub issued_at: Option<String>, // ISO 8601 datetime when token was issued or minted
31    pub expires_at: Option<String>, // ISO 8601 datetime when token expires
32    pub starts_at: Option<String>, // ISO 8601 datetime when token starts being valid
33    pub updated_at: Option<String>, // ISO 8601 datetime when token was last updated
34    pub extra: Option<String>, // anything extra the NFT wants to store on-chain. Can be stringified JSON.
35    pub reference: Option<String>, // URL to an off-chain JSON file with more info.
36    pub reference_hash: Option<Base64VecU8>, // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
37}
38
39#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize)]
40pub struct Token {
41    pub token_id: TokenId,
42    pub owner_id: AccountId,
43    pub metadata: Option<TokenMetadata>,
44    pub approved_account_ids: Option<HashMap<AccountId, u64>>,
45}