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 umi = createUmi(rpcUrl);
umi.use(mplTokenMetadata());
umi.use(signerIdentity(signer_wallet))
const umiMintSigner = generateSigner(umi);
const nftData = {
mint: umiMintSigner,
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);
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:
> Failed to send transaction Error: Simulation failed. Message:
> Transaction signature verification failure.
If I don't use the string .add(createNft(umi, nftData))
then the problem doesn't occur and the code works correctly.
How to fix the problem?