I'm noticing that with many NFT marketplaces, they transfer ownership of the NFT by having owners transfer control of the SPL token account, rather than creating a token account for the recipient based on the derived address. For example, this token account is being transferred between owners https://explorer.solana.com/address/BW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB
(see transaction history how the authority keeps changing hands).
When I call Token.getAssociatedTokenAddress with mint 3MwVdf1kEDRUU4qTfoHk1u363qJGxrCYHT5RBAEBQGLs and owner BAJkBrrMZusHYingeqmvKND7LZBYRLYRMjDtFJ7wbjkT I get the derived address BW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB. But now since BW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB has a new owner than the original owner, we can run into a situation where I want to send the SPL token to original owner BAJkBrrMZusHYingeqmvKND7LZBYRLYRMjDtFJ7wbjkT, but I can't use BW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB as the destination in the Token.createTransferInstruction instruction, since it has the wrong owner, and I can't generate a new keypair to use for creation of a new recipient associated token account because then I get the error Associated address does not match seed derivation.
Proposed Solution
I guess I need to transfer ownership of the token account I'm sending from, but this solution seems to just perpetuate a problem where account ownership is being transferred rather than creating the derived account for a recipient. Account transfer works for NFTs where the supply is 1, but I don't see this account transfer working in cases where I want to transfer some fungible SPL tokens but not all.
Problem
I'm noticing that with many NFT marketplaces, they transfer ownership of the NFT by having owners transfer control of the SPL token account, rather than creating a token account for the recipient based on the derived address. For example, this token account is being transferred between owners https://explorer.solana.com/address/BW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB (see transaction history how the authority keeps changing hands).
When I call
Token.getAssociatedTokenAddress
with mint3MwVdf1kEDRUU4qTfoHk1u363qJGxrCYHT5RBAEBQGLs
and ownerBAJkBrrMZusHYingeqmvKND7LZBYRLYRMjDtFJ7wbjkT
I get the derived addressBW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB
. But now sinceBW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB
has a new owner than the original owner, we can run into a situation where I want to send the SPL token to original ownerBAJkBrrMZusHYingeqmvKND7LZBYRLYRMjDtFJ7wbjkT
, but I can't useBW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB
as the destination in theToken.createTransferInstruction
instruction, since it has the wrong owner, and I can't generate a new keypair to use for creation of a new recipient associated token account because then I get the errorAssociated address does not match seed derivation
.Proposed Solution
I guess I need to transfer ownership of the token account I'm sending from, but this solution seems to just perpetuate a problem where account ownership is being transferred rather than creating the derived account for a recipient. Account transfer works for NFTs where the supply is 1, but I don't see this account transfer working in cases where I want to transfer some fungible SPL tokens but not all.