CRYPTO NEWS

Ethereum testnet Beacon Chain launched and ready for trial merge

The Sepolia testnet is the next in line after Ropsten to undergo a merge trial run since its Beacon Chain is now live and ready to give developers valuable information leading up to the real thing.

How to loop over an array and be sure to get enough gas?

in my contract a function loop over an array with undefined length : function tallyVotes() external onlyOwner { uint _winningProposalId; for (uint256 p = 0; p < proposalsArray.length; p++) { if (proposalsArray[p].voteCount > proposalsArray[_winningProposalId].voteCount) { _winningProposalId = p; } } winningProposalID = _winningProposalId; } Here it’s okay the array length is under 100 but if::Listen

in my contract a function loop over an array with undefined length :

function tallyVotes() external onlyOwner {         uint _winningProposalId;         for (uint256 p = 0; p < proposalsArray.length; p++) {             if (proposalsArray[p].voteCount > proposalsArray[_winningProposalId].voteCount) {                 _winningProposalId = p;             }         }         winningProposalID = _winningProposalId;     } 

Here it’s okay the array length is under 100 but if length would have been more than 100 000 000 ( I overdo it I know) I will be out of gas ! So my question is how to handle this ? Is there a better way to loop over an array if I can’t be sure I will get enough gas ?

Ethereum testnet Beacon Chain launched and ready for trial merge

Shopping cart
There are no products in the cart!
Continue shopping
0