Questions tagged [struct]

Question about the solidity Structs

Filter by
Sorted by
Tagged with
0 votes
1 answer
11 views

mapped struct storage layout (slots) and collsions

I want to establish a pattern that ensures no storage slot collisions between current and future (compliant) versions of a contract behind a transparent proxy. In particular, contracts that are meant ...
user avatar
  • 50.6k
0 votes
0 answers
28 views

How to get struct arrays within structs in ethers?

My code: struct C { address addr; uint amount; } struct Item { uint a; uint b; C[] itemCs; int d; uint e; int f; uint g; } mapping(uint => Item) public ...
user avatar
0 votes
0 answers
6 views

How can i create a mapping properly?

I would like to create a mapping with a struct inside as key struct MyMap { bytes32 data1; address data2; string data3; } mapping(MyMap => bool) public currentMap; but i am getting ...
user avatar
  • 15
0 votes
1 answer
35 views

Encode a struct with solidity

Is it possible to encode a struct in Solidity without serializing each variable separately? Something like: struct MyStruct { uint x; uint y; } MyStruct storage myStruct = MyStruct({ x: 11, ...
user avatar
  • 265
0 votes
1 answer
25 views

using struct with mapping in solidity

i am developing a locker smartcontract where user can lock their erc20 token. i have successfully develop the adding(lock) functionality but having difficulty developing the withdraw function. for ...
user avatar
0 votes
1 answer
23 views

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

While writing a contract that uses structs, I'm getting an error by the linter "Struct containing a (nested) mapping cannot be constructed". According to this, the problem with structs is ...
user avatar
  • 11
0 votes
0 answers
20 views

How to import struct members from Solidity Library

Trying to implement the diamond upgrade following Nick Mudge implementation in aave. Been getting this error (struct member not found or not visible after argument dependent lookup in struct) ...
user avatar
0 votes
1 answer
32 views

Getter function to return a nested struct that contains mapping?

For example, struct SomeStruct { uint _someUint; uint _someUint2; mapping(address => uint) _someMapping; } A getter function for a non-nested struct could be ...
user avatar
  • 37
0 votes
2 answers
31 views

Deleting values from a struct

how do i go about removing values from inside a struct and or a mapping. For example iam creating a smart contract that acts kind of like a vault, iam not yet finished but i have a create an account ...
user avatar
0 votes
1 answer
13 views

I need help with balances

I would like to create a balance for each "vault". for example i will have my struct: struct unnamed { string[] crowdFundName; } I would like to add a balance to each vault for ...
user avatar
0 votes
1 answer
42 views

Can a library have a `public` function using `struct memory`?

I can't find any up-to-dates (and clear enough for my level of understanding) responses to this question that has also been raised very recently on a hardhat issue, with no response to date (https://...
user avatar
0 votes
1 answer
13 views

Returning structs from Chainlink oracle job

Is it possible to return struct from chainlink oracle job? I would like to return list of transactions from chainlink job to the contract. So far I've only seen examples where it's possible to return ...
user avatar
  • 101
0 votes
1 answer
39 views

Array of structs inside a struct

Im trying to set a mapping to a struct that contains an array of structs inside. Like so: struct ParentTokenDetails{ TokenType _tokenType; address _tokenOwner; ChildTokenDetails[] children;...
user avatar
0 votes
0 answers
32 views

struct array in a mapping updating

mapping(address => trnsctn[]) private transactionsOfAdress; struct trnsctn{ uint256 when; uint256 amount; } uint256 public ege; function deposit() public payable {...
user avatar
  • 3
0 votes
1 answer
32 views

Efficient struct ordering for less gas

Unlike initializing state variables in specific orders in order to save on gas, does this also apply to how you declare your struct properties where you keep lower uints side by side each other? // ...
user avatar
  • 103
0 votes
0 answers
21 views

The best option to share structs

What is the best and common option for sharing structs between contract? I can use for that Library, Interface or Contract and put there a Struct and then import it to another contract. But what is ...
user avatar
0 votes
1 answer
24 views

Get data from mapping whose values are struct and keys as address (msg.sender)

Hey so this is my solidity code, when I am running the getter functions, I am not seeing any output. And as for a fact I don't even know whether the setter functions are even working or not. Please ...
user avatar
0 votes
0 answers
14 views

Delete struct from array of structs

I've found a great answer to do things with an array of structs here but I am a bit confused about one particular example which is below: contract mappingWithStruct { struct EntityStruct { uint ...
user avatar
  • 118
0 votes
1 answer
41 views

TypeChain says the struct array field does NOT exist in my Ballot struct, why?

I am trying to test my voting ballot contract using Hardhat/ethers/TypeChain, but for some reason, the Ballot struct's typescript interface is NOT showing the array of choices struct field I have ...
user avatar
  • 1
0 votes
1 answer
42 views

Cheapest way to access and modify a struct

I am using solidity 0.8.10. In my contract I have a state variable struct: struct Product { uint id_prod; address payable producer_addr; address payable owner_addr; bool onSale; } ...
user avatar
  • 113
0 votes
1 answer
46 views

How to override an interface function that returns a struct with a mapping

I have an interface with a public function foo that consumes a single address parameter and returns a Point struct: //SPDX-License-Identifier: MIT pragma solidity ^0.8.4; interface IFoo { struct ...
user avatar
0 votes
1 answer
17 views

How do you manipulate a storage struct array with an external library function?

Basic pseudocode mockup of my problem import libraryB; contract A{ struct Person{ string Name; uint age; } Person[] public Party; Party[0] = (Alice, 30); libraryB.addAgeToPerson(Party[0], 1) } ...
user avatar
1 vote
1 answer
24 views

How can i test this solidity contract for(lets say) 5000 calls of the set function(.sol or .js)?

// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; contract storeData { uint256 internal index = 0; struct IslandFcst { uint islandId; uint forecastDate; ...
user avatar
0 votes
1 answer
14 views

How can i able to get total students details from struct at a time when i call?

Solidity Code: pragma solidity 0.5.1; contract Management{ struct studentInfo { string name; string birthdate; string department; string location; string email; uint256 ...
user avatar
0 votes
1 answer
30 views

How to update a struct field from different contract

pragma solidity ^0.8.0; contract Contract1 { struct User { bool isValid; uint value; } mapping(address => User) public party; } ...
user avatar
  • 880
0 votes
1 answer
66 views

Member "xxx" not found or not visible after argument-dependent lookup in type

How can I access to fields of struct that is in mapping from different contract? pragma solidity ^0.8.0; contract Contract1 { struct User { bool isValid; uint value; } ...
user avatar
  • 880
1 vote
1 answer
57 views

sload. with struct - loading bytes

I'm trying to load varios bytes from a struct in assembly. I found a good explanation here for uint. While this is working for uint and the whole memory slot i cant figure out how to get a bytes1 or ...
user avatar
0 votes
1 answer
64 views

Create dynamic fixed-size arrays

Any ideas on how to dynamically create fixed-side arrays that doesn't involve a bunch of if statements? EDIT: Got this function that needs to produce a fixed-side array which length would depend on ...
user avatar
  • 265
1 vote
1 answer
39 views

Solidity - Struct Array Inside Mapping | How to reference Struct Array Elements?

I am unable to reference struct elements which are inside mapping. Mapping: struct VoterData { string iD; address voterEthAddress; } // One to Many mapping; one Eth ...
user avatar
0 votes
1 answer
41 views

What is the most appropriate Natspec tag to use for struct properties?

For each struct property, what is the most appropriate Natspec tag to describe what it is? Is it acceptable to use @param?
user avatar
0 votes
0 answers
29 views

Unable to assign dynamic array to Struct field

I have a struct where a field (whitelist) is a dynamic array of addresses: struct Project { string name; address[] whitelist; } mapping(uint => Project) public projects; function setProject(...
user avatar
  • 133
1 vote
0 answers
13 views

Writing tests for a contract function that uses a struct

I have a contract that implements an interface which contains a struct that is used in both the arguments to a function as well as the return value. // IContract.sol interface IContract { struct ...
user avatar
-1 votes
2 answers
135 views

How to store all user's data separately to smart contract

What is the best way to store users data on smart contract? Suppose we have n number of users and we want to store each user's username and his/her other details. For example if i enter my wallet ...
user avatar
0 votes
1 answer
130 views

Different number of components on the left hand side (1) than on the right hand side (0)

Need this architecture { address1 => [struct1, struct2], address2 => [struct1, struct2, struct3,], address3 => [struct1, struct2, struct3, struct4, struct5], ... } My ...
user avatar
0 votes
1 answer
25 views

return a struct from a mapping of addres-struct

I'm trying to return a struct called Trainer from a mapping of addresses -> Trainer Is there any way to easily retrieve the Trainer struct from the trainersMap? struct Trainer { address owner; ...
user avatar
  • 1
0 votes
1 answer
39 views

Array of nested structs

I am trying to write a simple election contract, currently trying to add candidates to an array of Candidates in my Election struct. Can this be done and if so how can it be implemented? The code ...
user avatar
0 votes
0 answers
90 views

How to sort an array of structs by struct's value, inside another struct?

this is a contract where a "board" struct nests an array of "participant" structs. Every Participant struct has a score, which can be upvoted with a specific function. I'm trying (...
user avatar
0 votes
0 answers
15 views

Question about a struct called in an interface

a huge thanks to the members here for their support. I have a question regarding a struct that is declared in an interface. Lets say you have two contracts: "Contract_A", which is already ...
user avatar
  • 11
0 votes
1 answer
44 views

Accessing and storing a Struct from external contract

I was trying to access and store a Struct from an external contract. Is there a way with which this is possible. This would be a simple PoC where I am trying to access a Struct from Student contract ...
user avatar
  • 15
0 votes
2 answers
291 views

What is the gas cost to read a member of a global struct?

Say I have a global state variable struct MyStruct that has multiple members/attributes/fields, what is the gas cost for reading a specific member? Is it equivalent to the gas cost of reading the ...
user avatar
  • 170
3 votes
1 answer
150 views

ethers.js web version, but not hardhat local version, gives error when calling contract

In a react/ethers web page connected to Polygon Mumbai, I get this classic error: Uncaught (in promise) Error: invalid address or ENS name (argument="name", value=undefined, code=...
user avatar
  • 81
0 votes
0 answers
42 views

How do I read the length of a struct in JS for my Front-End?

I have a couple questions regarding structs and accessing their information on my React front-end. The struct is as follows: struct BracketPicks { address user; uint8[] allPicks; } ...
user avatar
0 votes
1 answer
120 views

Is it possible to have an immutable or constant struct?

Is it possible to have a struct that is or has fields that are constant or immutable? // struct with constant or immutable fields: struct MyStruct { uint constant number; int immutable integer; } ...
user avatar
  • 170
0 votes
0 answers
57 views

How do i pass in an array of struct from js to a contract

If i have a contract like below contract Test { struct Bar { uint a; uint b; bool c; } Bar public z; string public y; function foo(string s, Bar[] memory ...
user avatar
  • 101
0 votes
1 answer
60 views

Logical negation, conditions on struct, mappings

I'm still playing around with my first bigger smart contract, and I'm creating something like public sale, ICO, etc. Now I'm at the point where I want to specify some conditions like: one address can ...
user avatar
1 vote
0 answers
159 views

How to change/set values of a mapping through a function in solidity?

I have the following structure, with the mentioned mapping struct A { uint a; bool[100] b; } mapping(uint => A) public arr; I am using this function to set/...
user avatar
0 votes
1 answer
42 views

What is the most gas efficient way to read and write to global contract state?

Say I have a complex(list, mapping or struct) global/contract variable. What is the most gas efficient way to update that variable in a function that changes the value of one or more indexes, values ...
user avatar
  • 170
1 vote
2 answers
47 views

How Retrieve a specific entity on mapping

I'm trying to start a stacking smart contract. Each user can stake different ERC20 Token. I'm using follwing struct : struct Token { address tokenAddress; uint256 stakedAmount; ...
user avatar
  • 157
1 vote
1 answer
27 views

Access arrays from public struct mapping?

I have this struct: struct Amendment { string text; uint24 textColor; bool isRadialGradient; uint8[2] radialGradientCenterPct; uint16 linearGradientAngleDeg; uint24[2][11] ...
user avatar
  • 123
1 vote
1 answer
61 views

What is the most gas efficient way to initialise a struct?

Say I define a struct named MyStruct and a local variable called myStruct, what is the most gas efficient way to assign/update 1 or more fields/members of myStruct? If I wanted to assign a new value ...
user avatar
  • 170

1
2 3 4 5
9