New answers tagged

0

You have reference the mapping name at the index you want, which is a struct and the struct member for the math operations. pragma solidity 0.6.0; contract LoopingThroughArray { struct User { uint256 exampleValue; address id; } User[] public users; receive() external payable { for (uint i=0; i&...


1

You can only push one item at a time. In your case, simply split up your function: path.push(address1); path.push(address2);


0

Since you have a condition in the iteration I will add this key in Henk's answer: pragma solidity ^0.4.21; contract Foo { function getRange(uint n) public pure returns(unit[] memory result) { uint j = 0; for (uint i = 0; i < n; i++) if (someCondition(i)) result[j] = i; j++; } }


0

Operation push has changed behavior since since solidity 0.6. It no longer returns the length but a reference to the added element. You can solve this by splitting the assignment in two operations: sketchs.push(_sketch); uint _id = sketchs.length - 1;


0

You can use .push() to increase the length of the array by one. It will return a storage pointer to the new last array slot, so this should work: Checkpoint storage newCheckPoint = checkpoints.push();


Top 50 recent answers are included