Questions tagged [struct]

Question about the solidity Structs

Filter by
Sorted by
Tagged with
2
votes
1answer
19 views

What size is an enum member inside of a struct

Let's consider the following code: pragma solidity ^0.4.18; contract Test { enum EnumTest { Test0, Test1 } struct StructTest { EnumTest Foo; uint256 Bar; } } Not taking ...
1
vote
1answer
38 views

Vyper mapping inside a struct

Is it possible to have a mapping inside a struct for vyper? For example: struct Teddy: id: uint256 year: uint256 component: map(uint256, uint256) teddies: private(map(uint256, Teddy)) ...
0
votes
1answer
33 views

How to save data using multiple structures and arrays in solidity?

How can i use multiple arrays please? e.g: I have this contract: pragma solidity >=0.4.21 <0.6.0; contract SessionManagement { struct ChargeProfileSegment{ uint startDateTimeSeg;...
1
vote
1answer
45 views

VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if

Hi Guys 👋 I have two contacts first one is SubToken and second one is MainContract. First I deploy MainContract after that I use createNewContract function and I create new SubToken. and then I ...
1
vote
1answer
19 views

Trouble accessing an array inside a struct inside a mapping via web3

Here are a few relevant code snippets from my smart contract struct Constituency{ uint16 id; string name; uint64[] cans; } mapping(uint => Constituency) public constituencies; ...
1
vote
1answer
31 views

Are memory variables initialized by solidity?

I've the following struct struct Vote { uint amount; uint count; } Is it initialized when allocated in memory? function boofar(uint val) public { Vote memory result; result.amount += val; } ...
0
votes
3answers
22 views

Struct creates instances with zero values for all of it properties instead of using function arguments

Inside my smart contract I have a struct type NotaryEntry and a function addNotaryEntry which creates an instance of the struct and add to a mapping, I do pass the right values to the function but the ...
0
votes
1answer
23 views

Return an array of structs using events?

I wan’t my function to spit out an array of structs. I know this is not straightforwardly possible. What is the best way for me to proceed? Should I loop through my array in my function and trigger ...
0
votes
1answer
42 views

Member “name” not found or not visible after argument-dependent lookup in string storage ref

I have code like this and I want to set my name, surname and age in my struct so I want to set them and get them using with my functions here's my code : pragma solidity >=0.4.0 <0.7.0; ...
1
vote
1answer
47 views

Which is faster: loop inside contract or loop of transactions?

I have this contract: pragma solidity 0.5; pragma experimental ABIEncoderV2; contract TestStruct { struct User { string name; uint256 age; } mapping (bytes32 => ...
0
votes
3answers
112 views

ParserError: Expected ',' but got identifier

pragma solidity >=0.4.0 <0.7.0; contract NewHello{ struct kullanicilar{ string name; string surname; uint age; } event infoChanged( string name, ...
1
vote
1answer
53 views

How to pass struct params in remix ide?

I have this smart contract: pragma solidity 0.5; pragma experimental ABIEncoderV2; contract TestStruct { struct User { string name; uint256 age; } mapping (bytes32 =&...
0
votes
1answer
72 views

Type string memory is not implicitly convertible to expected type struct InsanFactory.User storage ref

pragma solidity >=0.4.0 <0.7.0; contract InsanFactory{ struct User{ string name; address myaddress; } mapping(address => User) public userStructs; ...
1
vote
0answers
44 views

How to pass a struct as an argument in call using web3.py

Following is a working code on remix. It is recommended to use memory keyword for the struct parameter. Please also see: Solidity Storage Array Bugs Which does not work on Web3.py and gives the ...
3
votes
2answers
46 views

returning the struct value in smart contract and experimental ABIEncoderV2

I am storing and returning the struct value by using mapping. pragma solidity >=0.5.0 <0.7.0; pragma experimental ABIEncoderV2; contract Manage{ struct Policy{ string PolicyID ; } ...
0
votes
1answer
25 views

Web3 event listener - timing issue when immediately retrieving contract values

I'd like to be able to immediately get a struct value from a mapping after calling a function that updates the struct, however, when testing with Ganache, sometimes the event arrives to the listener ...
0
votes
2answers
56 views

How to access content of mapping in a struct?

I'm aware of this post: Accessing a mapping within a struct via Truffle console However, it seems to me, it does not provide a clear answer. Also, my question is more generic and not just for ...
0
votes
1answer
30 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
20 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
22 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
77 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
12 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
46 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
98 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
71 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
251 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
141 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
16 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
51 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
23 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
46 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
69 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 ...
2
votes
2answers
385 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
216 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
209 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
322 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
41 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
58 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
24 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
67 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
80 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"}, {"...
4
votes
2answers
94 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
268 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
117 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
94 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
193 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
124 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>) }