New answers tagged

0

It is possible to do something like this: struct Location { string city; string street; uint time; } struct Product { uint id; string name; mapping (uint => Location) locations; } mapping (uint => Product) products; Then the implementations will be like: function viewLocation(uint _productID, uint _location) public returns(...


1

This field's type is editor[], and its name is editors. So change rentalStructs[_bagId].editor to rentalStructs[_bagId].editors. Also, for good practice, I recommend that you move struct editor { ... } before (above) struct BuildingRental { ... }, since the latter depends on the former and not vice-versa.


0

Solidity automatically adds a getter to public mappings and returns a tuple, so there is no need for a function like getUser(uint256 user_id). Check out solidity documentation for returning multiple values


0

From Solidity read the docs: Array: Arrays can have a compile-time fixed size, or they can have a dynamic size. Indices are zero-based. Takeaway: Solidity does not support heterogeneous arrays yet, i.e. the indices for arrays are integers and not any other value. Mapping: Mapping types use the syntax mapping (_KeyType => _ValueType) and variables of ...


1

If you need any of the following to run in O(1) operations: Get an item by unique ID which is not a sequential number (e.g., an address) Remove an item Then an array is inappropriate, and you must use a mapping.


0

I tried the contracts in Remix and they kind of work, updateDoc might trigger the event DocUploaded multiple times and the _title is not updated. The function updateDoc doesn't need to iterate over the mapping. It can access the Doc directly with _id. function updateDoc(uint _id, string memory _IPFShash, string memory _title) public { if (Docs[_id].id =...


3

Like this: struct Example { uint a; uint b; uint c; } Example public example; function set1(uint _a, uint _b, uint _c) public { example.a = _a; example.b = _b; example.c = _c; } function set2(uint _a, uint _b, uint _c) public { example = Example(_a, _b, _c); } function set3(uint _a, uint _b, uint _c) public { example = ...


0

You can access only one element of an array with the automatically generated getter method (the argument passed is the position of the array to return, default is 0). To get the full array, you need to write a getter yourself that returns an array. Also, I recommend you use a mapping instead of a dynamic array: contract TestChainStorage { ... ...


Top 50 recent answers are included