Blog

Solana: “KeyExcludedFromSecondaryIndexMessage” error when using get_program_accounts for SPL token in Solana

Error “KeyExcludedFromSecondaryIndexMessage” When Using get_program_accounts for SPL Token on Solana

As a developer building applications on the Solana blockchain, it’s essential to understand the intricacies of the Solana ecosystem. In this article, we’ll delve into an error that occurs when using the get_program_accounts function from the solana-py library to retrieve the top 100 holders of a specific SPL token.

The Issue: KeyExcludedFromSecondaryIndexMessage

When you call get_program_accounts, Solana returns a list of program accounts, which are the addresses that have access to the blockchain. However, in some cases, a key might be excluded from this secondary index message due to various reasons such as:

  • The account is not authorized for transaction or reading.

  • The account has been deactivated.

  • There’s an issue with the program account’s configuration.

In our case, the error “KeyExcludedFromSecondaryIndexMessage” occurs when get_program_accounts returns a list of accounts that do not have any programs associated with them. This is often due to the following reasons:

  • The user has restricted access to the account.

  • The program that owns the account does not have permission to be included in the secondary index.

Why You’ll Encounter an Error

If you encounter an “Error: KeyExcludedFromSecondaryIndexMessage” when using get_program_accounts for your SPL token, here are some potential reasons why:

  • Missing programs: The program that owns the account might not have any associated with it.

  • Restricted access: The user has restricted access to the account or the program.

  • Program configuration issues: There’s a problem with how the program is configured.

How to Fix the Issue

To resolve this issue, you can try the following steps:

  • Check the get_program_accounts call: Ensure that you’re calling get_program_accounts correctly and passing in the required arguments.

  • Verify account access: Check if the user has access to the account by verifying their permissions with Solana’s API documentation.

  • Adjust program configuration: If possible, adjust the program configuration to grant access to the account or modify its rules.

Code Example

Here is an example of how you can use get_program_accounts to retrieve the top 100 holders of a specific SPL token on Solana:

import solana.publickey as pk

from solana programs import get_account, get_account_info

def main():






Define your account ID and SPL token name

account_id = "your_account_id"

spl_token_name = "your_spl_token_name"


Create a client instance with the Solana CLI tool

from solana.web3 import Web3

web3 = Web3()


Get the account info for your SPL token holder

spl_token_holders = get_program_accounts(web3, account_id, spl_token_name)

print("Top 100 holders of", spl_token_name)

print(spl_token_holders[:100])

if __name__ == "__main__":

main()

Conclusion

In this article, we’ve explored an error that occurs when using get_program_accounts to retrieve the top 100 holders of a specific SPL token on Solana. By understanding the potential reasons behind this error and following the steps outlined in the example, you should be able to resolve the issue and successfully use get_program_accounts with your SPL token holder.

Related articles

Explore The Quarter World

play beyond your limits

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Articles
Featured

The proven 3 steps to play any song without notes

See more

Quartback 

יוצאים לקדם השקה בקרוב

.תוכל להשאיר פרטים, וצוות השיווק יעדכן אותך מיד כשנתחיל