Search code examples
pythonblockchainsubstratepolkadotpolkadot-js

How to get the account data of all accounts in Polkadot using py-substrate-interface


I want to do a couple of things. First, get the data of all the accounts to do a wealth distribution analysis. Second, get the data of all the accounts who have attached identity information.

I am able to do basic stuff using py-substrate-interface but I am not able to figure out the commands for fetching the data of all the accounts or accounts with identity of some kind attached.


Solution

  • To get an exhaustive list of all entries of a mapped storage function, you should have a look at the query_map function described at: https://github.com/polkascan/py-substrate-interface#query-a-mapped-storage-function

    This example actually describes how to retrieve all accounts, in case you want to retrieve all identities, you need to transform it to:

    result = substrate.query_map('Identity', 'IdentityOf')
    
    for account, identity_info in result:
        print(f"Identity of account '{account.value}': {identity_info.value}")
    
    

    You can find a list of all available storage functions per module/pallet at https://polkascan.io/polkadot/runtime-module