Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [struct]

Question about the solidity Structs

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

Size limit to number of items in a struct

If I loop over mapping into a struct the gas fee is very low. However, in trying to test its limits, the EVM often causes Remix to crash in creating edge cases, because I'm creating blocks of 50 new ...
0
votes
1answer
41 views

How to use array of arrays with mapping in Solidity

I'm developing a smart contract handling document signing. Mainly, there are two things to consider 1) Signers 2) Sign Types. 1) Signers: Mandatory sign the document 2) Types: Types of signs such as ...
1
vote
1answer
57 views

Accessing struct fields from assembly block

Say we have the following structure: struct MyStruct { uint256 x; uint256 y; } and that it is passed as an argument to some function. Inside that function, we have assembly block from where we ...
0
votes
1answer
16 views

Deleting vs. Assigning to Default Values

If I have a struct with many customer accounts: bytes32[] public customerID; mapping(bytes32 => CustomerAccounts) public customerAccounts; struct CustomerAccounts{ address customer; uint ...
1
vote
1answer
33 views

Add Number to Item in all Struct Members

I have a struct where I want to increment an item across all struct members. For example, say there is a struct 'Contract', and new customers get their own bytes32 ID, which points to their own struct:...
0
votes
1answer
36 views

Stack too deep problem

I try to add more property to the scenario struct but when I run the compile the same error appear: struct Scenario { uint id; address payable author; address editor; ...
0
votes
1answer
16 views

Check if Struct already exists in array of structs

I am new to solidity. I have a struct and an array of structs, like this: struct Adopter{ uint age; uint gender; // 0 woman, 1 man // maybe add an id field } Adopter[] adopters; So, a ...
0
votes
1answer
19 views

Solidity. Check if key has value in mapping. Operator != not compatible with types struct

I am new to solidity. I have a Person struct and mapping: struct Person{ uint age; string gender; } Person[] players; // holds the 24 players mapping (string => Person) ...
0
votes
1answer
14 views

Solidity. Return a Sruct that lives inside an array

I am not sure how to return a struct that is inside an array of structs. This is my code: contract StudentsInfoTracker{ Student[] students; struct Student{ string name; ...
2
votes
1answer
28 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
53 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
38 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
77 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
20 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
35 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
26 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
40 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
97 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
50 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
200 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
85 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
181 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
59 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
55 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
28 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
74 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
35 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
27 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
25 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
141 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
53 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
121 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 ...
3
votes
0answers
65 views

One-to-many mapping inside struct

I have two structs: struct A{ uint bid; mapping(uint => B[]) BMap; //bid - index for struct B } struct B{ uint cid; } mapping(uint => A[]) AMap; How can we push and fetch 'cid' ...
0
votes
0answers
80 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
398 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
179 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
17 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
55 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
26 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
58 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
83 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 ...
3
votes
2answers
553 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
259 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
265 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
404 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
48 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
72 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
27 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
75 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. ...