Questions tagged [struct]

Question about the solidity Structs

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

Why is array.length giving "length" not found or not visible after argument-dependent lookup in mapping?

Here's how I defined an array of my struct: struct FoodItem { string name; uint price; bool available; } mapping(uint => FoodItem) public foods; Now I want to delete an ...
0
votes
1answer
14 views

How does Solidity decode a struct returned from a delegate call?

I have a proxy contract that delegate calls to a target contract. The proxy is similar to DSProxy. In it, there is an execute function: function execute(address target, bytes memory data) external ...
1
vote
1answer
148 views

Error encoding arguments: invalid BigNumber string after deploying to Remix

I wanna create a system allowing a company to save several data in the contract, and at the same time many companies can save data in this system. So I create the mapping of struct, and there's array ...
0
votes
1answer
19 views

Access struct of other contract via interface

I am trying to access the struct of another contract via an interface. I am having two different contracts that I want to deploy on the chain: Contract: contract cat { uint id = 0; mappung(...
1
vote
1answer
27 views

Reverse engineering an Event from its ABI

I'm trying to reverse engineer a smart contract interface from its ABI but I'm stuck with this event definition (the struct in particular). Does anyone know how that event would look like in solidity? ...
0
votes
1answer
20 views

Store a struct to multiple data structures

I have a contract which acts as an auction house. Each Auction is a struct. Therefore, each time a user wants to sell an item, a new Auction struct is created in storage. This wouldn't be a problem if ...
0
votes
1answer
23 views

Access Tuple of one contract from another

I have been having problems when wanting to access information from a contract that returns it through a view function. This information is a tuple generated from a struct. The contract code that ...
1
vote
1answer
33 views

How to return an array of structs that has mappings nested within them?

This is the code. And I want to return the Requests array. pragma solidity >=0.8.4; contract Contract { struct Requests { string description; uint value; address ...
0
votes
1answer
20 views

Howto use encodeFunctionCall with nested, array or non-string parameters?

Web3.js has a method named encodefunctioncall with the following signature: encodeFunctionCall(abiItem: AbiItem, params: string[]): string; The first parameter is ABI interface of that function and ...
0
votes
0answers
8 views

Moving parameter outside of the function call

I have the below Role struct in the Roles library: library Roles { struct Role { mapping (address => bool) bearer; } I also have a hasRole function in the same library that takes a ...
0
votes
1answer
14 views

wrapping state variables in struct

I asked this question in OZ forum and I'm asking it here again. The question is Why a state variable is wrapped in a struct in their Counters library. Please see the question in that post. Thanks.
0
votes
1answer
62 views

Struct on delegatecall

Is it possible to pass a struct as an argument to delegatecall ? I have this function that calls delegatecall and takes a struct (a 0x quote) as an argument which is later used on the function ...
0
votes
1answer
274 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
29 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
1answer
37 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
12 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
14 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
19 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
27 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
16 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
56 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
69 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
17 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
133 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
129 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
14 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
18 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
27 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
227 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
34 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
52 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
1k 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
49 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
54 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
18 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
32 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
33 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
21 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
59 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
259 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
67 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
31 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
129 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
27 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
79 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
53 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
379 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
35 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 ...

1
2 3 4 5
7