We’re rewarding the question askers & reputations are being recalculated! Read more.

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
14 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
17 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
16 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-...
0
votes
1answer
25 views

Keeping a finite set of addresses (Solidity)

struct Data { ... } contract Court { mapping(address => Data) subcourts; } I want to keep track of a small finite set (which can be added or removed) of all keys of this mapping. What is the ...
0
votes
2answers
20 views

Set contract storage directly at deployment

Is there a way to pre-define a contracts storage when deploying it? Say I want a mapping to be filled with 1000 entries but want to avoid having to pay gas for adding every entry on its own. Since ...
0
votes
1answer
18 views

Solidity. Check if key has value in mapping. Operator != not compatible with types struct

I am new to solidity. I have a Person struct and mapping: struct Person{ uint age; string gender; } Person[] players; // holds the 24 players mapping (string => Person) ...
0
votes
1answer
26 views

Solidity. How to add an address to a mapping

I have this: contract Diary { string[] private facts; mapping (address => bool) approvedAddresses; address owner; constructor() public { owner = msg.sender; ...
1
vote
1answer
51 views

Vyper mapping inside a struct

Is it possible to have a mapping inside a struct for vyper? For example: struct Teddy: id: uint256 year: uint256 component: map(uint256, uint256) teddies: private(map(uint256, Teddy)) ...
0
votes
1answer
77 views

I would like to 3 mappings

I am a beginner. I would like to 3 mappings I know 2 mapping looks like this: mapping (address => mapping (address => uint256)) public allowed; and my question is: is 3 mappings look like ...
1
vote
1answer
20 views

Trouble accessing an array inside a struct inside a mapping via web3

Here are a few relevant code snippets from my smart contract struct Constituency{ uint16 id; string name; uint64[] cans; } mapping(uint => Constituency) public constituencies; ...
3
votes
1answer
150 views

TypeError: Indexed expression has to be a type, mapping or array (is function (address) view external returns (string memory,string memory…)

I have 2 contracts first one is sub second one is main . First i deploy main and create a new subtoken. Then I want to access my maincontract in subToken contract but I cant :( When I compile this ...
0
votes
1answer
17 views

How do I check If a map entry doesn't exist for a given sender?

I have a map such as: mapping (address => bytes32) private myMap; Later in the code, in a function, I want to ensure my sender already has an entry in that given map. Can I do this? require(!...
1
vote
1answer
24 views

How do mappings in solidity occupy memory

Say, I declare a mapping that uses uint256 numbers as keys and maps them to a single 8 bit character. I add 5 members to this mapping. Obviously, I can then access any of these 5 characters using ...
0
votes
1answer
32 views

Getting information from contract address?

pragma solidity ^0.5.0; import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol'; contract SubToken{ using SafeMath for uint; struct token{ ...
0
votes
3answers
26 views

Struct creates instances with zero values for all of it properties instead of using function arguments

Inside my smart contract I have a struct type NotaryEntry and a function addNotaryEntry which creates an instance of the struct and add to a mapping, I do pass the right values to the function but the ...
0
votes
1answer
23 views

Mappings inside functions to filter query

I have a struct and several boolean mappings that are used to keep track of struct's properties struct Animal { string species; bytes32 ID; } mapping (bytes32 => Animal) public Animals; ...
0
votes
1answer
91 views

Member “name” not found or not visible after argument-dependent lookup in string storage ref

I have code like this and I want to set my name, surname and age in my struct so I want to set them and get them using with my functions here's my code : pragma solidity >=0.4.0 <0.7.0; ...
0
votes
1answer
40 views

Expected ')' but got identifier if(string name != users[name]){ ^--^

pragma solidity >=0.4.0 <0.7.0; contract NewHello{ mapping(address => string) public users; // contains a name for every address function updateUser(string memory name) public { ...
0
votes
1answer
76 views

member not found or not visible after argument-dependent lookup in mapping

pragma solidity >=0.4.0 <0.7.0; contract New{ mapping(address => string) public users; string name; address[] public userAddress ; //string[] public userNames; ...
0
votes
1answer
158 views

Type string memory is not implicitly convertible to expected type struct InsanFactory.User storage ref

pragma solidity >=0.4.0 <0.7.0; contract InsanFactory{ struct User{ string name; address myaddress; } mapping(address => User) public userStructs; ...
0
votes
2answers
69 views

How to access content of mapping in a struct?

I'm aware of this post: Accessing a mapping within a struct via Truffle console However, it seems to me, it does not provide a clear answer. Also, my question is more generic and not just for ...
1
vote
1answer
56 views

Mapping with iterating uint as identifier - multiple transactions in the same block

I want to use an iterating uint as an identifying number, but I have a simple question to make sure I can do this safely on the mainnet. Here's a simple example to demonstrate the issue: pragma ...
1
vote
1answer
22 views

Why does a mapping update itself when I am not doing anything?

The title is a little bit vague but I've seen this contract and tried it on remix: pragma solidity ^0.4.24; contract Tester { struct Account { uint256 balance; } mapping (address => ...
1
vote
4answers
106 views

mapping one id to multiple addresses

Suppose I have a product with a specific id for sale(so I am the owner) and someone wants to buy the product from me. When he pays the price he will become the new owner of that product. How can I ...
0
votes
1answer
45 views

Can I init mapping in solidity with pre-defined values?

f.e in Python: mappingName = { 'key1': 'value1', 'key2': 'value2' } What are the best practices to achieve that?
0
votes
1answer
72 views

How can I push data to array when using mapping (address => address[]) mappingName?

What is the exact syntax to push data using the above given syntax?
0
votes
0answers
10 views

What is the maximum storage size to store number of addresses in array? [duplicate]

I want to map multiple addresses using one address by doing this: mapping (address => arrayOfAddresses[]) mappingName; What is the maximum size of addresses I can store in that array?
0
votes
1answer
34 views

map multikey how-to?

I'm trying to create a map whose key is composed of two bytes32 keys. I've tried with tuples-keys and struct-keys but both are rejected by the compiler. I'm also thinking about "hashing" both keys ...
1
vote
1answer
15 views

Problem on returning fields of a struct inside a mapping

I have the above code mapping(string => Owner) public Owners; function addOwner( string memory name, string memory surname, string memory fathername, string memory mothername, string memory ...
0
votes
1answer
128 views

DeclarationError: identifier not found or not unique 'candidate'

I got the above error at the mapping 'candidate' pragma solidity ^0.4.22; contract Election { struct Candidates { string name; uint voteCount; } struct voter { bool authorized; ...
1
vote
2answers
175 views

Reset all values in a mapping

I am trying to figure out how to have the balance of all players reset to (amount) when a certain condition happens. This is the function that will update a specific player balance. How do I make it ...
0
votes
0answers
50 views

Best way to support restoring of all the keys of a mapping

I have a contract, in which I maintain the keys of a mapping in two different ways: Storing each key in an array Emitting an event for each key I do this in order to be able to restore the keys (and ...
0
votes
2answers
378 views

Default getter and setter for mapping in solidity

In my smart contract I've public mapping as mapping (uint=>User) public users where User is a Struct, so is there any way to get the values of this mapping using default getter. For Example : If ...
0
votes
1answer
29 views

Mapping or indexed event

I want to store data on chain that is not needed within a smart contract but should be retrieved easily and particularly quickly from outside. I know that storing the data within an indexed event is ...
1
vote
3answers
344 views

how do I loop through a mapping of address [duplicate]

I have a mapping of list of struct (mapping (address => struct[])) I'm having a trouble in how to display all them together in the front end (i'm using React js). Thnx.
1
vote
1answer
17 views

Use Values Returned from One Function in Another

need a little help if you can spare the time. Making a little card game where people can collect "warrior" cards. We'll have an initial 12 master "cards" that supply the initial traits for the ...
2
votes
1answer
207 views

In Ethereum how to check if in mapping, the key already exists?

In this Proof of existence, integrity, and ownership contract of a file why files[fileHash].timestamp == 0 is used? why timestamp? contract Proof { struct FileDetails { uint timestamp; ...
1
vote
1answer
202 views

How to search through blockchain?

I m doing project for document verification using blockchain in which we don't have to carry documents everywhere, hash key of block will fetch data of doc from blockchain.I m not getting how to ...
0
votes
2answers
256 views

access mapping inside mapping of struct in Solidity ^0.5.0

I have a contract which looks like this: contract a { struct Str { uint256 totalTokens; mapping(address => uint256) playerTokens; } mapping(uint256 => Str) public ...
0
votes
1answer
32 views

How Ethereum stores its data in the blockchain [duplicate]

I am new to ethereum and the blockchain, but I am wondering about blockchain databases. Mainly I am wondering how exactly the database data and the blockchain merge. For instance, in a database you ...
0
votes
1answer
47 views

Associate event struct to user addresses

I have two contracts. One called User and other called Event pragma solidity ^0.4.24; contract User { mapping(uint=>address) addresses; uint addressRegistryCount; } pragma solidity ^...
1
vote
1answer
1k views

Return a mapping in a getAll function

pragma solidity ^0.4.24; contract User { mapping(uint=>address) addresses; uint addressRegistryCount; function set(address userAddress) public { addresses[...
0
votes
1answer
14 views

How do I get product/parcelID from particular Assigned address using struct and mapping?

struct Sellers{ address sellerAddress; uint parcelId; uint parcelPrice; } In this struct I've entered multiple parcel Ids to sellerAddress and I've retreived them using _sellerAddress. ...
0
votes
1answer
27 views

Struct and Mapping input value error of Invalid Opcode while calling setSeller() to store multiple seller's addresses

What dose the -1 means? Or why we should use -1 while pushing one element in array. What should I enter in sellerAccounts: field as input? pragma solidity ^0.5.1; contract Seller{ struct ...
1
vote
0answers
68 views

Return an array of adresses

I have a mapping with the key as an address and the value as an array of addresses. How do I return the array of addresses? In older solidity versions it works. In newer compiler versions I have to ...
2
votes
2answers
162 views

Pure functions as a replacement of constant mappings?

I need to create a lookup table [uint -> uint] that is constant. Constant mappings or switch-case are not available in solidity. Are pure functions full of if-else the only option? Any better ...
0
votes
0answers
53 views

Why was mapping introduced in Solidity instead of a dictionary or map data strcuture?

What was the thought process behind introducing mapping in Solidity? Doesn't dictionary and map serve the same purpose in other languages? I want to know the necessity that led to the inclusion of ...
1
vote
1answer
120 views

How to access nested struct values?

I'm new in solidity programming so for learning purpose I'm developing e-voting system using ethereum blockchain. Code mentioned below, pragma solidity 0.4.25; contract RegisterCandidate { // ...
3
votes
1answer
115 views

Which is the expected behavior trying to get an undefined mapping value?

In ERC20 standard, _allowed is defined as: mapping (address => mapping (address => uint256)) private _allowed; and the getter function is defined as: function allowance(address owner, address ...
2
votes
2answers
326 views

How do I read an array inside of a struct?

as part of learning solidity and smart-contract development, I am developing a simple part management/tracking system. I have a struct and a mapping for a list of parts as such: struct Part { uint ...