Stack Exchange Network

Stack Exchange network consists of 175 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
17 views

Initialize an array of struct within a struct

I am working on a use case of "Purchase Order" wherein there will be multiple Products listed/ordered under one Purchase Order(PO) by a buyer. 1 PO : N Products struct Product{ bytes32 ...
0
votes
1answer
17 views

Storing geo location in contract

I am beginner in solidity programming, I am trying to write my first contract. I am trying to store a piece of land (which is array of coordinates) against a person. I am having trouble storing the ...
0
votes
1answer
8 views

How can I pass struct as function parameter with ABIEncoderV2 from outside?

have this code: struct UserScore { address user; uint score; uint time; } function getWithStruct(UserScore _user) public view returns (address, uint, uint) { return (_user.user, _user....
0
votes
1answer
25 views

How can I send array of structs as arguments?

I want to send to my contract an array of currency and its price so it will store it: pragma solidity ^0.4.24; contract ExchangeContract { enum CurrencyType { USD, TWOKEY, BTC, ETH, DAI, USDT, ...
0
votes
0answers
10 views

How to return a struct which contains another struct?

I'd like to return a struct which contains another struct. When calling the function, I want to make the return result likely to 0:string: Username 1:string[]: [[a.doc,...
1
vote
1answer
33 views

Struct member access in web3 requires additional dummy field

If a struct contains a single field, then that field is inaccessible from web3. In the below example, field uint b must also be present in order to access field uint c from web3. Of course, it's not ...
2
votes
3answers
49 views

Should I use require in view functions?

When I call a solidity function to get a struct element, is it a best practice to use require and check if the element exists or should I just return the empty values? Without require: function ...
0
votes
0answers
56 views

How should I pass a nested struct as a function argument in Remix IDE?

Example contract: pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; contract someContract { struct structOne { uint a; } struct structTwo { uint b; ...
0
votes
2answers
122 views

Default getter and setter for mapping in solidity

In my smart contract I've public mapping as mapping (uint=>User) public users where User is a Struct, so is there any way to get the values of this mapping using default getter. For Example : If ...
0
votes
1answer
93 views

Invalid type for argument in function call. Invalid implicit conversion from mapping

I have defined struct for saving data to ethereum blockchain. I am using uint to map the data stored with a unique ID. I am using truffle framework to write smart contracts with solidity version: 0.4....
1
vote
1answer
15 views

Use Values Returned from One Function in Another

need a little help if you can spare the time. Making a little card game where people can collect "warrior" cards. We'll have an initial 12 master "cards" that supply the initial traits for the ...
0
votes
1answer
45 views

Pushing a stuct into an array

What i am attempting to do is elementary, adding a struct to a storage array. But for some reason I am getting the following error TypeError: Indexed expression has to be a type, mapping or array (...
0
votes
1answer
19 views

Read storage struct from a modifier

If i read a struct(storage) Human storage human = humans[2]; in my modifier is there a possibility that the function that uses this modifier can use the "human"? Otherwise i have to scope the storage ...
2
votes
1answer
34 views

Passing in an array of complex structs

I am wondering what pattern I am supposed to follow in Solidity to take in an array of structs as a parameter. I am translating code from CPP and mostly everything translates directly besides this (...
1
vote
1answer
56 views

Can I modify a struct property and send it back to the contract?

we are experiencing an issue dealing with structs. We expect to modify a struct property after getting it from an event in web3js, but, it seems that the modify does not apply. Any ideas? Contract ...
1
vote
2answers
217 views

Passing Struct as an argument in call

I am trying to pass a struct as an argument while calling the function of another contract: pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; library Test { struct TStruct { int x; ...
1
vote
1answer
139 views

UnimplementedFeatureError: Encoding type “struct BiddingContract.Bidder memory” not yet implemented

The code is broken with the new upgrade v0.5, using Truffle v5.0.1 (core: 5.0.1) struct Bidder { address bidders_address; uint productId; uint bidValue; } struct Product { uint ...
0
votes
2answers
152 views

access mapping inside mapping of struct in Solidity ^0.5.0

I have a contract which looks like this: contract a { struct Str { uint256 totalTokens; mapping(address => uint256) playerTokens; } mapping(uint256 => Str) public ...
1
vote
0answers
202 views

Check if a struct is empty

I have a function where I pass a id. With that id the contract find in a mapping a struct. My idea is to check if exists that struct with the given id with a if clause. I try with 0, null, "". Is ...
0
votes
1answer
30 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 ^...
1
vote
0answers
45 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
19 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
59 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
56 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
29 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"}, {"...
3
votes
2answers
78 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
237 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
30 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
81 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
57 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
14 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
152 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
90 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
38 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 ...
0
votes
1answer
48 views

Return an array of mappings reflecting global state between struct associations?

I am looking for a construct that's something like "return an list of key value pairs," which I think would be implemented as an array of mappings. Is that right? That is, I'd like a data structure ...
1
vote
1answer
53 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
67 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
20 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
144 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
65 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
52 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
247 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
62 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
116 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
115 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
66 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
135 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
28 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
112 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
99 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 ...