Questions tagged [struct]

Question about the solidity Structs

Filter by
Sorted by
Tagged with
0
votes
0answers
12 views

Arrays not showing up inside structures

I am creating a record of people and have created a structure struct asset{ uint assetId; string hash; address creatorAddress; uint cost; uint soldCount; } struct person{ uint ...
0
votes
1answer
39 views

How to encode arrays for solidity function calls

I want to understand how to encode the following arrays in Solidity. Dynamic Arrays For example, the following: function getDynamicUintArray() public pure returns (uint[] memory) { uint[] ...
0
votes
1answer
13 views

Solidity: How to enter a value in a dynamic array inside a struct?

I'm working on the following code in Remix IDE. What I'm trying to do is create an object of a structure that is mapped to an address. Inside the struct, there is a dynamic array. How can I put a ...
1
vote
1answer
27 views

adding an struct instance into a dynamic array of struct objects

Consider this code. function getDoctorsList(uint[] memory _docIds) public view returns (doctor[] memory) { doctor[] memory _doctors; for(uint i = 0; i < _docIds.length; i++) { ...
1
vote
1answer
20 views

Add and compare items of struct in Solidity (dealing with struct in Solidity)

How can I know the whole entityData of the struct and add a new entity only if it didn't exist before (ensure no replicated data)? struct EntityStruct { uint entityData; bool isEntity; bool ...
0
votes
1answer
18 views

Struct is not saved in mapping for some unknown reason

I don't understand why my struct is not saved in mapping. I've tried diffrerent methods of initializing struct I found all over the web and it didn't work on development network (ganache + truffle). ...
2
votes
1answer
20 views

Accessing struct members

Can we access the struct member using a variable as we access in JavaScript? For example: struct Abc { uint256 a, uint256 b } Abc xyz; string memName = 'a'; I want to do something like ...
2
votes
0answers
28 views

How to store array parameter of a function to contract state?

I am trying to save an invoice to contract storage (see function addNewInvoice(..)) but I seem to be tripping over the data locations. // SPDX-License-Identifier: private pragma solidity >=0.7.0; ...
0
votes
1answer
40 views

How do i loop through an array of structs? “TypeError: Integer constant expected.” Solidity

What i want my code to do Everytime the function is called the exampleValue of all users should be increased by 5 What the code actually does When i compile it in Remix i get this error message: ...
1
vote
1answer
28 views

I do not understand the definition used to update a mapping stored inside a struct type as explained below

struct Payment { uint amount; uint timestamp; } struct Balance { uint totalBalance; uint numPayments; mapping(uint => Payment) payments; } mapping(address => Balance) public ...
0
votes
0answers
18 views

Storing Struct inside an array. Help Please

I am designing an EHR System that will store patient records (with a unique ID) and separated by the date and Hospital entered. I am able to enter data in Hospital struct mapping to the Record struct, ...
0
votes
0answers
14 views

How can I delete values from nested mapping after a sum

I'm making an staking contract in solidity and i have used structs and nested mapping for saving users staking amount and its staking time, At the time of calling unstake function msg.sender will ...
1
vote
1answer
29 views

How to add a field to a struct dynamically?

Suppose we have a proxy contract that separates Data layer from Logic layer. We have a struct in Data contract, like this: struct person { uint id; string name; } mapping(address => person) ...
1
vote
2answers
29 views

Resetting the value of a structure

I am fairly new to solidity and I am trying to create a lottery contract where every address needs to pay 1 ether to get added to the lottery pool and at the end, the owner would randomly select one ...
2
votes
3answers
400 views

Solidity Error: Struct containing a (nested) mapping cannot be constructed

My version of solc: "solc": "^0.7.1", When I try to construct a struct that contains mapping, I got this error: "Struct containing a (nested) mapping cannot be constructed&...
0
votes
1answer
143 views

UnimplementedFeatureError: Copying of type struct Question memory[] memory to storage not yet supported

How can I resolve this error: "UnimplementedFeatureError: Copying of type struct EthereumOpinionRewards.Question memory[] memory to storage not yet supported"? My code is provided below. ...
0
votes
0answers
102 views

Gas requirement is infinite for the function

pragma solidity ^0.5.9; contract kyc2{ bool public isallowed; // Structure of customer struct customer{ string custname; ...
0
votes
1answer
41 views

How to create different structs through an array argument

I am trying to create different structs by passing the necessary components of the struct through an array in the arguments. So far, the compiler does not complain but when i execute the transaction, ...
0
votes
3answers
32 views

Get a blank address

I have a little problem with my code. I'm trying to follow who are the current sender and the previous sender of a transaction respectively with the variable currentSender and lastSender, and then ...
0
votes
1answer
41 views

Getter of mapping inside a struct

I wanted to create a getter function to access a mapping nested inside a struct. But the function that I made required me to use the expiremental version (I'm on Remix). So I used the expiremental ...
0
votes
0answers
69 views

Type struct Mycontract.User memory is not implicitly convertible to expected type struct Mycontract.User storage pointer

pragma solidity >=0.5.0 <0.7.0; contract Mycontract{ uint256 a; struct User { string name; } User[] users; function foo() public{ **User storage user=User("hey&...
0
votes
1answer
29 views

The below code gets compiled but when foo is called invalid opcode error is thrown

pragma solidity >=0.5.0 <0.7.0; contract Mycontract{ uint256 a; struct User { string name; } User[] users; function foo() public{ User storage user=users[0]; ...
0
votes
1answer
29 views

Passing structures between contracts with ABIEncoderV2 [closed]

Hello I am having problems passing accessing the structure Rental in my secound contract can some one help? contract RentalCompleting{ struct Rental { uint256 stratingDate; uint256 endingDate;...
0
votes
0answers
17 views

What is the maximum size of a struct?

Assuming gas and hard drive space are not an issue, if you had a struct containing arrays how much data could you actually put into those arrays before the struct reaches its maximum size? I am ...
0
votes
1answer
10 views

array.push replacing last value instead of adding to the array

I am attempting to keep a log of when a user does certain things but when a new log event is reached the second log is overwritten instead of adding a new one to the array I am unsure as to why when ...
0
votes
1answer
76 views

Adding Struct to Array - Invalid OpCode - Solidity 0.6

I've been wreaking my brain on this for a while, could use some help. Bottomline, the newProposal function throws an VM Exception while processing transaction: invalid opcode error. The puzzling thing ...
1
vote
1answer
141 views

using mappings inside structs

I'm trying to use a mapping inside a struct: struct PoolStruct { uint currentUserID; uint activeUserID; uint price; uint minimalReferrals; mapping(uint => address) poolUserList; ...
1
vote
0answers
43 views

how to display a struct inside mapping inside struct in solidity on react js frontend

I have a mapping of struct (mapping (address => struct)) inside another struct. I'm having issue in how to display the struct in the front end while using Reactjs.
0
votes
0answers
38 views

Type error, unit256 is not implicitly convertible to expected type struct

Using sol compiler 0.5.1 I am trying to fetch data from old smart contract's function called people, the smart contract is already deployed on the blockchain mapping(address => Person ) public ...
1
vote
0answers
21 views

Natspec Commenting Style for Structs

Is there specific way to explain the variables of a struct using the Natspec format? I do something like: struct XYZ{ uint x; //Explain what it does uint y; } Is it this the right way for ...
0
votes
2answers
219 views

Solidity 0.4.26 check if element already exists in array

How do I make it so this only adds an identifier to the dataArray if it doesn't exist already? pragma experimental ABIEncoderV2; contract structWithMapping{ struct Data{ string[] user; ...
0
votes
1answer
14 views

Populating struct throws error

Hi I am trying to run this code in remix. It deploys successfully but whenever I add a Customer using the addCustomer function, it shows this message "transact to MyContract.addCustomer pending ...". ...
0
votes
1answer
57 views

Accessing array within struct in a mapping using web3.js

I have created a struct patient as follows, and a mapping of uint->patient. struct patient { uint pId; string name; string phone; address payable owner; uint numRecords; uint[]...
1
vote
0answers
26 views

vyper no mappings allowed when adding a function to initialize a struct that has a map inside

Version Information vyper Version (output of vyper --version): 0.1.0b17+commit.eaa6754 OS: Debian GNU/Linux 10 (buster) Python Version - 3.6.2 Environment (output of pip freeze): asttokens==2.0.3 ...
0
votes
1answer
80 views

Ganache Storage

I am trying to push data to an address array within a struct array. There are no errors, however, when I check the storage of the array in my contract in Ganache, it remains empty. Is there something ...
0
votes
0answers
19 views

is there any possibility to read struct via interface from deployed contract?

the contract is deployed which has no view function for that particular struct, is there any way to read values via interface in another contract which I want to write and deploy ?
0
votes
1answer
26 views

Unknown Parameter to Push Values to Dynamic Struct Array

I am trying to use Web3.js to push values from my frontend to a dynamic struct array in my backend. However, I am receiving an error that I need to provide a parameter to my frontend: "Unhandled ...
0
votes
0answers
46 views

No transfer of ether

My Code below ( Following an Online Course, absolute beginner here ^_^) pragma solidity >=0.4.17 <0.7.0; contract CampaignFactory{ Campaign[] public deployedCampaigns; function ...
0
votes
1answer
23 views

Mapping multiple structs to a struct and call them

I have a question about how I should design my contract to achieve the following: I want to create products identifiers (can be struct or string) something like: "product#123abc". Then I want to map a ...
1
vote
0answers
15 views

How to save/read mappings within struct?

I am trying to create a mapping inside struct and then create a mapping of the struct. Take a look at below example: // ------------------------------------------------------------------------ ...
1
vote
1answer
58 views

TypeError: Member “editor” not found or not visible after argument-dependent lookup in struct PrivateSmartContract.BuildingRental storage ref

I want to store user's wallet address array as editor's address so i created struct with array like following pragma solidity >=0.4.0 <0.7.0; pragma experimental ABIEncoderV2; contract ...
1
vote
2answers
41 views

why is need of mapping if same work done by using array in struct?

I muddle up with mapping use with struct. this smart contract I used array instead of mapping pragma solidity ^0.6.*; contract MyContract{ //here we can not assume the length off array so need ...
1
vote
1answer
27 views

struct initialization

I want to know how to initialize the structure created using 'struct' key word. I can't see use of 'new' key word in Solidity documentation. Some body please guide me. Zulfi.
1
vote
1answer
24 views

During data insertion function pushes data only once

I wonder why data insertion in users occurs only once, while userCount updates correctly? pragma solidity >=0.4.22 <0.7.0; contract TestChainStorage { address private owner; uint256 public ...
0
votes
1answer
66 views

Updating a struct value in mapping

I am trying to update a value in a struct that is mapped. I tried updating a value in the smart contract, it asked me to confirm the transaction but when I check the value it doesn't seem to change ...
3
votes
1answer
117 views

Store date in base64 string inside contract

I started creating a solidity smart contract to serve almost as both BD and Backend service. Everything was ok until I got a warning saying my contract had too many bytes.. was too big (refering to ...
1
vote
1answer
44 views

Array and mapping are not pointing to the same struct

I am building a DApp game and I am experiencing a problem. Let me describe it. I have a struct: struct NPC { uint id; string name; uint level; } Then I have an array that stores all the ...
0
votes
1answer
28 views

how to do sales receipt

I have a marketplace. I wanted to make a sales receipt for each item sold. The sales receipt will indicate address_receipt,nameOfGood, amountOfGood,Price, sumPrice,address_transaction. What should I ...
0
votes
0answers
55 views

Parsing nested JSON into structs

I need to store the following JSON object in a struct. { "id":"ea6d69b3-f1", "type":"ofoo", "channel":"website", "funding":[ { "type":"xxx", "amount":"1", ...
4
votes
0answers
503 views

Stack too deep when compiling inline assembly

I'm running into a YulException: Stack too deep when compiling inline assembly: Variable headStart is 1 slot(s) too deep inside the stack. using a smart contract that has this function. I took this ...

1
2 3 4 5
7