near nep标准

文章目录

  • nep = Near Enhancement Proposals ,即near改善提案
  • 标准号由来: https://github.com/near/NEPs 仓库的pull request 的ID作为标准号

ft

  • ft = Fungible Token,可替换token
  • Core standerd nep-141 ,类似ERC-20
    function ft_transfer(
        receiver_id: string,
        amount: string,
        memo: string|null
    ): void {}
    
    function ft_transfer_call(
       receiver_id: string,
       amount: string,
       memo: string|null,
       msg: string
    ): Promise {}
    
    function ft_on_transfer(
        sender_id: string,
        amount: string,
        msg: string
    ): string {}
    
    function ft_total_supply(): string {}
    
    function ft_balance_of(
        account_id: string
    ): string {}
    
    function ft_resolve_transfer(
       sender_id: string,
       receiver_id: string,
       amount: string
    ): string {}
    
  • metadata nep-148
    type FungibleTokenMetadata = {
        spec: string;
        name: string;
        symbol: string;
        icon: string|null;
        reference: string|null;
        reference_hash: string|null;
        decimals: number;
    }
    
  • spec参考: https://github.com/near/NEPs/tree/master/specs/Standards/FungibleToken

nft

  • nft = Non Fungible Token,不可替换token
  • nep-4
type TokenId = u64;
type AccountId = String;
pub trait NEP4 {
   fn grant_access(&mut self, escrow_account_id: AccountId);
   fn revoke_access(&mut self, escrow_account_id: AccountId);
   fn transfer_from(&mut self, owner_id: AccountId, new_owner_id: AccountId, tokenId: TokenId);
   fn transfer(&mut self, new_owner_id: AccountId, token_id: TokenId);
   fn check_access(&self, token_id: TokenId) -> bool;
   fn get_token_owner(&self, token_id: TokenId) -> AccountId;
}
  • 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>;
    
    • Metadata: nep-177
    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.
    }
    
    • Enumeration: nep-181
    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
      }
    }
    
  • spec参考: https://github.com/near/NEPs/tree/master/specs/Standards/NonFungibleToken
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值