nearprotocol

Is there a way to list all the subaccounts my account have?


I´m working on a contract using rust that creates subaccounts and transfer some tokens to it as part of its functionality, but since im repeating the process many times testing the functions I wonder if im leaving many subaccounts created. Is there a way to list all the subaccounts an account have?


Solution

  • There is no simple way because each subaccount is an independent account and the upper-level account has no control over subs.

    Though you can try to use Indexer for Explorer public database to query accounts table with something like:

    SELECT account_id FROM accounts WHERE account_id LIKE '%.youraccount.near';
    

    From the README

    NOTE: Please, keep in mind that the access to the database is shared across everyone in the world, so it is better to make sure you limit the amount of queris and individual queries are efficient.