Questions tagged [mapping]

A type in solidity that allows access to arbitrary elements via a key, similar to a dictionary or hashmap in other languages.

Filter by
Sorted by
Tagged with
0
votes
2answers
29 views

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

My version of solc: "solc": "^0.7.1", When I try to construct a struct that contains mapping, I got this error: "Struct containing a (nested) mapping cannot be constructed&...
1
vote
0answers
32 views

Huge gas cost for deleting an element of a map

As you can see with the code below the last person to call claimAuction cleans up the AuctionProposal but has to pay 383729 gas instead of 73846 for that cleanup, a 519% increase! My question is ...
0
votes
1answer
28 views

Create map of existing objects in mint function for a smart contract

I'm really new to solidity and there is still alot I dont fully get. I have created this smart contract. I am getting an error while performing a test stating that the id to be set by the push cant be ...
0
votes
3answers
30 views

Get a blank address

I have a little problem with my code. I'm trying to follow who are the current sender and the previous sender of a transaction respectively with the variable currentSender and lastSender, and then ...
0
votes
1answer
34 views

Getter of mapping inside a struct

I wanted to create a getter function to access a mapping nested inside a struct. But the function that I made required me to use the expiremental version (I'm on Remix). So I used the expiremental ...
1
vote
1answer
38 views

Finding values within an Array/Mapping based off min and max values

I want a user to be able to place a bet on some number, between a range of numbers. So the user wants to place a bet on the numbers 50-500. Then there is a function that sees if the number has been ...
0
votes
0answers
11 views

Raise & return error with message if no key found in mapping

I am writing a test that should fail because it looks for a key that doesn't exist on a mapping. How can I raise the error with and error message in solidity? this is the test: it('Should NOT update ...
1
vote
1answer
19 views

Array of mapping

I would like an array of mappings, is this possible? mapping (address >= value) sentValue; sentValue[] public sentValues; I want to record amounts sent by address, and I want each send event to ...
1
vote
0answers
26 views

How to update multiple values in a mapping without a loop?

if you have a mapping like: mapping (uint => bool) owned; How would you go through and update 1000 items in that mapping to set them all to true? Without using a loop due to gas prices. Is there a ...
1
vote
1answer
36 views

Mapping vs Arrays: duplicating variables gas consumption

I have a contract that has a struct including address and unit, and mapping of a struct, like this. struct User { uint count; address userAddress; } mapping (address => User) users; ...
0
votes
1answer
20 views

When using mapping, why use an address over bytes32?

From an end user standpoint, they will never want to use the address for searching for mapped data when they could just submit a username for function parameters, so is there any specific reason why ...
0
votes
1answer
16 views

Solidity get() function only returning one string when i ask for all strings in mapping

Can anyone tell why my get() function only returns the string "name" in Remix? I'd like it to return all the values within the users mapping like i've defined, can you help me accomplish ...
1
vote
1answer
27 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; ...
0
votes
0answers
32 views

Storing data directly on chain

Im trying to store data directly on the blockchain, not on a smartcountract as they have a limit of what they can handle and it would slow down the chain to go above the limit. My initial plan is to ...
1
vote
0answers
31 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
1answer
38 views

Mapping didn't storing unique values

I wrote this piece of code with the goal to store unique documents hash. Used mapping to accomplished that. pragma solidity ^0.5.16; contract DocumentHash{ string public documentHash; ...
0
votes
2answers
69 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
16 views

Read and write private variable from child contract

I have a contract MyContract is ERC721. MyContract needs to concatenate a string with an existing token URI using this function: string(abi.encodePacked(_tokenURIs[_tokenId], _URI)); Problem is all ...
0
votes
1answer
42 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[]...
0
votes
1answer
61 views

Check if user exists using mapping in solidity

I use solidity to store users information so before that i want to check if the user id already exist or no, Can any one help me with this code ? i see some solution using array or require all ...
1
vote
0answers
16 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
24 views

Delete mapping within a mapping

I have a mapping with the following structure: mapping(uint256 => mapping(address => SOME_STRUCT)) public submissions; delete submissions[uint256] is not allowed(compiler error). delete ...
0
votes
1answer
271 views

How to access data stored in Ethereum Blockchain using Smart contract?

I want to write solidity contract which stores hash table as mapping(uint => string) documents data structure in ethereum blockchain. Now, each time I run a function "storeDocument" in this contract,...
0
votes
1answer
21 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: // ------------------------------------------------------------------------ ...
0
votes
1answer
15 views

Adding modifier for mappings

can I add a modifier (for ex: onlyOwner) to a mapping? only I must see the value of mapping's key by myself(onlyowner). For example: mapping (address => bool) onlyOwner getAddress; Thank you.
1
vote
1answer
40 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
38 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 ...
0
votes
1answer
41 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 ...
1
vote
2answers
96 views

Can the mapping storage change after contract deployment?

I am beginner in mapping.I work on Truffle and Ganache. I deploy the following contract: pragma solidity ^0.5.12; contract customerFinder{ mapping(uint256 => address payable) public ...
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
35 views

wallet of goods [closed]

I sell goods for tokens. And I would like to make a wallet of goods for each user. So that he sees the amount of each product that he bought. Can I realize this in solidity? For example: through ...
3
votes
2answers
114 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 ...
0
votes
1answer
83 views

Read and write products using solidity

I am new to Solidity, trying to store a product in the purchaser wallet and retrieve the information from the owner wallet. I have some ideas but didn't know which one will be best. To store an ...
1
vote
1answer
68 views

Why does not Ethereum allow removing all entries from a mapping, like clear() in Python

Is it common that dictionaries like mapping(uint => uint) foo; cannot be cleared with something like clear()? What is the reason deleting mappings aren't allowed in Ethereum?
2
votes
1answer
27 views

How to check if a mapping has not been written yet?

I have this mapping: mapping (uint256 => string ) private storedData; I am trying to do this: modifier dataNotStored(uint256 _index) { require( keccak256(abi.encodePacked(storedData[...
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
0answers
133 views

Efficient way to save and retrieve hash in blockchain

I am learning Ethereum using Geth. I have a private blockchain and I am saving hashes through a REST API (python web service). I have readed I can save hash values using maps (mapping data type) and ...
0
votes
0answers
33 views

How to check if key exists in array of bytes? [duplicate]

I have an array of bytes10 inside a mapping, like this: mapping(uint => bytes10[]) public Players; I want to check if a certain index exists in the bytes10 array. I tried to check it with ....
0
votes
1answer
50 views

How to get a nested map value from web3.js?

In contract: mapping (address => mapping (address => uint256)) public spentLimit; How to retrieve spentLimit[a][b] for given a and b from web3.js?
1
vote
1answer
197 views

Storing multiple values in one key mapping (Solidity)

Can I store multiple values in one key mapping in solidity? like I can retrieve all of the values if I use that one mapping key? Is this possible?
1
vote
1answer
24 views

arrays and structs for function arguments

A lot of contracts and libraries with functions that use arrays and structs for arguments. Structs can themselves include arrays, structs and mappings. For example: function doSomething(MyStruct ...
0
votes
1answer
22 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 ...
0
votes
1answer
45 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
70 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 ...
2
votes
2answers
55 views

loop though all the members of a map

I need to loop though all of the members of a map and change their property (which is a struct). the way i'm doing this is when adding a member to the map object also save it's address inside an ...
1
vote
2answers
73 views

Why can't I map string with address in solidity?

I want to map names(string) with a wallet address in solidity but solidity throws an error saying that its not allowed! mapping(string => address) public users; And this is the error I get: ...
0
votes
1answer
34 views

Need to enumerate keys of a mapping [duplicate]

I have a directed multigraph of courts "trusting" each other: struct TrustedCourt { uint256 courtId; mapping (uint256 => uint256) limits; // intercourt token => amount } ...
0
votes
1answer
30 views

Query each struct of a Mapping vs looping getter function for front-end?

I have a mapping of structs and a counter variable to keep track of how many structs are stored in the mapping. For front-end development would you recommend to query each struct using the auto-...

1
2 3 4 5
7