Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [struct]

Question about the solidity Structs

0
votes
1answer
9 views

Associate event struct to user addresses

I have two contracts. One called User and other called Event pragma solidity ^0.4.24; contract User { mapping(uint=>address) addresses; uint addressRegistryCount; } pragma solidity ^...
0
votes
0answers
20 views

How can I pass struct from one contract to another?

I have two contracts and I'm trying to pass the struct data from one to another, I can do this by creating a mapping and having a uint input associated with that struct but I'd like to get the struct ...
0
votes
1answer
10 views

Struct and Mapping input value error of Invalid Opcode while calling setSeller() to store multiple seller's addresses

What dose the -1 means? Or why we should use -1 while pushing one element in array. What should I enter in sellerAccounts: field as input? pragma solidity ^0.5.1; contract Seller{ struct ...
0
votes
1answer
27 views

Making a contract with new keyword address is always 0x0000000000000000000000000000000000000000

I'm making a contract that makes other contracts. Once the contract is made using address tokenAddress = new MyToken('Name'); I want to save the address of the contract, tokenAddress, in MyStruct. ...
0
votes
1answer
24 views

Access modifiers for properties of a struct

I am relatively new to Solidity. I am following a tutorial and came up with the following contract: contract Election { struct Candidate { uint id; string name; uint voteCount; } ...
0
votes
1answer
23 views

Array of struct inside and a array

It´s posible to save structs inside array and all this array´s inside the same array. I mean: [ [{"struct"}, {"struct"}, {"struct"}], [ {"struct"}, {"struct"}], [{"struct"}, {"struct"}, {"struct"}, {"...
2
votes
2answers
56 views

Why is the Eternal Storage approach still used if it hugely increases gas usage compared to storing data in structs?

I was wondering why is the eternal storage approach (first code snippet) still used? I know it's meant to make contracts upgradable but it seems too expensive to me. contract Storage { mapping(...
1
vote
1answer
102 views

Nested structs that are part of a mapping broken in Solidity 0.5.0?

The following code compiled successfully with Soldity 0.4.21. With 0.5.0 it triggers a fatal compilation error as follows: UnimplementedFeatureError: Encoding type "struct TestNestedStructInMapping....
1
vote
2answers
17 views

Can I instantiate a struct with a member struct without supplying a member struct?

I have a struct containing another struct. The member struct does not yet exist when instantiating the containing struct. Is there a default for a struct (for address, int, etc' I would initialize ...
0
votes
1answer
17 views

Is there any way to return multiple structs (or the fields from them) in Solidity when one of the struct fields is of type `bytes`?

I would like to return structs keys from my contract to display on the frontend, ideally 10 at a time. I understand that if I make keyByOwner public I can return a single key at a time with the getter ...
1
vote
1answer
26 views

Set just a couple of parameters in a Struct

I have a struct with 10 parameters. The idea is to apply this struct for represent the flow of a trace. So I have to set variables values in a stepped way. Now i´m trying to call a function to set the ...
0
votes
1answer
13 views

Struct param not found

I´m trying to call a function insertOrigin inside a struct and then call other function getOrigin to return that values. But VS Code get a error pragma solidity ^ "0.4.24"; contract Origin { struct ...
0
votes
1answer
58 views

How can return a struct from a function [duplicate]

I have one solidity file, inside that file I have a this function: struct OriginInfo{ string 1; uint32 2; //In timestamp uint8 3; address 4; bool 5; } function insertOrigin(...
0
votes
1answer
22 views

How to initialize a new struct with an empty mapping? [duplicate]

For expl. mapping(uint => Test) tests; struct Test { uint id; mapping(address => uint) votes; } function newTest() public { test[0] = Test(0, <EMPTY_MAPPING>) }
1
vote
1answer
36 views

How can data be retrieved in Ethereum?

I am a newbie to the blockchain world. I have written contract code in solidity and tested in remix. I am able to get the list values from the struct, but I am confused on how I can get a single ...
1
vote
1answer
20 views

How to initialise a mapping of a struct inside a function?

Mappings are normally declared in the top part of the contract, however is there any way to instantiate a mapping - which belongs to a struct - while in a function?
1
vote
3answers
38 views

updating variable inside and outside struct, different results, why?

With this, bool p does not update, contract b { bool p; mapping(uint => bool) public t; function setValue() { bool b = t[1]; b = true; } function ...
0
votes
1answer
18 views

Read List of Posts using struct

I tried to read a list of posts using the code below struct posts { bytes32 postTag; string post; address[] acceptedBy; uint8[] voteCount; } mapping(address => posts) totaluserPosts; ...
2
votes
2answers
41 views

How to create Interface to read Struct in mapping?

There are 2 contracts A and B. A has a mapping which returns Struct: mapping (bytes32 => Cup) public cups; How can we read the cups mapping in contract B? Following code doesn't work for sure:...
1
vote
2answers
52 views

Display Array of struct within array of struct in react

I'm trying to create 2d array of different types, one of the users have suggested to use struct within a struct method -> 2d array of different types? Now I run into problem how to display it in my ...
0
votes
2answers
43 views

initialise array of struct inside a new struct

Following up on the question of 2d array of different types: 2d array of different types? How would one go about initializing a new array of structs (Vote) when creating a new struct (Project) ...
0
votes
2answers
83 views

Solidity: How to initialize an array within a struct, passed as a parameter?

pragma solidity 0.4.25; contract A{ struct N{ string any; uint256[] numberArray; } N[] public numbers; function init(uint256[] _numbers) public{ for (uint256 ...
3
votes
1answer
44 views

Initializing array of structs inside a mapping of structs - "UnimplementedFeatureError

I have two structs struct Vote { address from; uint256 rep; bool vote; } struct Pool { address from; string tokenSymbol; string name; uint256 timeout; string evidence; ...
0
votes
1answer
43 views

Gas cost in a struct

If i change a existing uint variable in a struct compared to normal ones does it consumes the same amount of gas(cost)? Im trying to optimize my contracts cost
0
votes
2answers
84 views

How would you render this structure of data?

I have coded a smart contract which allows one to store a certain type of structure of datas which can be described as something like that : ├── Client1(Contract) │ ├── Year2018 (Struct containing ...
1
vote
1answer
28 views

How to dynamicaly edit a mapping

I want to be able to edit values in a struct. My struct is declared and mapped like this : struct entityLinks{ string linksUrl; string linksName; } mapping (uint => ...
1
vote
1answer
71 views

Reading nested structs

I've got this snippet of code within a contract: struct Brick { uint256 length; uint256 width; uint256 height; } struct Garage { uint256 length; uint256 width; uint256 height;...
1
vote
1answer
25 views

What is the best way to imbricate structs of data?

I'm creating a DAPP and i'm currently drafting the structure of my code. I'm not really experienced with Solidity so i'm trying to have a clear representation of my code before starting to code it. I ...
1
vote
1answer
65 views

How to have an address inside a solidity Struct?

My problem Suppose I have this struct: struct TextThatWorks { bytes32 text; uint reads; } How can I add a address variable to it? What I tried I tried simply adding address ...
0
votes
1answer
68 views

solidity dynamic struct array

when I develop my smart contract with solidity, I encounter a problem. And Below is my solidity code. pragma solidity ^0.4.0; contract RegisterContract{ event setNewUser(bytes32 name,address ...
2
votes
1answer
43 views

Can i create a new address this way?

I am busy with a project. So I have an array of a struct within another struct. In this case for example array of CattleHealth in Cattle. In my RecordHealth function, I am taking the address of the ...
1
vote
1answer
27 views

How to add an instance of a struct to an array of another?

Hi I am pretty new to solidity. I am busy with a project that records all kinds of information about cattle. In my code below my cattle struct has an array of CattleHealth and CattleGrowth which are ...
1
vote
1answer
101 views

How to map Array of Structs in Solidity [duplicate]

Need this architecture { address1 => [struct1, struct2], address2 => [struct1, struct2, struct3,], address3 => [struct1, struct2, struct3, struct4, struct5], ......
0
votes
1answer
76 views

Array of Struct always returns 0x0 at index 0

Here's my sample contract code. contract SimpleStore { uint public BetRound; uint public SelectedUser; struct Struct { uint _round; address _owner; uint _index; bool _active; ...
3
votes
1answer
184 views

Pass array of structs to contract from truffe using ABIEncoderV2

How do you pass an array of structs from Truffle (javascript) to a smart contract (Solidity)? There are a few similar questions (like this one and this one) whose answers say you cannot pass a struct ...
1
vote
0answers
25 views

Understanding Solidity Libraries using Solidity Docs code example

I was going through this code (see code below) about how to use libraries in solidity docs : https://solidity.readthedocs.io/en/v0.4.24/contracts.html?highlight=library#libraries and there are some ...
2
votes
2answers
93 views

Adding an array in mapping

The main purpose of this code is to add an array of users in mapping. there are certain users who play a video game and are on a certain level now level will be considered as a mapping index and on ...
2
votes
1answer
27 views

Access single value of a mapped struct

I want to access a single value of a mapped struct from another contract. For now, I know how to return all values of the struct by using the following code: function getUnitById(uint256 _id) public ...
2
votes
1answer
151 views

Storing a dynamic array of structs which contains a dynamic array of structs

I am trying to create the following objects: Bounty[] public bounties; struct Bounty { address issuer; uint256 fulfillmentAmount; uint256 balance; bool bountyOpen; Fulfillment[] ...
0
votes
1answer
18 views

As of today (Solidity v0.4.22)… Is there a way to return structs from public functions?

https://medium.com/coinmonks/solidity-tutorial-returning-structs-from-public-functions-e78e48efb378 According to this article (link above), on Medium I'd have to use tuples... but this was so in ...
0
votes
0answers
28 views

hash an array of structs

So what I am trying to do is create a keccak256 of an array of structs. pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; contract Test { struct test1 { address test; ...
0
votes
0answers
36 views

Problem creating struct inside a struct

Currently I am developing a game in solidity, I have 2 structs as follow: struct Team{ address owner; uint[] players; uint8[] moves; } struct Game{ Team challenger; Team ...
1
vote
1answer
398 views

InternalCompilerError: Stack too deep, try removing local variables [duplicate]

I want add and store more than 16 variables value in in my private blockchain, I am unable to define the variable in Struct {}, I got Error "InternalCompilerError: Stack too deep, try removing ...
2
votes
1answer
62 views

Modify Struct on Upgradeable Smart Contracts

I have reviewed some techniques around Upgradeable smart contracts from starting point(Elena Dimitrova's Eternal Storage) to zeppelinOS's Unstructured Storage pattern. As I understood from posts that ...
0
votes
1answer
24 views

bytes value while initialising struct

struct Proposal{ uint32 id; string text; bytes docs; bool selected; uint expectedBudget; address submitter; } // _text and _expectedBudget already define. Proposal proposal = ...
0
votes
0answers
27 views

Quorum PrivateFor unable to work with structs of structs (nested structs) / arrays within structs in solidity

I am able to use privateFor in quorum to set and get multiple values. However, when I deployed a complex contract consisting of struct of structs, array of arrays, privateFor doesn't work -- unable to ...
0
votes
1answer
70 views

Unable to retrieve struct from mapping

I have a mapping like this: pragma solidity 0.4.24; pragma experimental ABIEncoderV2; pragma experimental "v0.5.0"; ... mapping(bytes32 => LibMarket.Market) public hashToMarket; where each ...
0
votes
0answers
38 views

How to use multidimensional memory array in solidity

I'm working with a project where I have requirement of multidimensional memory array. Here is basic structure of types and person(s) Id -Types -0 -Person1 -Person2 -1 -Person1 -...
1
vote
1answer
273 views

Code Explanation of how to return an array of structs

I was reading a tutorial on a medium about how to return an array of structs. This is the code they have for doing it. pragma solidity ^0.4.13; contract Project { struct Person { ...
0
votes
1answer
39 views

What is the cheapest and most efficient way to send data to a struct, and why?

I'm struggling to find which way to send data to a struct is cheaper and most efficient. I came up with these 2 different styles: struct Database { string name; string addressPerson; } ...