New answers tagged

1

You can try this code : pragma solidity ^0.8.0; contract Agent { struct Agent { uint idAgent; address direction; uint[] preferences; } Agent[] agents; uint256 public numAgents; mapping(address=>bool) _isRegistered; /// @notice Registra a un nuevo agente a la subasta /// @param _preferences preferencias del agente function regAgent(uint[] ...


1

In your example. You may create another map to record the init price, the key is unint256 key = tokenID/50, the value is the init price. Then the size of the map changes from 5000 to 100. mapping (uint256 => uint256) public initPrice; initPrice[tokenID / 50] = "the token's init Price xxxxxxx" But it seems a bad idea and hard to updata.


0

Just an update - the v2 encoder is the default encoder from Solidity 0.8 and up (see docs), meaning that you have the ability to pass in structs by default. To summarize the details in the other answers here (and this answer) and docs, from 0.6 and up the v2 encoder was no longer considered experimental, and could be invoked using: pragma abicoderv2; For ...


2

The first push consumes 41129 gas That'll be 21,000 gas for the transaction base fee, and 20,000 gas for using the storage associated with the array for the first time. (Plus 129 gas - unsure about this, but probably unimportant.) while the second one only consumes 26129 That'll be 21,000 gas for the transaction base fee, and 5,000 gas for updating the ...


1

It always depends on your needs. The biggest difference is that you can't iterate over a mapping. So if you store two entries (key => value) in a mapping, there is no way to get the values without knowing the keys. In your example, it also depends on your needs. If you only want to access the answers based on known key (so for example a function which ...


Top 50 recent answers are included