I have a contract in which I must import ~100k ETH addresses into a map. Whenever I try to do that on Ropsten network (via Infura), I receive the error:
Error: exceeds block gas limit
If I try to do it on Ganache, the RPC client crashes:
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
What other tools could I use to avoid these congestions? Can these errors occur on mainnet as well?
I must create a voting system and restrict the access of voting to only 100k people. Thus I must somehow import the addresses of those people into contract:
// SPDX-License-Identifier: ISC
pragma solidity >=0.8.0;
contract Vot {
// Key can have three states:
//
// 0 -> not assigned
// 1 -> assigned, address can vote
// 2 -> assigned, address cannot vote
mapping (address=>uint8) private _votersWhichCanVote;
// Stores the votes with the voters in list.
// Did it likewise to have O(1) complexity for votes retrieval.
int8[] private _votes;
address[] private _voters;
address private _owner;
constructor() {
_owner = msg.sender;
}
// Import voters without overwriting existing ones.
// Only contract creator may call it.
function importVoters(address[] memory voters) public {
require(msg.sender == _owner);
for(uint256 i=0; i<voters.length; i++) {
if(_votersWhichCanVote[voters[i]] == 0) {
_votersWhichCanVote[voters[i]] = 1;
}
}
}
// One user votes.
// Sender must be present in _votersWhichCanVote.
function setVote(int8 choice) public {
require(_votersWhichCanVote[msg.sender] == 1);
_voters.push(msg.sender);
_votes.push(choice);
_votersWhichCanVote[msg.sender] = 2;
}
function getVotes() public view returns(int8[] memory) {
return _votes;
}
function getVoters() public view returns(address[] memory) {
return _voters;
}
function iCanVote() public view returns(bool) {
return _votersWhichCanVote[msg.sender] == 1;
}
function iHaveVoted() public view returns(bool) {
return _votersWhichCanVote[msg.sender] == 2;
}
}
The only solution seems to be batch inserts?