You might have noticed an error
failed to get accounts owned by program Tokenkeg...: Tokenkeg... excluded from account secondary indexes; this RPC method unavailable for key
This error is when you send an unexpected payload or not sending the correct data to the Solana validator.
To better explain it, we'll use a real world example
Get tokens with the same update authority
Let's say you want to get all tokens with the same update authority. There's an easy way with an SDK and a hard way by calling the getProgramAccounts and calculating the bytes.
The easy way would be to use the Metaplex SDK and do
await METAPLEX.nfts().findAllByUpdateAuthority({updateAuthority: AUTHORITY})
The hard way is to check the bytes manually. For this, you need to understand this diagram
We would build thegetProgramAccounts
in the following way:
{
"method": "getProgramAccounts",
"jsonrpc": "2.0",
"params": [
"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s", # Token Metada Account, do not change! do not use Tokenkeg!
{
"encoding": "jsonParsed",
"commitment": "processed",
"filters": [
{
"memcmp": {
"offset": 1,
"bytes": "7ys9jKmtNT2ARdutN5Jmx9hpNmUULb4o6H8usfrpvgg9". # updateAuthority to match
}
}
]
}
],
"id": "1"
}
offset
: set to 1, as the position of theUpdated Authorityfield within theToken Metadata Programstarts at offset 1bytes
: set to the public key of the account you want to search for to be theMint Authority
The first result is the Token Metadata Account with address8yQpSuMs9LkGWwsF8M3snkQKHEKNGG8rzEG8C3PLof7b
.
Again, this is the Token Metadata Account for a certain NFT, not the Token Program Account, so if you check that account in the Solana Explorer, you will not see anything beneficial.
So, the gross of the work now is to obtain the Mint Account from the Mint field of the Token Metadata Account we just got.
For that, you need to deserialize thedata
field from the response above (I recommend you use our guide to get started on how to deserialize Solana data).
You will need the Field names, Offset, and Sizes of the Token Metadata Account from the Metaplex docs.
Once you decode the data, you can extract the Mint field, which would be the Token Program Account of the NFT itself.
We strongly recommend going the Metaplex SDK way, as going directly throughgetProgramAccounts
is several orders of magnitude more complex.
If you want to continue through thegetProgramAccounts
route, we recommend you join our Discord server or the Metaplex's Community one, where you may find some Metaplex experts who could help you move forward.
Comments
0 comments
Article is closed for comments.