Questions tagged [struct]

Question about the solidity Structs

Filter by
Sorted by
Tagged with
1
vote
1answer
23 views

Why is solidity asking me to restrict state modifier function to view?

Version 0.8.7 Solidity is complaining that several state modifier functions can be restricted to view, such as: function updateStruct( uint256 dummyParam ) public onlyOwner { DummyStruct ...
0
votes
1answer
25 views

Structs on inheritance

Can an inherited contract have access to his parent's struct variables? I'm trying the code from below but I can't access the struct defined on ContractA, so I don't know if it's not possible at all ...
0
votes
1answer
25 views

Solidity: How to inherit a struct to create a new struct?

Is there a way to inherit a previously defined struct while defining a new struct (similar to the classes in C++)? I'm looking for something like this: struct Person { bytes32 name; uint256 ...
0
votes
0answers
21 views

solidity struct unit test

I think I am not the only one who has this problem. I just want to get the names of the variables inside a struct along with typing them. I have a file that shows the structure of the item. But I do ...
0
votes
0answers
39 views

NFT data on database vs On-Chain/IPFS

First of all, I feel sorry because my doubt is more kind of philosophical, rather than technical. I'm developing an NFT based game, where items are ERC721 tokens, all of them with a different Index ID....
0
votes
1answer
14 views

Add new variable to defined struct

Is it possible to create a new variable/key -with its corresponding value- for an already defined Struct? Kind of like objects in JS. struct MyStruct { //defined elsewhere in SomeLib uint num; ...
0
votes
1answer
17 views

Is there a difference whether a struct is defined inside a contact or outside of it?

Both, struct Test { uint x; uint y; } contract A { Test test; } and contract A { struct Test { uint x; uint y; } Test test; } are valid ways to define a struct. Is there any ...
0
votes
1answer
21 views

One Mapping of Structs vs Multiple one variable mappings

I'm developing a contract to manage multiple NFTs. The contract is an instance of ERC721, which manages some common attributes for every NFT. Which could be the most efficient way to do it? Option 1: ...
0
votes
0answers
12 views

index on a struct

The veCRV token from Curve includes the following lines of code: point_history: public(Point[100000000000000000000000000000]) # epoch -> unsigned point user_point_history: public(HashMap[address, ...
0
votes
0answers
14 views

Any plans to allow mappings in public struct instances?

In a dApp I've created, I generate and store data in a compartmentalized way, generating a new Data object each period in the system (a period is one month. ) Ideally, it would be done like this: ...
0
votes
1answer
30 views

Procedure of transferring the ERC721 tokens in return for money between different accounts

I am using ERC721 in my script and have declared a method for transferring the tokens In return for a desired amount of money from the buyer. However, after sending the money by the buyer the ...
0
votes
0answers
6 views

How do you decode a struct? [duplicate]

How do you decode a struct that's inside a transaction data? How do you encode/decode structs in general to bytedata?
1
vote
1answer
19 views

Dynamic nesting - Mapping with Array of struct with a nested array of struct

I'm trying to write a dynamic nested struct but I’m not sure the pattern I'm following is right and cost-effective. It is just an practice example please ignore the string arguments which it can be ...
0
votes
1answer
47 views

How to create nested data structures Solidity 0.8

I'm a JS dev fairly new to solidity. I couldn't find something to cover this when dealing with custom data. I want to create a function that I can use to push data into the contract. I'm trying to get ...
0
votes
1answer
24 views

"Member not found or not visible" when trying to access individual struct members

I'm new to Solidity and coding in general and this code may be a disaster, but I'm learning. Basically, I'd like to get members of a struct with a function. I can return the entire struct in the form ...
1
vote
1answer
22 views

How do I initialise a dynamic array in a solidity struct for every newly created struct?

contract Foo { struct Bar { address owner; uint[] x; } mapping( uint => Bar) bars; function foobar(uint index) public { Bar memory b = bars[index]; ...
0
votes
1answer
38 views

Looping Through an Array in Solidity?

Having a difficult time with loops and arrays in Solidity. If i have a simple contract like below (no mapping, just a struct array), is it possible to loop through the array to get a particular ...
0
votes
1answer
21 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
76 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
947 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
50 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
39 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
33 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
52 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 ...
2
votes
1answer
209 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
61 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
10 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
17 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
103 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
726 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
34 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
80 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
16 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
21 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
29 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
33 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
21 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
98 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
147 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
22 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
269 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 ...
2
votes
1answer
476 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
16 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
33 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
286 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
36 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
68 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
2k 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
2 3 4 5
8