New answers tagged struct
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 ...
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 ...
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;
...
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 ...
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[] ...
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 ...
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: ...
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 ...
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 {
...
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 ...
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(...
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 ...
Top 50 recent answers are included
Related Tags
struct × 418solidity × 304
mapping × 119
arrays × 114
contract-development × 64
storage × 45
contract-design × 43
remix × 40
web3js × 24
truffle × 15
memory × 14
gas × 10
addresses × 10
library × 9
constructor × 9
data-types × 8
go-ethereum × 7
error × 7
contract-debugging × 6
abi × 6
interfaces × 6
events × 5
evm × 5
react × 5
string × 5