Hi guys i have a question, i am trying to develop a form of lottery discussing with my team mate we face the following problem:
The token is based on standard ERC20, it does not have the way to get the list of all holders (it only holds a list of address:balance pairs, but it has no way for other contracts to get holder list),.
Now is there a way to get around this?
Oct 11, 2021, 6:56 PM
any help regarding the above?
Oct 12, 2021, 9:12 AM
u should try iterating through the address: balances table on the contract and filter out the addresses with 0 balance
Oct 12, 2021, 9:56 AM
fbslo, [12.10.21 11:33]
It's not possible to iterate through a mapping in solidity.
fbslo, [12.10.21 11:34]
And balances are stored in address => balance mapping
fbslo, [12.10.21 11:36]
That's why balances has to be calculated off-chain using Transfer event logs. I personally worked with getting holders many times before, and there is no way to get holders of a standard erc20 directly from another contract.
It's not possible to iterate through a mapping in solidity.
fbslo, [12.10.21 11:34]
And balances are stored in address => balance mapping
fbslo, [12.10.21 11:36]
That's why balances has to be calculated off-chain using Transfer event logs. I personally worked with getting holders many times before, and there is no way to get holders of a standard erc20 directly from another contract.
.
Had this as response but doesnt look possible due the above issue
Oct 12, 2021, 1:29 PM
You are building the token or already existing one?
Oct 12, 2021, 1:31 PM
Existing one i am trying to make a sort of lottery
Oct 12, 2021, 1:31 PM
Hmm that'll be hard
Oct 12, 2021, 1:32 PM
Hahahah oh well
Oct 12, 2021, 1:32 PM
This lottery function will be integrated to token contract right?
Oct 12, 2021, 1:34 PM
Why would be a dream? For amount of holders or type of smart contract?
Oct 12, 2021, 1:34 PM
Or I didn't really understood your problem...
Oct 12, 2021, 1:34 PM
We cant is a standard erc20 token
Right hang on
so our requirement are:
when we reach 100k holders —> mapping holders balance for eligible member with over 50 dollar wort in wenlambo (with data feed price of chainlink)——->VRF will be activated which will chose the winner from eligible holders ———> price will be value of a Lamborghini in our token (still using price feed of chainlink)
We have reached this 3 possible option:
it can be ready by the end of the week. There are few ways to collect addresses and do a giveaway, each of them has pros and cons.
The easiest, fastest, and cheapest way would be to collect addresses of token holders off-chain. Since WENLAMBO is based on standard ERC20, it does not have the way to get the list of all holders (it only holds a list of address:balance pairs, but it has no way for other contracts to get holder list), so it has to be done off-chain. We would then publish the list of addresses, hash the data, and publish the hash to the smart contract before selecting the winner via chainlink VRF. Anyone would be able to verify that the published list was not modified after winner selection.
The only issue is that it's not trustless, and while it's provable fair, the team (you) still need to transfer rewards to the winner (or at least feed the data about the winning address to the smart contract).
The second way is to collect all addresses off-chain, and then feed them to the smart contract before selecting the winner. But it will be expensive, it will use 2,600,000,000 gas for 100k addresses, that's around $6k worth of BNB just for gas fees. But once the contract has a list of addresses, it's completely trustless.
The third option is to allow users to register their addresses (passing the gas fees to the users), but the number of registered users will be much lower, since not everyone will register (but the winner will be a more committed/active member of your community).
when we reach 100k holders —> mapping holders balance for eligible member with over 50 dollar wort in wenlambo (with data feed price of chainlink)——->VRF will be activated which will chose the winner from eligible holders ———> price will be value of a Lamborghini in our token (still using price feed of chainlink)
We have reached this 3 possible option:
it can be ready by the end of the week. There are few ways to collect addresses and do a giveaway, each of them has pros and cons.
The easiest, fastest, and cheapest way would be to collect addresses of token holders off-chain. Since WENLAMBO is based on standard ERC20, it does not have the way to get the list of all holders (it only holds a list of address:balance pairs, but it has no way for other contracts to get holder list), so it has to be done off-chain. We would then publish the list of addresses, hash the data, and publish the hash to the smart contract before selecting the winner via chainlink VRF. Anyone would be able to verify that the published list was not modified after winner selection.
The only issue is that it's not trustless, and while it's provable fair, the team (you) still need to transfer rewards to the winner (or at least feed the data about the winning address to the smart contract).
The second way is to collect all addresses off-chain, and then feed them to the smart contract before selecting the winner. But it will be expensive, it will use 2,600,000,000 gas for 100k addresses, that's around $6k worth of BNB just for gas fees. But once the contract has a list of addresses, it's completely trustless.
The third option is to allow users to register their addresses (passing the gas fees to the users), but the number of registered users will be much lower, since not everyone will register (but the winner will be a more committed/active member of your community).
Oct 12, 2021, 1:36 PM
Yep these are your options, since the token is already deployed
Oct 12, 2021, 1:40 PM