Is it possible to get a list of token holders for a given ERC20 token from within another solidity contract?
Since "balances" are stored in a mapping in most ERC20 contracts, I do not think it is possible, since you can't get a list of keys for a mapping in solidity.
Is there anything I missed? Or is this just impossible?
Thanks!
You could try using an on-chain indexer that has token holder data.
Bitquery, for example, has an API for token holders that provides information on holders, their holdings, top holders, and other details.
Here's an example. This query gives you top holders for USDT You can run it here.