pub trait NonFungibleTokenResolver {
// Required method
fn nft_resolve_transfer(
&mut self,
previous_owner_id: AccountId,
receiver_id: AccountId,
token_id: TokenId,
approved_account_ids: Option<HashMap<AccountId, u64>>,
) -> bool;
}
Expand description
Used when an NFT is transferred using nft_transfer_call
. This is the method that’s called after nft_on_transfer
. This trait is implemented on the NFT contract.
§Examples
use std::collections::HashMap;
use near_sdk::{PanicOnDefault, AccountId, PromiseOrValue, near};
use near_contract_standards::non_fungible_token::{NonFungibleToken, NonFungibleTokenResolver, TokenId};
#[near(contract_state)]
#[derive(PanicOnDefault)]
pub struct Contract {
tokens: NonFungibleToken,
}
#[near]
impl NonFungibleTokenResolver for Contract {
#[private]
fn nft_resolve_transfer(&mut self, previous_owner_id: AccountId, receiver_id: AccountId, token_id: TokenId, approved_account_ids: Option<HashMap<AccountId, u64>>) -> bool {
self.tokens.nft_resolve_transfer(previous_owner_id, receiver_id, token_id, approved_account_ids)
}
}
Required Methods§
Sourcefn nft_resolve_transfer(
&mut self,
previous_owner_id: AccountId,
receiver_id: AccountId,
token_id: TokenId,
approved_account_ids: Option<HashMap<AccountId, u64>>,
) -> bool
fn nft_resolve_transfer( &mut self, previous_owner_id: AccountId, receiver_id: AccountId, token_id: TokenId, approved_account_ids: Option<HashMap<AccountId, u64>>, ) -> bool
Finalize an nft_transfer_call
chain of cross-contract calls.
The nft_transfer_call
process:
- Sender calls
nft_transfer_call
on FT contract - NFT contract transfers token from sender to receiver
- NFT contract calls
nft_on_transfer
on receiver contract 4+. [receiver contract may make other cross-contract calls] N. NFT contract resolves promise chain withnft_resolve_transfer
, and may transfer token back to sender
Requirements:
- Contract MUST forbid calls to this function by any account except self
- If promise chain failed, contract MUST revert token transfer
- If promise chain resolves with
true
, contract MUST return token tosender_id
Arguments:
previous_owner_id
: the owner prior to the call tonft_transfer_call
receiver_id
: thereceiver_id
argument given tonft_transfer_call
token_id
: thetoken_id
argument given toft_transfer_call
approved_account_ids
: if using Approval Management, contract MUST provide set of original approved accounts in this argument, and restore these approved accounts in case of revert.
Returns true if token was successfully transferred to receiver_id
.