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

token_metadata.CreateVerifyCollection() function is not available? #186

Closed
eprtha opened this issue Feb 1, 2025 · 2 comments
Closed

token_metadata.CreateVerifyCollection() function is not available? #186

eprtha opened this issue Feb 1, 2025 · 2 comments

Comments

@eprtha
Copy link

eprtha commented Feb 1, 2025

The function is defined in this document as attached but VS Code says 'undefined: token_metadata.CreateVerifyCollection'
/solana-go-sdk/program/metaplex/token_metadata/instruction.go
Please advise. Thanks.

type VerifyCollectionParams struct {
Metadata common.PublicKey
CollectionUpdateAuthority common.PublicKey
Payer common.PublicKey
CollectionMint common.PublicKey
Collection common.PublicKey
CollectionMasterEditionAccount common.PublicKey
CollectionAuthorityRecord *common.PublicKey
}

func CreateVerifyCollection(param VerifyCollectionParams) types.Instruction {
data, err := borsh.Serialize(struct {
Instruction Instruction
}{
Instruction: InstructionVerifyCollection,
})
if err != nil {
panic(err)
}
accounts := []types.AccountMeta{
{
PubKey: param.Metadata,
IsWritable: true,
IsSigner: false,
},
{
PubKey: param.CollectionUpdateAuthority,
IsWritable: true,
IsSigner: true,
},
{
PubKey: param.Payer,
IsWritable: true,
IsSigner: true,
},
{
PubKey: param.CollectionMint,
IsWritable: false,
IsSigner: false,
},
{
PubKey: param.Collection,
IsWritable: false,
IsSigner: false,
},
{
PubKey: param.CollectionMasterEditionAccount,
IsWritable: false,
IsSigner: false,
},
}
if param.CollectionAuthorityRecord != nil {
accounts = append(accounts, types.AccountMeta{
PubKey: *param.CollectionAuthorityRecord,
IsWritable: false,
IsSigner: false,
})
}
return types.Instruction{
ProgramID: common.MetaplexTokenMetaProgramID,
Accounts: accounts,
Data: data,
}
}

@eprtha
Copy link
Author

eprtha commented Feb 2, 2025

I have implemented the type VerifyCollectionParams struct {} and func CreateVerifyCollection(param VerifyCollectionParams) types.Instruction {} directly to my codes.
and assigned values to the struct as this.

setCollectionIx := CreateVerifyCollection(VerifyCollectionParams{
Metadata: tokenMetadataPubkey,
CollectionUpdateAuthority: feePayer.PublicKey,
Payer: feePayer.PublicKey,
CollectionMint: colMintPubKey,
Collection: colMetadataPubKey,
CollectionMasterEditionAccount: colMasterEditionPubKey,
CollectionAuthorityRecord: nil,
})

But following error occurred.

failed to send tx2, err: {"code":-32002,"message":"Transaction simulation failed: Error processing Instruction 0: insufficient account keys for instruction","data":{"accounts":null,"err":{"InstructionError":[0,"NotEnoughAccountKeys"]},"innerInstructions":null,"logs":["Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]","Program log: IX: Set and Verify Collection","Program log: Error: NotEnoughAccountKeys","Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 13317 of 200000 compute units","Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: insufficient account keys for instruction"],"replacementBlockhash":null,"returnData":null,"unitsConsumed":13317}}

Seems like the instruction requires all 7 values and param.CollectionAuthorityRecord cannot be omitted even though it's value is nil.

and so, I updated the function as follows to add dummy value in case of nil instead of omitting.

if param.CollectionAuthorityRecord != nil {
accounts = append(accounts, types.AccountMeta{
PubKey: *param.CollectionAuthorityRecord,
IsWritable: false,
IsSigner: false,
})
} else {
// Even if nil, add a dummy PublicKey to prevent "NotEnoughAccountKeys" error
accounts = append(accounts, types.AccountMeta{
PubKey: common.PublicKey{}, // Empty placeholder
IsWritable: false,
IsSigner: false,
})
}

Now, this error occurred.

failed to send tx2, err: {"code":-32002,"message":"Transaction simulation failed: Error processing Instruction 0: custom program error: 0x39","data":{"accounts":null,"err":{"InstructionError":[0,{"Custom":57}]},"innerInstructions":null,"logs":["Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s invoke [1]","Program log: IX: Set and Verify Collection","Program log: Incorrect account owner","Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s consumed 14770 of 200000 compute units","Program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s failed: custom program error: 0x39"],"replacementBlockhash":null,"returnData":null,"unitsConsumed":14770}}

If anyone has some experience about flipping Verified: option from 'false' to 'true' of collection NFT, please advise.
Thanks in advance.

@eprtha
Copy link
Author

eprtha commented Feb 4, 2025

I have tested VerifyCollection using simple Node.js as attached to make sure my information for the verification has no problem.
It worked without any error message and the Verified flag of the NFT was updated.
Please advise how to make the instruction for VerifyCollection in golang.

import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
import { publicKey, createSignerFromKeypair, signerIdentity } from "@metaplex-foundation/umi";
import { verifyCollectionV1, findMetadataPda } from '@metaplex-foundation/mpl-token-metadata';

const umi = createUmi('https://api.devnet.solana.com')

const privateKeyStr = "My Private Key";
const privateKeyArray = privateKeyStr.split(",").map(s => parseInt(s.trim(), 10));
const walletFile = new Uint8Array(privateKeyArray);

let keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(walletFile));

const signer = createSignerFromKeypair(umi, keypair);

umi.use(signerIdentity(signer))

// first find the metadata PDA to use later
const metadata = findMetadataPda(umi, {
mint: publicKey("NFT Mint Public Key")
});
const collectionMint = publicKey("Collection NFT Mint Address");
const collectionAuthority = publicKey("Update Authority Public Key");

await verifyCollectionV1(umi, {
metadata,
collectionMint,
authority: collectionAuthority,
}).sendAndConfirm(umi)

@eprtha eprtha closed this as completed Feb 6, 2025
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

1 participant