New answers tagged

0 votes

mapped struct storage layout (slots) and collsions

I have found a lot of documentation about the layout of structs, mappings but nothing to confirm my interpretation of how they work together in mapped structs. Structs work exactly the same with or ...
user avatar
  • 4,899
0 votes

How can I return struct when function is called?

[UPDATE] Solidity Compiler version >= 0.8.0 If you want to retrieve a specific struct (in this case User's struct) from a mapping, you can do it without ABIEncoderV2. You can see this smart ...
user avatar
  • 1,165
0 votes

How can I return struct when function is called?

// SPDX-License-Identifier: MIT pragma solidity >=0.4.22 <0.9.0; pragma experimental ABIEncoderV2; contract UserMgnt{ struct User{ uint256 user_id; bytes32 name; ...
user avatar
  • 115
1 vote
Accepted

Encode a struct with solidity

If you just want to store this on your contract, solidity structs are already stored encoded in storage. Just define a data member as struct and assign values, it will be properly encoded. In case you ...
user avatar
  • 1,166
0 votes

Can I save structs in a Mapping?

yes, you can use struct in map like this: // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; contract MyFriends{ struct Friends{ string name; string[] ...
user avatar
0 votes

Passing Struct as an argument in call

Passing structs is a bad bad idea even between functions in the same contract. If you play around with structs a lot in your code, you may want to consider the effects of passing structs around and ...
user avatar
0 votes

using struct with mapping in solidity

I tried to solve your issue and implementing my logic in your claim function. I put also some notes for understand you your errors. You can see this smart contract code: // SPDX-License-Identifier: ...
user avatar
  • 1,165
0 votes

Error: "Struct containing a (nested) mapping cannot be constructed"

Update After looking at the OP's code, it seems like a incorrect use of mapping and struct. Instead of this implementation - function appendBuilding(uint8 id) public { Building storage ...
user avatar
  • 1,166
0 votes

Getter function to return a nested struct that contains mapping?

If you're using a mapping for your SomeStruct, you could implement this smart contract code: // SPDX-License-Identifier: MIT pragma solidity ^0.8.10; contract Test { struct SomeStruct { ...
user avatar
  • 1,165
0 votes

Deleting values from a struct

Based on your code, deleteAccount will look something like this: function deleteAccount(address _addr) public { delete accDetails[_addr]; delete balanceOf[_addr]; delete ...
user avatar
0 votes

Deleting values from a struct

Not sure if this is the best way but for me this works, function deleteAccount() public { require(accDetails[msg.sender].creationTimeStamp != 0, "You do not have an account."); if(...
user avatar
0 votes

I need help with balances

You can use nested mapping inside your struct for mapping different balances in it. You can see this example: // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract Test { struct ...
user avatar
  • 1,165

Top 50 recent answers are included