Questions tagged [struct]
Question about the solidity Structs
491
questions
2
votes
2
answers
43
views
Solidity automatically generated getter function returning tuple instead of struct
// SPDX-License-Identifier: MIT
pragma solidity =0.8.22;
contract A {
struct User {
string name;
uint age;
}
mapping(uint => User) public users;
function getUser(...
1
vote
0
answers
39
views
Decoding Result Struct from tryAggregate3 Multicall3 with web3.py
Hello Ethereum StackExchange community,
I'm currently working with the Multicall3 contract's tryAggregate3 function which returns an array of Result structs with the following format:
struct Result {
...
2
votes
1
answer
20
views
Has Solidity Introduced Storage Optimization for Smaller Integer Types in Structs?
I am working on a project where storage efficiency is of utmost importance. Specifically, I have a scenario where I want to store an ID of type uint16 and a code of type uint8. The current plan is to ...
0
votes
0
answers
21
views
how to get a function's signature that have a structre as parametter
function createClone(
uint256 dbId,
launchpadLib.IDOInfo memory _idoInfo,
launchpadLib.IDOInfoTwo memory _IDOInfoTwo
) external{}
I have this funtion how can i make signature of this function with ...
0
votes
0
answers
23
views
creation of PairFlash errored: Error encoding arguments: Error: types/values length mismatch (count={"types":5,"values":11
Getting this error when attempting to deploy a contract that reads in three addresses and two tuples
creation of PairFlash errored: Error encoding arguments: Error: types/values length mismatch (count=...
2
votes
1
answer
53
views
Possible way to hack Solidity into executing a function directly from a struct as a method? (v0.8.20)
pragma solidity 0.8.20;
contract SolidityLimitTest {
mapping (address => Hack) private Hackable;
struct Hack {
uint amount;
function(uint) returns (uint) ten_x;
}
...
1
vote
0
answers
10
views
Struct string not saving to storage from mapping
Good morning guys,
I would like to get some help with some declaration that I am doing in my solidity contract, basically I want to have some data on my registry from a user, such as if it is admin, ...
1
vote
1
answer
19
views
How to create a hash based on struct array types?
I have the following arguments to call a function in a smart contract:
ERC20Reward[] calldata _erc20Rewards
ERC721Reward[] calldata _erc721Rewards
ERC1155Reward[] calldata _erc1155Rewards
...
1
vote
1
answer
41
views
How to handle calls to mapping of big structs
Good day y'all, i'm tying to write a contract which is supposed to interact with another one that has a big struct that i need to retrieve to do some calculation, the struct have 14 properties and it ...
0
votes
1
answer
20
views
How do i initialize an array inside of a struct
I have a struct (Activity) where one of the arguments is an array of int. What i want to do is to initialize the struct and set the routinesID argument as an array like i did in the createActivity ...
0
votes
0
answers
19
views
web3.eth.abi.decodeLog not finding an event argument
I have a complicated event with the following signature:
event SwappedShares(uint256 _stable, DataTypes.FeeReturn _fees, address _user, DataTypes.SubPoolGroup[] _subPoolGroups);
Here are the ...
0
votes
1
answer
30
views
How can I add array of addresses inside my struct. Please See the code below and help me
Can anyone please update the listUser Function or make a new function to update the address of the User of type struct UserAddress.
Push it in the array in the struct User.
// SPDX-License-Identifier: ...
0
votes
1
answer
149
views
Best practices for putting structs in interfaces
I have a struct
struct Person {
string firstName;
string lastName;
uint8 age;
uint256 favNumber;
}
I have a function that returns a Person struct from an array
Person[] private ...
0
votes
1
answer
192
views
Abi calldata encoding nested structs, find a way
I didn't found any instructions about nested structs (in structs).
Seen video about sending bytecode to contract and I wanted to understand.
For example, method is:
function fulfillOrder(
Order ...
0
votes
1
answer
35
views
Brownie not returning Mapping Values
Good day to everyone, I've been working with brownie for sometime now and have been running into a lot of challenges. I created a struct basically and a mapping to that struct, however when I deploy ...
0
votes
1
answer
219
views
Encoding ENUM data type in struct for EIP712
I have a struct.
struct Order {
uint256 price;
uint256 quantity;
OrderType orderType;
}
enum OrderType {
BUY,
SELL
}
Question is, how should I ...
0
votes
1
answer
19
views
Why we can't initial a public mapping in a struct?
contract MyContract {
struct Balance {
uint numDeposit;
mapping(address=> uint) public Deposit; //It will give an error due the public keyword
uint numWithdraw;
...
1
vote
1
answer
1k
views
Error encoding arguments: Error: types/values length mismatch (count={"types":1,"values":3}
Can you please explain me why it's happening and how I can solve it ?
Error:
call to GameItem.storeWalletAddress errored: Error encoding arguments: Error: types/values length mismatch (count={"...
0
votes
1
answer
26
views
New to solidity. Help: UnimplementedFeatureError: Copying of type struct TransactionContract.Product memory[] memory to storage not yet supported
I have here a solidity program that I am trying to make, it should store the transaction to the blockchain, this transaction contains, id, date, buyer, seller, ORnumber, a multiple products with their ...
1
vote
1
answer
21
views
Dynamic update of struct field inside mapping
I have a struct
struct Shots{
uint coverDrive;
uint straightDrive;
uint pull;
uint squareCut;
}
and I used a mapping
mapping(address => Shots) public BattingSkill;
Now I want to ...
3
votes
0
answers
163
views
Can't Access Properties Off of Struct In Foundry / Forge: Possibly Due to Nested Mapping
I am unable to get attributes off a struct in my contract from my Foundry test file. How can I get a property off an instance of a struct in my contract from my Foundry test file.
In DAO.sol contract (...
1
vote
1
answer
120
views
What is the problem with structs having just arrays as its members?
I'm getting this error
TypeError: The struct has all its members omitted, therefore the getter cannot return any values.
--> Test.sol:11:5
for the following smart contract code:
// SPDX-License-...
0
votes
1
answer
16
views
Array of structures
How to store the returned array of structs from a contract to some other contract?
Like for eg. I have a doctor contract that has the function as :
function getRegisteredDoctors() public view returns(...
0
votes
1
answer
27
views
How can i call an already deployed contract with struct as parameters from a new contract?
I want to call some function in a contract B from a contract A. In my contract B I have some function who's signature is function execute(ExecutionInfo[] calldata executionInfos) where ExecutionInfo ...
0
votes
1
answer
16
views
Variable Values do not persist in between function calls
I am new to Solidity, and I am experimenting on smart contracts using Remix-IDE connected to a deployed local Geth instance.
What I am trying to do is to create a struct containing multiple fields for ...
1
vote
0
answers
39
views
What's the benefit of encapsulating storage slots as structs?
Often times you'll see the following pattern for reading and writing to storage slots:
struct Slot {
address value;
}
...
function getSlot(bytes32 slot) returns (Slot storage s) {
assembly { s....
0
votes
2
answers
80
views
Update struct variable based on the other variable from same struct
I'm trying to create a contract with a struct (Category) containing an array of another structs (Item). Item struct has a boolean variable minted with a default value of false. I'd like to change that ...
0
votes
1
answer
107
views
Error When Passing Struct as Input to Function in Solidity
I'm trying to just call a function that has a struct argument...The thing is that Remix somehow doesn't recognize all the inputs from the struct in the function.
I tried making the image very ...
3
votes
1
answer
476
views
How to parse event args: struct of custom internalType
Question: How does one parse the contents of a custom struct emitted as an indexed parameter with a contract event? Or, is it even possible to emit and then parse a custom struct from the event args?
...
1
vote
2
answers
145
views
Convert Custom Struct to Uint in solidty
I'm unable to convert Uint/bytes32 back to my struct Jury
Here is the struct im trying to convert to bytes32.
struct Jury {
address userAddress; //20 bytes
uint16 credibilityScore; //2 bytes
...
0
votes
3
answers
34
views
Unable to push structure in an array dynamically
I have a election contract as follows:
contract election{
struct Candidate{
uint id_db;
string name;
string party;
string election_sign;
...
0
votes
0
answers
35
views
How to compare two values of structs of the same msg.sender from different mappings
I'm having a Smart Contract contest among friends about who loses the most weight. Each competitor is expected to enter its weight at the beginning of the week and at the end of the week. The ...
2
votes
1
answer
87
views
Struct returns indexed numbers and property names
I'm using ethers and hardhat to run my React application. I want to pass an object as a parameter to a Solidity function. The function should map the object (struct) to the id provided as a property ...
0
votes
1
answer
264
views
Retreive a mapping nested inside a struct from Ethers
Hello Ethereum community,
I have couple of structs in my solidity code to organize things. Here is one struct from the code:
struct Staking {
uint total;
uint currentIndex;
mapping(address => ...
0
votes
0
answers
47
views
Best approach for modifying/implementing structures on Upgradable Smart Contracts
I am developing a project that is heavily reliant on the ability to upgrade smart contracts. However, I am not sure of the best way of handling structures in such contracts.
Trivial Example: (Imagine ...
2
votes
1
answer
29
views
Initializing Stuct
I would like to know if it is considered good practice initializing a struct when instantiating it or if it is just equally good to initialize its content right after instantiating it.
In other words, ...
0
votes
1
answer
89
views
How to call another function in solidity that has a struct for a parameter of over 16 variables?
Let's say I have the following code:
// This is in a separate imported interface.
interface MyInterface{
struct MyStruct {
uint256 one;
uint256 two;
// . . .
uint256 sixteen;
}
}
/...
1
vote
1
answer
18
views
What are the advantages/disatvantages to specify a struct param in a function as calldata vs. memory?
If I am not modifying the input parameter in the function body are there any reasons a reference type parameter should be labeled as stored in memory?
More generally what are the reasons to go for ...
2
votes
1
answer
94
views
Dynamic array inside a struct in solidity
contract EventContract {
struct Event {
address organiser;
uint price;
uint totalTickets;
uint ticketsAvailable;
uint startDate;
uint endDate;
...
1
vote
1
answer
79
views
How to return an array of structs from one contract to another contract in solidity
I am creating a Course contract which contains some details about the course hosted...
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Course{
string courseName;
uint256 ...
1
vote
2
answers
243
views
Define a struct in library vs in the contract
I have a struct defined in a library (to call it from different contracts):
library DataTypes {
struct Test{
uint256 a;
uint256 b;
}
when i want to initialize it or update in my ...
1
vote
1
answer
66
views
Unable to reach storage struct via mapping
Gm,
I've got a smart contract for 2D board game purposes. There is a struct Unit
struct Unit
{
UnitType unitType;
uint16 x;
uint16 y;
int8 hp;
int8 dmg;
...
0
votes
2
answers
28
views
Updating a struct property in an array stored as mapping value
This is my data structure for storing a list of questions which will be different for every address
struct Question{
uint16 id;
string question_string;
string answer;
}
and this is stored ...
0
votes
1
answer
83
views
Testing Struct Data
I have a struct and getter function that should return the id to zero when I delete it from my function but I dont know on how to return from my testing script
Here is my struct, mapping & ...
0
votes
2
answers
71
views
Is this the right way to assign values to struct array with mapping?
struct userdata
{
string task;
bool isdone;
}
userdata[] public userinfo;
address public user;
// mapping (uint[]=>string) public tasksno;
mapping (address=>userdata[]) ...
0
votes
2
answers
41
views
Return an array of structs for a specific condition
I would like to know if it is possible to create a function that would return an array of structs for a specific condition. Let's consider this for the following contract:
// SPDX-License-Identifier: ...
0
votes
1
answer
247
views
Mint and Create a Struct give me give me error "Stack too deep try removing local variables"
I have an issue with my code, I want to create a function to be able to Mint a token, and add a struct to represent all attributes of this token.
The issue is, I have lot's of args on my function (8) ...
3
votes
2
answers
382
views
Do the tight variable packing rules apply to arrays in structs?
Tight variable packing is a known coding pattern in Solidity for saving gas by placing variables that are lower than 256 bits closer to one another in structs.
For instance, the following will cost ...
0
votes
1
answer
205
views
Operator == Not compatible with types address[] storage ref and address
I have a mapping which maps uniqueids to an array of structs called Listing:
mapping(uint256 => Market.Listing[]) private _listings;
// the struct in the Market.sol
struct Listing {
address[] ...
0
votes
0
answers
47
views
Mapping or Struct to store data in NFT : gas fee and best practice
What is the best practice and gas less to store data inside the nft, not in metadata.
First exemple with 3 writes and second with 1 write.
But it seems Struct is more expensive. And when it will be ...