New answers tagged

1

I am not sure about the end-functionality of your code in the terms of what you are looking to accomplish (Gater all the values of all the tokens owner has?) But this commented code should help, I tried to make it as simple as possible. pragma solidity ^0.7.0; contract Function{ function tokenOfOwner(address owner) public virtual returns (uint256[] ...


1

TypeError: This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour. Is perfectly normal as uint256[] storage _ownerAmount; is not initialized, meaning that it defaults to slot 0 possibly overwriting whatever is already occupying that slot. However, looking at your code you probably don't ...


0

By default, all storage locations have zero value on the EVM. So when you change a slot from zero to non-zero, the overall size of the state increases. This means, all the nodes have to allocate extra storage to accommodate for the new slot you created. However, when you change a non-zero to another non-zero, it doesn't increase the overall size of the EVM ...


0

Yes this is the case. This has also been outlined here What is the immutable keyword in Solidity? and can be found in the official Solidity docs here: https://docs.soliditylang.org/en/v0.8.11/contracts.html#constant-and-immutable-state-variables


0

NFT marketplaces are not decentralized. What happens when people start hosting [CENSORED: something horrible was here] on your website? Or what about if someone just plain steals Metallica copyrighted music for sale on your website? These both require human review. And you can handle this by normal web 2 means. If you are willing to created badges and share ...


1

For dynamic types you need to defined the storage location. In your case function usersLists(address user) external view returns (bytes32[] memory); See more information in the Solidity docs: https://docs.soliditylang.org/en/v0.8.10/types.html#data-location Edit: The question you linked used an older Solidity version, therefore it was not required there. ...


1

I didn't quite understand the depth of the idea, but maybe this option will help: function store(uint256 _myVal) public { myVal.push(_myVal); for(uint256 _y = 0; _y < myVal.length; _y++) if(_y<_arr.length) _arr[_y]=myVal[_y]; else _arr.push(myVal[_y]); }


0

Writing multiple times to a specific storage slot is cheaper, but not free. The current state is defined by EIP-2929 Edit: Since you asked about temporary or so called transient storage. There is an EIP that is aimed towards this: EIP-1153


0

In the case of the examples you posted, there is no difference. When you initialize the state variable in the line of declaration, it's the same as you if you do it in the constructor. If you want to have state variables initialized at contract creation, there is no way to optimize this. It should use a similar amount of gas in either implementation.


1

In your particular example, the difference is negligible. There are 137 opcodes used for the first case and 140 for the second case. In the first case, the storage is initialized practically immediately: while in the second case there is some boilerplate code to get to the initialization: (solidity 0.8.0 and a=10 instead of 10000000) However, constructors ...


Top 50 recent answers are included