Update Metadata Account Fields
Hi. I was trying to update Metadata Account fields' value, but the following error shows up! {"jsonrpc":"2.0","error":{"code":-32602,"message":"invalid transaction: Transaction failed to sanitize accounts offsets correctly"},"id":2}
Could you provide me a sample?
I found multiple ways to get this error. Double check you have the correct wallet public keys set in the CreateMetadataAccount method when creating the instructions. If they are not signers of the transaction you will get this error. If the metadata program instructions is part of a separate transaction than its account creation TX it will throw this error as well
Thank you. But now I get the custom program error: 0x3f, Program log: Data type mismatch error when trying to update mint authority
Which instructions are you building in the transaction builder? Hard to pin point the issue without knowing what parameters you are using as well as other instructions included in the Tx. Show me an example what you are trying to accomplish and ill help you out
var updateMetadataTX = new TransactionBuilder() .SetRecentBlockHash(recentHash.Result.Value.Blockhash) .SetFeePayer(signer) .AddInstruction( SystemProgram.CreateAccount( signer.PublicKey, customer, rpcClient.GetMinimumBalanceForRentExemption(TokenProgram.TokenAccountDataSize).Result, TokenProgram.TokenAccountDataSize, TokenProgram.ProgramIdKey ) ) .AddInstruction( TokenProgram.InitializeAccount( customer.PublicKey, mint, signer.PublicKey ) ) .AddInstruction( MetadataProgram.UpdateMetadataAccount( metadata, customer, customer, metadataData, false ) ) .Build(new List<Account> { signer });
and the result is "Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]","Program log: (Deprecated as of 1.1.0) Instruction: Update Metadata Accounts","Program log: Data type mismatch","Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 3320 of 792542 compute units","Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: custom program error: 0x3f"]
`
Wallet wallet = new Wallet("test", passphrase: "test");
Account signer = wallet.GetAccount(0);
PublicKey customer = new PublicKey("customers public key here");
PublicKey mint = new PublicKey("NFT mint address here");
byte[] metadataKeyBytes = new byte[32];
int nonce;
AddressExtensions.TryFindProgramAddress(new List<byte[]>() { Encoding.UTF8.GetBytes("metadata"), MetadataProgram.ProgramIdKey, mint }, MetadataProgram.ProgramIdKey, out metadataKeyBytes, out nonce);
PublicKey metadataAddress = new PublicKey(metadataKeyBytes);
var creator = new Creator(signer.PublicKey, 100);
var metadataData = new MetadataParameters()
{
name = "Test",
symbol = "Test",
uri = "Off chain metadata link",
creators = new List<Creator>() { creator },
sellerFeeBasisPoints = 500
};
RequestResult<ResponseValue<BlockHash>> blockHash = await rpcClient.GetRecentBlockHashAsync();
var updateMetadataTX = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(signer)
//The token account doesnt need to be created since it should of been created when the NFT was minted
//.AddInstruction(AssociatedTokenAccountProgram.CreateAssociatedTokenAccount(signer, customer, mint))
//Customer does not have update authority so they can not be the one to update the metadata. If they are the update authority than it requires them to be a signer as well but this allows the customer to modify the NFT so I doubt this is the case. I hope. If you plan to transfer authority than put customer for the newUpdateAuthority parameter
.AddInstruction(MetadataProgram.UpdateMetadataAccount(metadataAddress, signer.PublicKey, signer.PublicKey, metadataData, false))
.Build(new List<Account> { signer });
`
Thank you, it solved my problem However, sometimes when I send transactions, I come across with the following error: Tx Signature: {"jsonrpc":"2.0","error":{"code":-32003,"message":"Transaction signature verification failure"},"id":5} but with the "SimulateTransactionAsync()" method everything is OK. Do you have any idea?