2

I'm trying to freeze an NFT via createFreezeDelegatedAccountInstruction but I'm always getting this error: "failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x3e".

Here's the code I'm using:

import fs from 'fs'
import { PublicKey, Transaction, Keypair, clusterApiUrl, Connection } from "@solana/web3.js"
import { createApproveInstruction, } from "@solana/spl-token"
import { createFreezeDelegatedAccountInstruction, PROGRAM_ID } from '@metaplex-foundation/mpl-token-metadata'

const walletSecretKey = Uint8Array.from(
  JSON.parse(
    fs.readFileSync('./key.json', 'utf8')
  )
)

const USER_WALLET_ADDRESS = 'RANDOM_WALLET_ADDRESS'
const NFT_MINT_ID = new PublicKey('RANDOM_NFT_ID')


const connection = new Connection(clusterApiUrl("mainnet-beta"), "confirmed")
const userWalletAddress = new PublicKey(USER_WALLET_ADDRESS)
const authorityWallet = Keypair.fromSecretKey(walletSecretKey)

// Get block hash
const blockhashObj = await connection.getLatestBlockhash()
const blockhash = blockhashObj.blockhash

// create transaction
const transaction = new Transaction()
transaction.feePayer = userWalletAddress
transaction.recentBlockhash = blockhash

const accountAddress = await getAssociatedTokenAddress(NFT_MINT_ID, userWalletAddress)

transaction.add(
  createApproveInstruction(
    accountAddress,
    authorityWallet.publicKey,
    userWalletAddress,
    1
  )
)

const [edition] = await PublicKey.findProgramAddress(
  [
    Buffer.from("metadata"),
    PROGRAM_ID.toBuffer(),
    NFT_MINT_ID.toBuffer(),
    Buffer.from("edition"),
  ],
  PROGRAM_ID
);

transaction.add(
  createFreezeDelegatedAccountInstruction(
    {
      delegate: authorityWallet.publicKey,
      tokenAccount: accountAddress,
      edition,
      mint: NFT_MINT_ID,
      tokenProgram: PROGRAM_ID,
    },
    PROGRAM_ID
  )
)

// sign transaction
transaction.sign(authorityWallet)

// serialize and return
const serializedTransaction = transaction.serialize({
  requireAllSignatures: false,
});
const transactionBase64 = serializedTransaction.toString("base64");
console.log(transactionBase64)

And here's the Front-End's code:

const recoveredTransaction = Transaction.from(
  Buffer.from(transactionBase64, "base64")
)
const newTxId = await sendTransaction(recoveredTransaction)

I also tried doing each transaction alone ( approve, then freeze ) however, the approve worked and the freeze didn't ( also returned the error above ).

I'm not sure if I'm doing something wrong or there's something wrong in the mechanism.

0

1 Answer 1

3

In This Section of the Code the tokenProgram is being passed wrong.

createFreezeDelegatedAccountInstruction(
{
  delegate: authorityWallet.publicKey,
  tokenAccount: accountAddress,
  edition,
  mint: NFT_MINT_ID,
  // Import TOKEN_PROGRAM_ADDRESS from @solana/spl-token and add it here
  tokenProgram: TOKEN_PROGRAM_ADDRESS,
},
PROGRAM_ID
) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.