New answers tagged

0

Storage arrays are passed as reference. // SPDX-License-Identifier: MIT pragma solidity >=0.5.0 <0.9.0; contract A { uint256[] public a; uint256[] public b; uint256[] public c; function foo(uint w, uint256 x) public { if (w == 0) { bar(a, a.length, x); } else if (w == 1) { bar(b, b.length, x)...


0

Actually if your hashing algorithm gives you c89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6 when hashing 1 then it is the correct algorithm. It's just that you must encode the value properly before using the hash function, i.e. you must use the hex string 0000000000000000000000000000000000000000000000000000000000000001 instead of simply 1. ...


1

Solidity docs recommends using delete array Source: https://docs.soliditylang.org/en/v0.4.23/miscellaneous.html#tips-and-tricks Use delete on arrays to delete all its elements.


0

No, you have created three copies of the same data. Can't recommend something for this case but usually having a mapping from ID to Product and storing ID instead of Product.


1

It's not possible to copy data from memory to calldata. Calldata, being the cheapest type of storage, is read-only and can only be used for data passed in to a function through the transaction input. From the Solidity documentation: As already said, the called contract (which can be the same as the caller) will receive a freshly cleared instance of memory ...


1

That's not an array. That's a mapping. Mappings can't be iterated over and they are unordered - therefore they also don't have a length. In fact, there is no way to know how many entries a mapping has, unless you have stored that information somewhere else (or calculate it from outside the blockchain by looking at transactions). To delete an entry from a ...


2

Mainly because storage is expensive. A large contract require more gas to deploy and it will cost more ether. Every operation carried by a contract has an associated cost, storing data is one of the most expensive operations. The exact costs are defined in Ethereum Yellow paper and subsequent enhancement proposals. This question has some calculation about ...


0

You have to respect the constructor when you are deploying your contract. I recommend you to read this for remix: https://remix-ide.readthedocs.io/en/latest/create_deploy.html Since the deployment is the creation of the instance of your class, all the parameters defined must be presented, in this case you are expecting string memory _titel, string memory ...


Top 50 recent answers are included