6

I think Substrate API is really messy and difficult to understand. How could I get all the transactions for an account? And getting account by address is also counterintuitive: you need to make a query with some module and function but I didn't find any list of available functions and modules. So I would appreciate if you could suggest me clear and full documentation.

P.S. I'm using Python for development, so therefor I use py-substrate-interface and code for getting account by address looks like:

result = substrate.query(
    module='System',
    storage_function='Account',
    params=['F4xQKRUagnSGjFqafyhajLs94e7Vvzvr8ebwYJceKpr8R7T']
)
3
  • Need tutorial for Golang also
    – Cloud Choi
    Commented Apr 1, 2022 at 16:02
  • In case, I found partial docs for polkascan with all historical pallets, but still there's nothing about getting full list of extrinsics for an account
    – Holmes
    Commented Apr 1, 2022 at 16:19
  • 1
    If you want to query across history then you might be after an indexer for speed: substrate.stackexchange.com/questions/35/…
    – Squirrel
    Commented Apr 1, 2022 at 16:28

2 Answers 2

8

Substrate indeed covers quite many use-cases, not just transferring coins from one account to another, and some of that complexity will leak through any API, even if there are specialized ones in the making for a few typical use-cases.

The part of the system you care about in your question is the Balances pallet that has a pretty comprehensive Rust documentation. This pallet does not maintain a list of extrinsics that changed the balance of the account, but some nodes in the network index Transfer events while executing blocks and store these events in a database. You can also build such a node on your own, this answer to another question might help you in the right direction.

3
  • 1
    Thank you, I'll check Rust docs. But how could I get this aggregated data, is requesting some 3d-party services the only chance?
    – Holmes
    Commented Apr 1, 2022 at 16:13
  • 1
    I edit and add link to another question that answers how you can build your own indexing node.
    – wigy
    Commented Apr 1, 2022 at 16:14
  • Got it, thanks!
    – Holmes
    Commented Apr 1, 2022 at 16:31
6

No blockchain is designed to be able to easily get all transactions for an account, as this is a waste of storage for a normal syncing chain.

Substrate provide the ability to run an Archive node, which stores all state for all blocks since the genesis, but querying for all transactions for a user would require searching all blocks, which can be slow for sure.

The correct solution for such a query is to use a blockchain indexer as described here: Is there a good indexer for substrate chains (like the graph)?

Or a block explorer like:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.