People who code: we want your input. Take the Survey

Questions tagged [struct]

Question about the solidity Structs

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

Returning struct arrays in solidity

I am currently writing a smart contract using Solidity in version 0.8.4 and I want to return a (dynamic) array or structs (comprising several strings each). Now in remix, this seems to work just fine ...
0
votes
1answer
23 views

Why a struct member is not visible to my function?

The very last function of the code makeBet() is throwing an error when I want to deploy it on Remix. The error says that member status is not found or not visible when calling Game.status. That is ...
0
votes
0answers
21 views

solidity: Loop through array of struct -> only looping to first array member

I'm using a struct to hold invoice data. After the invoice data has been submitted, i want to execute some code for the invoices that aren't due. My current code is this: contract mycontract { ...
0
votes
0answers
10 views

Structs, Memory, and data storage for smart contracts (General questions inside)

I seem to be having a fundamental misunderstanding here about how storage and memory relate to each other. I originally tried having the structs store their posts in dynamic arrays of structs inside ...
1
vote
0answers
11 views

Function argument sizes and gas usage

Is there any penalty for the amount of data passed to a function? Asking because I see non-linear behavior in gas usage during testing when sending more than 31 items in the array. struct Payment { ...
1
vote
0answers
9 views

Alias for external library type?

Say you're importing a library, and that library contains a struct: pragma solidity >=0.8.0; library SomeLibrary { struct FooType { uint256 value; } } contract SomeContract { ....
4
votes
0answers
20 views

How do I initialize an array of Structs

I would like to initialize an array of structs: struct person { string firstName; string lastName; } person[3] family = [ person("Will", "Smith"), person("Jada", &...
0
votes
0answers
8 views

Type struct storage Election.Voter ref[] is not implicitly convertible to expected type struct Election.Voter memory

I am creating an Election contract and want to get a list of voters but facing this issue inside of for loop in getVoterInfo function on compiling. Type struct storage Election.Voter ref[] is not ...
2
votes
1answer
23 views

“generic object” data type in solidity

Is there a data type similar to "object" in C# that any solidity data type could rely on? I currently have a struct with multiple fields and I would need one of them to be either a string, a ...
0
votes
1answer
24 views

Member “Address” not found or not visible after argument-dependent lookup in tuple(address,int16,int8,uint256,bool,int256,address)

I am new to programming and trying to access a struct located in another smart contract but am receiving the following error. "TypeError: Member "Address" not found or not visible ...
0
votes
0answers
13 views

Check if a mapped value for a struct exists

I have the following in my contract: struct familyMember { bool isParent; string name; uint balance; bool active; uint spendLimit; address accountNumber;...
0
votes
1answer
33 views

What are the truffle console commands to interact with a mapping function of struct

Im writing a simple smart contract to store and retrieve data of series of patients' name and blood group with an id using mapping function in solidity. I don't know the commands to interact with the ...
0
votes
1answer
19 views

array vs mapping in solidity: when to use one over the other?

When should you use array or mapping in solidity? Let's say I have multiple question questionnaire, with one question, and I want to store the responses of different people(address) in a smart ...
0
votes
0answers
13 views

Mapping with different datatypes showing on one struct

is it possible that in I can use a uint and a address that showing on the same struct(Submission) as mapping ? I need something what makes it easy to read out the mapping with a uint (number) and 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
99 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
32 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
41 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
482 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
44 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
16 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
28 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
30 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
19 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
46 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
160 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
36 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
30 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
56 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
23 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
23 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
30 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
225 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
32 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
50 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
46 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 ...
7
votes
5answers
2k 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
438 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
331 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
44 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
37 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
46 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 ...
2
votes
1answer
336 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]; ...

1
2 3 4 5
7