0

How can I get all accounts and sort by the balance? I'd like to build a list of all accounts and then sort them by the balance. I realize the data set would be large, but was thinking maybe via a cursor I could create some paging.

1 Answer 1

2

I think for this use case is best to run your own Horizon and Stellar Core instances so that you have direct access to their database.

Stellar Foundation provides a docker image to help you get started running Stellar Core and Horizon. After you finished syncing, you can access the databases directly.

In your case, you want to access the core database, for example using the psql command:

psql -h localhost -p 5432 -U stellar core

The core database contains the accounts table with the following schema:

+--------------------+-----------------------+-------------+
| Column             | Type                  | Modifiers   |
|--------------------+-----------------------+-------------|
| accountid          | character varying(56) |  not null   |
| balance            | bigint                |  not null   |
| seqnum             | bigint                |  not null   |
| numsubentries      | integer               |  not null   |
| inflationdest      | character varying(56) |             |
| homedomain         | character varying(32) |  not null   |
| thresholds         | text                  |  not null   |
| flags              | integer               |  not null   |
| lastmodified       | integer               |  not null   |
| buyingliabilities  | bigint                |             |
| sellingliabilities | bigint                |             |
+--------------------+-----------------------+-------------+

The query you are looking for is something similar to:

select * from accounts order by balance limit 100;

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.