Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list of ERC20 token holders in solidity

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!

like image 746
user1558646 Avatar asked Jan 19 '26 03:01

user1558646


1 Answers

It is not possible to get a list of ERC20 token holders directly from a contract.

You are correct in that you cannot do this because you cannot get a list of keys for a mapping in Solidity, therefore it is impossible without external intervention.

With that said, there are many people who need this functionality and perform tasks to achieve this. The biggest example I can think of is airdropping tokens to various accounts based on their holdings of another token. The way that most people do this is to read all of the token holders from the blockchain and store it in a local database. From there, they will implement a gas-efficient function that takes in the addresses as a parameter and performs actions on them that way.

It is not possible to accomplish what you desire using only the blockchain, but using a combination of on-chain/off-chain logic can achieve your goals.

like image 163
Shane Fontaine Avatar answered Jan 21 '26 08:01

Shane Fontaine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!