Hot answers tagged

2

OK, I ran a simple test and found out that in a dynamic array, the length of the array is located at the first 32 bytes relatively to the beginning of the array: Smart Contract: pragma solidity 0.4.25; contract MyContract { function read1() external pure returns (uint a, uint b, uint c) { uint[3] memory arr; arr[0] = 111; arr[1]...


1

I'm going to suggest a more ethereum-like approach. You can probably do that with the experimental ABI encoder. As well as stability concerns, there is a serious problem with overall approach. The gas cost of the operation will increase with the size of the array. That will make it impractical or impossible to use if the array grows too large. In most ...


1

About error handling in Solidity you can read here. Use require instead of if: The require function should be used to ensure valid conditions that cannot be detected until execution time. These conditions include inputs, or contract state variables are met, or to validate return values from calls to external contracts. You don't need to pass the ...


1

You need to directly access the members of the struct. Solidity docs. userStructs[msg.sender].name = name; userStructs[msg.sender].myaddress = myaddress; Code: pragma solidity >=0.4.0 <0.7.0; contract InsanFactory{ struct User{ string name; address myaddress; } mapping(address => User) public userStructs; address[...


Only top voted, non community-wiki answers of a minimum length are eligible