BACKEND:
const wallet_pubkey = new PublicKey(wallet_pubkey_string);
const wallet2 = Keypair.fromSecretKey(bs58.decode(wallet2_key));
const amount = 0.5;
const signer_wallet = createNoopSigner(fromWeb3JsPublicKey(wallet_pubkey));
const update_auth = createNoopSigner(fromWeb3JsPublicKey(wallet2_key.publicKey));
const umi = createUmi(rpcUrl);
umi.use(mplTokenMetadata());
umi.use(signerIdentity(signer_wallet))
const umiMintSigner = generateSigner(umi);
const nftData = {
mint: umiMintSigner,
updateAuthority: update_auth, //the problem is in this line
isMutable: true,
name: 'test',
symbol: 'test',
uri: url,
sellerFeeBasisPoints: percentAmount(10,2),
creators: creators,
tokenOwner: fromWeb3JsPublicKey(wallet_pubkey),
};
const transferData = {
destination: fromWeb3JsPublicKey(wallet2.publicKey),
amount: sol(amount),
};
let transaction = await transactionBuilder()
.add(createNft(umi, nftData))
.add(transferSol(umi, transferData))
.setFeePayer(signer_wallet)
.useV0()
.buildWithLatestBlockhash(umi);
const web3jsVersionedTransaction = toWeb3JsTransaction(transaction);
web3jsVersionedTransaction.sign([Keypair.fromSecretKey(umiMintSigner.secretKey), Keypair.fromSecretKey(wallet2.secretKey)]);
const web3jsVersionedTransactionSerialized = web3jsVersionedTransaction.serialize()
const transaction_serialize_string = Buffer.from(web3jsVersionedTransactionSerialized).toString('base64');
FRONTEND:
On the frontend, the transaction is signed by the wallet wallet_pubkey
.
if (window.solana && window.solana.isPhantom) {
try {
const connection = new Connection(url, "confirmed");
const transaction_array = Buffer.from(transactionBuildValue, 'base64');
const decodedTransaction = VersionedTransaction.deserialize(transaction_array);
const { blockhash } = await connection.getLatestBlockhash();
decodedTransaction.recentBlockhash = blockhash;
const signedTransaction = await window.solana.signTransaction(decodedTransaction);
const signature = await connection.sendRawTransaction(signedTransaction.serialize());
await connection.confirmTransaction(signature, 'processed');
return { success: true, signature };
console.log(signature);
} catch (error) {
console.error(error);
}
}
I get an error when trying to confirm a transaction via wallet.
Error:
Error: Simulation failed. Message: Transaction simulation failed:
Error processing Instruction 2: custom program error: 0x7.
Logs: [
"Program log: Instruction: SetAuthority",
"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3250 of 692177 compute units",
"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success",
"Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 117798 of 799706 compute units", "Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s success",
"Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]",
"Program log: IX: Mint",
"Program log: Update Authority given does not match",
"Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 31390 of 681908 compute units",
"Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: custom program error: 0x7"
].
If I don't use the string updateAuthority: update_auth
in nftData
and i don't use Keypair.fromSecretKey(wallet2.secretKey)
in web3jsVersionedTransaction.sign
then the problem doesn't occur and the code works correctly.
How to fix the problem and add updateAuthority
correctly?