Using the following transfer instruction, I get Error: Account is frozen when transferring programmable NFTs.
Is there another method on the spl-token library or do I need to manually create the instruction i.e.
https://github.com/metaplex-foundation/mpl-token-metadata/blob/main/programs/token-metadata/js/src/generated/instructions/Transfer.ts#L94
export const formTransaction = async (
tokenAddress: PublicKey,
recipientAddress: string,
sendAmount: bigint,
publicKey: PublicKey,
connection: Connection,
) => {
const { associatedAddress: fromTokenAccount, instruction: fromIxs } =
await getOrCreateAssociatedTokenAccountIxs(
connection,
publicKey,
publicKey,
tokenAddress,
);
const { associatedAddress: toTokenAddress, instruction: toIxs } =
await getOrCreateAssociatedTokenAccountIxs(
connection,
publicKey,
new PublicKey(recipientAddress),
tokenAddress,
);
const txsInstruction = createTransferInstruction(
fromTokenAccount,
toTokenAddress,
publicKey,
sendAmount,
);
const allIxs = [fromIxs, toIxs, txsInstruction].filter(
(ixs) => ixs,
) as TransactionInstruction[];
return new Transaction().add(...allIxs);
};
const getOrCreateAssociatedTokenAccountIxs = async (
connection: Connection,
payerKey: PublicKey,
ownerKey: PublicKey,
mintKey: PublicKey,
): Promise<{
associatedAddress: PublicKey;
instruction: TransactionInstruction | null;
}> => {
const associatedAddress = await getAssociatedTokenAddress(mintKey, ownerKey);
const accountInfo = await connection.getAccountInfo(associatedAddress);
if (accountInfo !== null) {
return { associatedAddress, instruction: null };
}
const createAssociatedAccountIx = createAssociatedTokenAccountInstruction(
payerKey,
associatedAddress,
ownerKey,
mintKey,
);
return { associatedAddress, instruction: createAssociatedAccountIx };
};
To send a PNFT, you'll need to create the instruction by feeding additional accounts