Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Metadata Account Fields #41

Open
morpacs opened this issue Sep 12, 2022 · 6 comments
Open

Update Metadata Account Fields #41

morpacs opened this issue Sep 12, 2022 · 6 comments

Comments

@morpacs
Copy link

morpacs commented Sep 12, 2022

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?

@BifrostTitan
Copy link
Contributor

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

@morpacs
Copy link
Author

morpacs commented Oct 24, 2022

Thank you.
But now I get the custom program error: 0x3f, Program log: Data type mismatch error when trying to update mint authority

@BifrostTitan
Copy link
Contributor

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

@morpacs
Copy link
Author

morpacs commented Oct 24, 2022

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"]

@BifrostTitan
Copy link
Contributor

BifrostTitan commented Oct 24, 2022

`

                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 });    

`

@morpacs
Copy link
Author

morpacs commented Oct 24, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants