nep-174,包含个四协议标准
- Core standard: nep-171 ,旧的标准是nep-4,类似ERC-721
type Token = {
id: string,
owner_id: string,
}
function nft_transfer(
receiver_id: string,
token_id: string,
approval_id: number|null,
memo: string|null,
) {}
function nft_transfer_call(
receiver_id: string,
token_id: string,
approval_id: number|null,
memo: string|null,
msg: string,
): Promise {}
function nft_resolve_transfer(
owner_id: string,
receiver_id: string,
token_id: string,
approved_account_ids: null|string[],
): boolean {}
function nft_on_transfer(
sender_id: string,
previous_owner_id: string,
token_id: string,
msg: string,
): Promise<boolean>;
function nft_metadata(): NFTContractMetadata {}
type NFTContractMetadata = {
spec: string, // required, essentially a version like "nft-1.0.0"
name: string, // required, ex. "Mochi Rising — Digital Edition" or "Metaverse 3"
symbol: string, // required, ex. "MOCHI"
icon: string|null, // Data URL
base_uri: string|null, // Centralized gateway known to have reliable access to decentralized storage assets referenced by `reference` or `media` URLs
reference: string|null, // URL to a JSON file with more info
reference_hash: string|null, // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
}
type TokenMetadata = {
title: string|null, // ex. "Arch Nemesis: Mail Carrier" or "Parcel #5055"
description: string|null, // free-form description
media: string|null, // URL to associated media, preferably to decentralized, content-addressed storage
media_hash: string|null, // Base64-encoded sha256 hash of content referenced by the `media` field. Required if `media` is included.
copies: number|null, // number of copies of this set of metadata in existence when token was minted.
issued_at: number|null, // When token was issued or minted, Unix epoch in milliseconds
expires_at: number|null, // When token expires, Unix epoch in milliseconds
starts_at: number|null, // When token starts being valid, Unix epoch in milliseconds
updated_at: number|null, // When token was last updated, Unix epoch in milliseconds
extra: string|null, // anything extra the NFT wants to store on-chain. Can be stringified JSON.
reference: string|null, // URL to an off-chain JSON file with more info.
reference_hash: string|null // Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included.
}
function nft_total_supply(): string {}
function nft_tokens(
from_index: string|null, // default: "0"
limit: number|null, // default: unlimited (could fail due to gas limit)
): Token[] {}
function nft_supply_for_owner(
account_id: string,
): string {}
function nft_tokens_for_owner(
account_id: string,
from_index: string|null, // default: 0
limit: number|null, // default: unlimited (could fail due to gas limit)
): Token[] {}
- Approval Management: nep-178
function nft_approve(
token_id: TokenId,
account_id: string,
msg: string|null,
): void|Promise<any> {}
function nft_revoke(
token_id: string,
account_id: string
) {}
function nft_revoke_all(token_id: string) {}
function nft_is_approved(
token_id: string,
approved_account_id: string,
approval_id: number|null
): boolean {}
function nft_on_approve(
token_id: TokenId,
owner_id: string,
approval_id: number,
msg: string,
) {}
nep-199 ,合约多收款人支付机制的标准/// A mapping of NEAR accounts to the amount each should be paid out, in
/// the event of a token-sale. The payout mapping MUST be shorter than the
/// maximum length specified by the financial contract obtaining this
/// payout data. Any mapping of length 10 or less MUST be accepted by
/// financial contracts, so 10 is a safe upper limit.
#[derive(Serialize, Deserialize)]
#[serde(crate = "near_sdk::serde")]
pub struct Payout {
pub payout: HashMap<AccountId, U128>,
}
pub trait Payouts{
/// Given a `token_id` and NEAR-denominated balance, return the `Payout`.
/// struct for the given token. Panic if the length of the payout exceeds
/// `max_len_payout.`
fn nft_payout(&self, token_id: String, balance: U128, max_len_payout: u32) -> Payout;
/// Given a `token_id` and NEAR-denominated balance, transfer the token
/// and return the `Payout` struct for the given token. Panic if the
/// length of the payout exceeds `max_len_payout.`
#[payable]
fn nft_transfer_payout(
&mut self,
receiver_id: AccountId,
token_id: String,
approval_id: u64,
balance: U128,
max_len_payout: u32,
) -> Payout{
assert_one_yocto();
let payout = self.nft_payout(token_id, balance);
self.nft_transfer(receiver_id, token_id, approval_id);
payout
}
}