Questions tagged [struct]

Question about the solidity Structs

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

Structs and Mappings

I am going through a tutorial at the moment and have just covered the basics of mappings and structs which I feel like I understand. However, in the next section of the tute we put together mappings ...
0 votes
1 answer
23 views

How to properly format an argument that is a struct with nested structs, with web3.py?

I have the following ABI: { "inputs": [{ "components": [{ "internalType": "enum LibNFTOrder.TradeDirection", ...
0 votes
0 answers
11 views

Is storing two copies of a mapping of a struct cheaper than storing one copy and two mappings of integer?

I am working on a smart contract that stores transactions of complicated objects (a struct with 11 properties including strings, addresses, boolean, and uint256). I want each user to have access to ...
  • 13
1 vote
0 answers
19 views

How to send array of structs using Foundry cast

Smart contract struct NewPrice{ address asset; uint256 timestamp; uint256 price; } function updatePrices(NewPrice[] memory _array) public onlyRole(FEEDER_ROLE) { ...
  • 111
0 votes
0 answers
10 views

Can't run the getbook function in the below given code due to "Payable"error

''' pragma solidity >=0.1.0 <0.9.0; contract Day5 { constructor() payable { } struct Book { string title; string author; uint256 book_id; } Book[] types; uint count=1; function setBook(string ...
1 vote
1 answer
14 views

Declaratively creating an array of structs with one statement in Solidity

I want to create a modifier that accepts a dynamic array, like this: modifier parameterizedTest(Set[] memory sets) { // ... } Where the Set struct is defined like this: struct Set { uint256 x;...
1 vote
1 answer
23 views

Push opeartion not working

I am creating a To-Do list with the limitation that one address should only be able to add upto 100 notes. Below is the snippet of code //SPDX-License-Identifier: MIT pragma solidity ^0.8.16; contract ...
  • 21
0 votes
1 answer
22 views

Mapping structure before copying values

Below is the solidity code which add instructors :- pragma solidity ^0.4.18; contract Courses { struct Instructor { uint age; string fName; string lName; } ...
  • 21
0 votes
1 answer
16 views

'Expected Idenfitier but got Public'

// SPDX-License-Identifier: MIT pragma solidity ^0.8.16; Books[] public individual_book; struct Books { string author; string title; } function add_books( string _author, string _title)...
  • 1
0 votes
1 answer
29 views

Mapping/variable in struct. Which one is cheaper in terms of gas?

Considering the following different approaches: 1st approach struct Apartment { string apartmentAddress; string description; string image; } struct Reservation { Apartment apartment; uint32 ...
1 vote
2 answers
50 views

What is the right way to track a uint256 to struct mapping?

the smart contract below is a market place where users can sell items. The struct Offer, holds all the info of a specific item. To track the offers, I used a mapping with a uint256 key and created a ...
0 votes
1 answer
19 views

Mapping of a struct missing field

I have an interface. interface IAuction { struct Auctioneer { uint256 a; uint256 b; bool c; address d; uint256 e; uint256 f; string[] bids; ...
  • 1,154
1 vote
1 answer
54 views

Access nested struct mapping member

I have 2 structs like this : struct Wheel { uint radius; uint width; } struct Vehicle { string model; uint wheelCount; mapping(uint => Wheel) wheels; } uint public ...
1 vote
1 answer
52 views

How to store a uint[] memory inside a struct in solidity

I have the below code struct Ticket { uint256 id; uint256[] numbers; address payable owner; } function enter(uint256[] memory userNumbers) public { Ticket memory ...
  • 179
0 votes
0 answers
19 views

What is the location of a struct's second attribute in storage when the struct is the first element of a dynamically sized array of said structs?

If I have a contract whose first state variable (slot 0 in storage) is a dynamically-sized array of structs (testArray), for structs with 2 attributes defined (Test). I know that the position in ...
  • 33
0 votes
2 answers
45 views

How to Return an Array of structs from Solidity?

i'm having an issue when trying to return an array of structs from a getter function i've made. The smart contract is an ERC721 Staking Contract. This is the getter function: function getNftInfo(...
0 votes
3 answers
111 views

Method with struct not presented over Etherscan

In my smart contract I have some methods that get a struct as an input: contract MyContract { MyStruct { uint[] arr; address[] addresses; } function myFunction(MyStruct[] structs) ...
  • 543
0 votes
1 answer
297 views

ABI encode array of structs ethers.js

In Ethers.js, how do I encode an array of structs? The struct: struct FacetCut { address facetAddress; FacetCutAction action; //<--- enum bytes4[] functionSelectors; } Function's ...
  • 379
0 votes
2 answers
149 views

Can you unpack a tuple into a struct? And vice versa?

Let's say I have a struct: struct NetworkConfig { bool myBool; uint256 myNum; } And I have it saved as a variable as such: NetworkConfig public activeNetworkConfig; If I were ...
0 votes
1 answer
18 views

Store an array of structs inside another struct

I am working on a smart contract for a quiz application, Basically, I want everyone to be able to create a quiz and for everyone to be able to answer. I am struggling on saving a list of quizzes with ...
0 votes
1 answer
29 views

How to initialise a mapping of a structure inside a function?

I am having a struct which is having a map and I want to update the map dynamically... Code : struct task { string description; status taskStatus; address assignedTo; ...
  • 23
0 votes
1 answer
26 views

Clearing storage struct array with Solidity

We're implementing a Lottery where a player can buy multiple tickets. A ticket is defined with a struct and they are being kept in a storage struct[]: pragma solidity >=0.4.22 <0.9.0; contract ...
  • 103
1 vote
1 answer
320 views

Get Signature for Tuple input for EIP712 [duplicate]

I'm using web3.js to try and sign a tuple and get the signature. I'm utilizing draft-EIP712Upgradeable.sol in order to hash and recover the input in solidity. I originally looked at the following link ...
0 votes
1 answer
29 views

Can't access a struct from one contract in another contract through interfaces. Any help?

I am trying to use a struct defined in one contract in another with the ise of interfaces. But my test cases is giving an error, AssertionError: Expected transaction to be reverted with Amount cannot ...
0 votes
0 answers
8 views

I can only return the last struct that I transacted. How do i return all of the structs that have been sent on the blockchain from sender address?

//SPDX-License-Identifier: MIT pragma solidity ^0.6.8; pragma experimental ABIEncoderV2; contract INCUBE{ struct project { string universal_project_id; string project_title;...
0 votes
1 answer
164 views

How do I pass a struct as an argument in delegatecall to a proxy library?

I am trying to call the buyAssetsForEth function in the OpenSeaMarketV2 library using delegatecall as follows: pragma solidity 0.8.4; contract Owned { address public owner; constructor(...
0 votes
2 answers
55 views

Struct Not Updating Using Ethers

I have an array of struct Campaign. The function launch adds a new Campaign to the array. After that when a user sends some ETH using the pledge function, the transaction succeeds and the eth gets ...
0 votes
1 answer
227 views

How to push Struct with a mapping to an array?

I have a struct called Meeting that contains an array of addresses. I want to check that the address doesn't exist before it RSVPs to a meeting, so I created a mapping called hasRSVPed. (I could loop ...
0 votes
0 answers
64 views

How to save gas in solidity structs with packaging

I am trying to figure out how to package my structures to optimize them. This first structure takes full 3x256 bits. struct FirstStruct { uint128 numberOne; // takes one 256bit slot uint256 ...
  • 843
0 votes
1 answer
366 views

mapped struct storage layout (slots) and collsions

I want to establish a pattern that ensures no storage slot collisions between current and future (compliant) versions of a contract behind a transparent proxy. In particular, contracts that are meant ...
  • 52.5k
0 votes
0 answers
301 views

How to get struct arrays within structs in ethers?

My code: struct C { address addr; uint amount; } struct Item { uint a; uint b; C[] itemCs; int d; uint e; int f; uint g; } mapping(uint => Item) public ...
0 votes
1 answer
20 views

How can i create a mapping properly?

I would like to create a mapping with a struct inside as key struct MyMap { bytes32 data1; address data2; string data3; } mapping(MyMap => bool) public currentMap; but i am getting ...
  • 15
1 vote
1 answer
631 views

Encode a struct with solidity

Is it possible to encode a struct in Solidity without serializing each variable separately? Something like: struct MyStruct { uint x; uint y; } MyStruct storage myStruct = MyStruct({ x: 11, ...
  • 379
0 votes
1 answer
46 views

using struct with mapping in solidity

i am developing a locker smartcontract where user can lock their erc20 token. i have successfully develop the adding(lock) functionality but having difficulty developing the withdraw function. for ...
0 votes
1 answer
48 views

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

While writing a contract that uses structs, I'm getting an error by the linter "Struct containing a (nested) mapping cannot be constructed". According to this, the problem with structs is ...
  • 11
0 votes
0 answers
84 views

How to import struct members from Solidity Library

Trying to implement the diamond upgrade following Nick Mudge implementation in aave. Been getting this error (struct member not found or not visible after argument dependent lookup in struct) ...
0 votes
1 answer
195 views

Getter function to return a nested struct that contains mapping?

For example, struct SomeStruct { uint _someUint; uint _someUint2; mapping(address => uint) _someMapping; } A getter function for a non-nested struct could be ...
  • 47
0 votes
2 answers
42 views

Deleting values from a struct

how do i go about removing values from inside a struct and or a mapping. For example iam creating a smart contract that acts kind of like a vault, iam not yet finished but i have a create an account ...
0 votes
1 answer
13 views

I need help with balances

I would like to create a balance for each "vault". for example i will have my struct: struct unnamed { string[] crowdFundName; } I would like to add a balance to each vault for ...
0 votes
1 answer
100 views

Can a library have a `public` function using `struct memory`?

I can't find any up-to-dates (and clear enough for my level of understanding) responses to this question that has also been raised very recently on a hardhat issue, with no response to date (https://...
0 votes
1 answer
16 views

Returning structs from Chainlink oracle job

Is it possible to return struct from chainlink oracle job? I would like to return list of transactions from chainlink job to the contract. So far I've only seen examples where it's possible to return ...
  • 101
0 votes
1 answer
267 views

Array of structs inside a struct

Im trying to set a mapping to a struct that contains an array of structs inside. Like so: struct ParentTokenDetails{ TokenType _tokenType; address _tokenOwner; ChildTokenDetails[] children;...
0 votes
0 answers
37 views

struct array in a mapping updating

mapping(address => trnsctn[]) private transactionsOfAdress; struct trnsctn{ uint256 when; uint256 amount; } uint256 public ege; function deposit() public payable {...
  • 3
0 votes
1 answer
162 views

Efficient struct ordering for less gas

Unlike initializing state variables in specific orders in order to save on gas, does this also apply to how you declare your struct properties where you keep lower uints side by side each other? // ...
  • 103
1 vote
0 answers
26 views

The best option to share structs

What is the best and common option for sharing structs between contract? I can use for that Library, Interface or Contract and put there a Struct and then import it to another contract. But what is ...
0 votes
1 answer
71 views

Get data from mapping whose values are struct and keys as address (msg.sender)

Hey so this is my solidity code, when I am running the getter functions, I am not seeing any output. And as for a fact I don't even know whether the setter functions are even working or not. Please ...
0 votes
0 answers
18 views

Delete struct from array of structs

I've found a great answer to do things with an array of structs here but I am a bit confused about one particular example which is below: contract mappingWithStruct { struct EntityStruct { uint ...
  • 138
0 votes
1 answer
162 views

TypeChain says the struct array field does NOT exist in my Ballot struct, why?

I am trying to test my voting ballot contract using Hardhat/ethers/TypeChain, but for some reason, the Ballot struct's typescript interface is NOT showing the array of choices struct field I have ...
  • 1
0 votes
1 answer
90 views

Cheapest way to access and modify a struct

I am using solidity 0.8.10. In my contract I have a state variable struct: struct Product { uint id_prod; address payable producer_addr; address payable owner_addr; bool onSale; } ...
  • 113
0 votes
1 answer
393 views

How to override an interface function that returns a struct with a mapping

I have an interface with a public function foo that consumes a single address parameter and returns a Point struct: //SPDX-License-Identifier: MIT pragma solidity ^0.8.4; interface IFoo { struct ...

1
2 3 4 5
9