Questions tagged [struct]

Question about the solidity Structs

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

How to add data to an array inside a struct?

I have made a struct which contains an array . Now when I am adding data to the struct, I'm not able to add data to the array . struct User { uint256 limit; // spending limit uint256 ...
1
vote
1answer
24 views

Reading out single elements from a struct of an other contract

here a shortcut from my both contracts. Is it possible to read out and change single elements(from contract B) of the struct (Contract A) ? e.g. from contract B like p.submission(_id).studentaddress ? ...
1
vote
0answers
22 views

Encode nested structs using web3

I'm using Solidity 0.8.0 (so I'm using ABIEncoderV2) and web3.js 1.3.4 and I'm trying to call a contract's method passing a nested struct. erc1155.methods.safeBatchTransferFrom( owner, ...
0
votes
0answers
7 views

array of struct inside struct - require

Given two structures, struct travel { string name; uint USN; } struct class { uint classID; string ProfessorName; student[] students; } mapping(uint => class) selectedClass; A ...
1
vote
0answers
31 views

Saving String Memory Argument to Struct Array

I have the following Solidity code that compiles and tests okay, but the insurancePlan property of the Patient struct is not being saved. I've tried many variations and it is just blank (empty) when I ...
1
vote
1answer
20 views

Member “” not found or not visible after argument dependent lookup line 45

i am trying to create e platform which people can contribute in answering questions by sending funds with specific answer to a question: group A or B, can anyone help me why am i getting this error? ...
1
vote
1answer
89 views

How to use Web3j call Multicall Contract?

I need to use Multi Call contract to merge multiple calls,Its address on the mainnet is 0x2cc8688C5f75E365aaEEb4ea8D6a480405A48D2A contract Multicall { struct Call { address target; bytes ...
1
vote
1answer
39 views

Problem with passing an argument for a Structure

I am trying to compile the following program. I have declared a structure and I am passing a variable of it in a function in order to assign it to an array of structure. pragma solidity ^0.5.1; ...
1
vote
2answers
34 views

Is it possible to create a mapping where the keys are an existing array?

I'm trying to create a mapping whit this structure: mapping(string => House) public houses; where House is a Struct: struct House { address payable owner; uint256 base_price; } I ...
0
votes
0answers
15 views

How can I store structure items in a variable

I am learning to code in solidity and stuck with view functions. I am trying to return values taken dynamically in a structure using view function. Is there a way to do it is solidity? I tried it but ...
1
vote
0answers
24 views

Solidity. Pushing a struct to an array. But that struct contains an array. Copying of type struct memory[] memory to storage not yet supported

Here is my code. I need to have a "checkpoint" object that stores some information including an array of "delegations" which is another object. struct delegation{ uint256 ...
0
votes
0answers
28 views

Get struct from mapping that include another mapping

I have an already deployed contract with a mapping that looks this way: struct Details { address a; address b; } struct Params { uint a; uint b; //..... uint n; mapping(address =&...
0
votes
0answers
18 views

VM Exception when accessing mapping

I created a contract with a User struct than contains an age, a first name, and a last name. The function getUser() should return this information for an inputted address. But when I call my getUser() ...
0
votes
1answer
41 views

How to initialize a mapping of structs with a mappings?

I have a mapping of a struct, which has a mapping to another struct: uint256 public questionIdCounter; mapping(uint256 => Question) public questions; struct Question { uint256 ...
0
votes
0answers
13 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
90 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
25 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
29 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
40 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
19 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
29 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
126 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
31 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
19 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
16 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
39 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
31 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 ...
3
votes
4answers
1k 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
284 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
158 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
42 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
36 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
44 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
200 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
24 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
133 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
514 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
50 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
57 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 ...
2
votes
0answers
34 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 ...
1
vote
2answers
525 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
15 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
108 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
31 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
115 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
33 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 ?

1
2 3 4 5
7