Questions tagged [struct]

Question about the solidity Structs

Filter by
Sorted by
Tagged with
0
votes
0answers
15 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
25 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]; ...
0
votes
1answer
24 views

Passing structures between contracts with ABIEncoderV2 [closed]

Hello I am having problems passing accessing the structure Rental in my secound contract can some one help? contract RentalCompleting{ struct Rental { uint256 stratingDate; uint256 endingDate;...
0
votes
0answers
16 views

What is the maximum size of a struct?

Assuming gas and hard drive space are not an issue, if you had a struct containing arrays how much data could you actually put into those arrays before the struct reaches its maximum size? I am ...
0
votes
1answer
9 views

array.push replacing last value instead of adding to the array

I am attempting to keep a log of when a user does certain things but when a new log event is reached the second log is overwritten instead of adding a new one to the array I am unsure as to why when ...
0
votes
1answer
19 views

Adding Struct to Array - Invalid OpCode - Solidity 0.6

I've been wreaking my brain on this for a while, could use some help. Bottomline, the newProposal function throws an VM Exception while processing transaction: invalid opcode error. The puzzling thing ...
1
vote
1answer
20 views

using mappings inside structs

I'm trying to use a mapping inside a struct: struct PoolStruct { uint currentUserID; uint activeUserID; uint price; uint minimalReferrals; mapping(uint => address) poolUserList; ...
1
vote
0answers
28 views

how to display a struct inside mapping inside struct in solidity on react js frontend

I have a mapping of struct (mapping (address => struct)) inside another struct. I'm having issue in how to display the struct in the front end while using Reactjs.
0
votes
0answers
21 views

Type error, unit256 is not implicitly convertible to expected type struct

Using sol compiler 0.5.1 I am trying to fetch data from old smart contract's function called people, the smart contract is already deployed on the blockchain mapping(address => Person ) public ...
1
vote
0answers
13 views

Natspec Commenting Style for Structs

Is there specific way to explain the variables of a struct using the Natspec format? I do something like: struct XYZ{ uint x; //Explain what it does uint y; } Is it this the right way for ...
0
votes
2answers
60 views

Solidity 0.4.26 check if element already exists in array

How do I make it so this only adds an identifier to the dataArray if it doesn't exist already? pragma experimental ABIEncoderV2; contract structWithMapping{ struct Data{ string[] user; ...
0
votes
1answer
14 views

Populating struct throws error

Hi I am trying to run this code in remix. It deploys successfully but whenever I add a Customer using the addCustomer function, it shows this message "transact to MyContract.addCustomer pending ...". ...
0
votes
1answer
32 views

Accessing array within struct in a mapping using web3.js

I have created a struct patient as follows, and a mapping of uint->patient. struct patient { uint pId; string name; string phone; address payable owner; uint numRecords; uint[]...
1
vote
0answers
13 views

vyper no mappings allowed when adding a function to initialize a struct that has a map inside

Version Information vyper Version (output of vyper --version): 0.1.0b17+commit.eaa6754 OS: Debian GNU/Linux 10 (buster) Python Version - 3.6.2 Environment (output of pip freeze): asttokens==2.0.3 ...
0
votes
1answer
27 views

Ganache Storage

I am trying to push data to an address array within a struct array. There are no errors, however, when I check the storage of the array in my contract in Ganache, it remains empty. Is there something ...
0
votes
0answers
15 views

is there any possibility to read struct via interface from deployed contract?

the contract is deployed which has no view function for that particular struct, is there any way to read values via interface in another contract which I want to write and deploy ?
0
votes
1answer
23 views

Unknown Parameter to Push Values to Dynamic Struct Array

I am trying to use Web3.js to push values from my frontend to a dynamic struct array in my backend. However, I am receiving an error that I need to provide a parameter to my frontend: "Unhandled ...
0
votes
0answers
45 views

No transfer of ether

My Code below ( Following an Online Course, absolute beginner here ^_^) pragma solidity >=0.4.17 <0.7.0; contract CampaignFactory{ Campaign[] public deployedCampaigns; function ...
0
votes
1answer
19 views

Mapping multiple structs to a struct and call them

I have a question about how I should design my contract to achieve the following: I want to create products identifiers (can be struct or string) something like: "product#123abc". Then I want to map a ...
0
votes
0answers
14 views

How to save/read mappings within struct?

I am trying to create a mapping inside struct and then create a mapping of the struct. Take a look at below example: // ------------------------------------------------------------------------ ...
1
vote
1answer
38 views

TypeError: Member “editor” not found or not visible after argument-dependent lookup in struct PrivateSmartContract.BuildingRental storage ref

I want to store user's wallet address array as editor's address so i created struct with array like following pragma solidity >=0.4.0 <0.7.0; pragma experimental ABIEncoderV2; contract ...
1
vote
2answers
36 views

why is need of mapping if same work done by using array in struct?

I muddle up with mapping use with struct. this smart contract I used array instead of mapping pragma solidity ^0.6.*; contract MyContract{ //here we can not assume the length off array so need ...
1
vote
1answer
24 views

struct initialization

I want to know how to initialize the structure created using 'struct' key word. I can't see use of 'new' key word in Solidity documentation. Some body please guide me. Zulfi.
1
vote
1answer
21 views

During data insertion function pushes data only once

I wonder why data insertion in users occurs only once, while userCount updates correctly? pragma solidity >=0.4.22 <0.7.0; contract TestChainStorage { address private owner; uint256 public ...
0
votes
1answer
35 views

Updating a struct value in mapping

I am trying to update a value in a struct that is mapped. I tried updating a value in the smart contract, it asked me to confirm the transaction but when I check the value it doesn't seem to change ...
3
votes
1answer
71 views

Store date in base64 string inside contract

I started creating a solidity smart contract to serve almost as both BD and Backend service. Everything was ok until I got a warning saying my contract had too many bytes.. was too big (refering to ...
1
vote
1answer
41 views

Array and mapping are not pointing to the same struct

I am building a DApp game and I am experiencing a problem. Let me describe it. I have a struct: struct NPC { uint id; string name; uint level; } Then I have an array that stores all the ...
0
votes
1answer
27 views

how to do sales receipt

I have a marketplace. I wanted to make a sales receipt for each item sold. The sales receipt will indicate address_receipt,nameOfGood, amountOfGood,Price, sumPrice,address_transaction. What should I ...
0
votes
0answers
33 views

Parsing nested JSON into structs

I need to store the following JSON object in a struct. { "id":"ea6d69b3-f1", "type":"ofoo", "channel":"website", "funding":[ { "type":"xxx", "amount":"1", ...
3
votes
0answers
208 views

Stack too deep when compiling inline assembly

I'm running into a YulException: Stack too deep when compiling inline assembly: Variable headStart is 1 slot(s) too deep inside the stack. using a smart contract that has this function. I took this ...
3
votes
2answers
112 views

Map or Array…?

I'm having a huge dilemma! I'm developping a smart contract that has, let's say Struct A and Struct B. Because I want to have a function retrieving all objects type A and B, I created a Struct All ...
2
votes
1answer
32 views

Whats the best way of translating this struct?

Let's say I must have this data structure: ├── Operations (struct) │ ├── date_begining (uint) │ └── date_end (uint) │ └── responsible (address) │ └── type **(?)** │ ├── Observation (...
1
vote
2answers
29 views

Returning an array of structs

Here is my code example: pragma solidity ^0.5.16; pragma experimental ABIEncoderV2; contract Operations { Operation[] public operations; struct Operation { uint startOperation; ...
0
votes
1answer
41 views

Is it possible to set a struct property as undefined or null?

In JavaScript we're able to have: Object { a: number; b?: string; c: number; d?: string; } b and d being optional, these can be left out during variable initialisation. Is this possible in ...
0
votes
0answers
47 views

Is there a graph data structure in solidity?

I am trying to achieve a file lineage information Dapp and I need a graph kind of data structure for that. I know I can always write one but is there a ready to use data structure that is efficient ...
0
votes
1answer
29 views

Cant Retrieve the values of Structure fields (i.e. text boxes) through Remix IDE

I am giving the values to structure field through Remix IDE, then I am putting ‘0’ as the index of people array, then I click transact and then I click call, but Remix does not show me the value I ...
0
votes
1answer
168 views

What is the differenc between Person and Account variables

What is the difference between Person and Account? struct Account { address addr ; uint balance ; } Account[ ] public accounts; function applyInterest () public returns ( uint ) { for ( ...
0
votes
1answer
28 views

Problem with understanding contract containing array of structure

I got the following code for a contract from a Solidity tutorial website: pragma solidity 0.5.1; contract MyContractPersonStruct { Person[] public people; uint256 public peopleCount; ...
0
votes
1answer
54 views

How to properly initialize nested storage array/struct?

contract Contract { struct A { int a; } struct B { A[] as; } mapping(address => B[]) bs; function addB(B memory b) { bs[msg.sender].push(...???...); } } I have nested hell of arrays and ...
0
votes
0answers
22 views

Accessing a storage array is causing my contract to revert with no explanation

I have the following contract: // Inspired by https://fravoll.github.io/solidity-patterns/eternal_storage.html pragma solidity ^0.5.8; import "./lib/Ownable.sol"; import "./MemberStruct.sol"; ...
0
votes
1answer
20 views

Can you have an array of mappings? The mappings have an address key and a struct value

Can you have an array of mappings? I want to have mappings with addresses as keys and structs as the value. I want to store these addresses in an array and iterate through them. so far it looks like ...
0
votes
1answer
36 views

Passing of a struct array from called contract to calling contract

I am currently developing a dAPP and I am splitting it in 2 distinct contracts. I will be calling functions from contract A to contract B. In contract B I have an array of struct which I can ...
1
vote
2answers
24 views

Remove empty space in a Struct

Once I do cancel some data from a struct, how do I remove the empty cells that I then create? Sorry for the silly question but I am just new :) Below you will see "function removeAppointment" where, ...
0
votes
1answer
40 views

Passing array of struct as parameter: Only libraries are allowed to use the mapping type in public or external functions

I am trying to push multiple items to the array of structs in the contract. Couldn't find a clear answer if it is possible to pass an array of struct as a parameter. Apparently I can't but I get a ...
0
votes
1answer
116 views

Size limit to number of items in a struct

If I loop over mapping into a struct the gas fee is very low. However, in trying to test its limits, the EVM often causes Remix to crash in creating edge cases, because I'm creating blocks of 50 new ...
0
votes
1answer
66 views

How to use array of arrays with mapping in Solidity

I'm developing a smart contract handling document signing. Mainly, there are two things to consider 1) Signers 2) Sign Types. 1) Signers: Mandatory sign the document 2) Types: Types of signs such as ...
1
vote
1answer
82 views

Accessing struct fields from assembly block

Say we have the following structure: struct MyStruct { uint256 x; uint256 y; } and that it is passed as an argument to some function. Inside that function, we have assembly block from where we ...
0
votes
1answer
21 views

Deleting vs. Assigning to Default Values

If I have a struct with many customer accounts: bytes32[] public customerID; mapping(bytes32 => CustomerAccounts) public customerAccounts; struct CustomerAccounts{ address customer; uint ...
1
vote
1answer
51 views

Add Number to Item in all Struct Members

I have a struct where I want to increment an item across all struct members. For example, say there is a struct 'Contract', and new customers get their own bytes32 ID, which points to their own struct:...
0
votes
1answer
58 views

Stack too deep problem

I try to add more property to the scenario struct but when I run the compile the same error appear: struct Scenario { uint id; address payable author; address editor; ...

1
2 3 4 5 6