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
0answers
16 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
1answer
25 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
31 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
14 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
36 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
16 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
20 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
25 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
75 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
60 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
49 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
71 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
17 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
33 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
17 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
44 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
33 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
27 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
65 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
179 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
23 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
36 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
41 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
94 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
49 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
37 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
41 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
26 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
42 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
19 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
95 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
59 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
46 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
138 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
56 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
76 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
105 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
44 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
105 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
27 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
77 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
86 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
53 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
33 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
153 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
91 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
233 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
36 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
188 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 ...