I would like to fetch the list of all ETH wallet addresses by an API(?), given a smart contract address (erc20 token address).
Similar feature that we see on etherscan.io under the erc20 Holder list. Any docs/resource would be appreciated. Thanks
I would like to fetch the list of all ETH wallet addresses by an API(?), given a smart contract address (erc20 token address).
Similar feature that we see on etherscan.io under the erc20 Holder list. Any docs/resource would be appreciated. Thanks
Your best bet would be via an API.
To get all the holders (some have limits) I would do this:
And if it is your erc20
contract (you createdd or you are the owner), you could just add something like that to do it:
contract MyContract is ERC20 {
... contract code ...
uint256 private _holders;
address[] private _allHolders;
constructor() {
... existing code ...
/// initialize the holders variable (new code)
holders = 0;
}
function mint(address _to, uint256 amt) {
... code ...
super._mint(_to, amt);
_holders += 1;
_allHolders.push(_to);
}
/// that would be the function you call in your offchain code with web3.js or ether.js to get the count.
function holdersCount() public onlyOwner {
return _holders
}
function getAllHolders() public onlyOwner {
return _allHolders;
}
}
You can try Bloxy's Token API: https://bloxy.info/api_methods
I think the one you are looking for is "Token Holder List".
Some methods require a paid subscription but this one isn't.
It's not possible to get the holders information directly from the ERC20 contract itself.
However there are some services offering their API for querying such info. Covalent offers an API for free. Check the API reference for token holders endpoint here