Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
1answer
27 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
24 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
25 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
14 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
31 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
12 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
0answers
40 views

How to use mapping with array, struct to store seller's and buyer's data in array? [closed]

contract Seller { address payable owner; address [] sellerArray; struct Sellers { address sellerAddress; uint parcelId; uint parcelPrice; } contract Buyer is ...
0
votes
1answer
12 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
17 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
76 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
31 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
21 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
23 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
39 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 ...
1
vote
0answers
20 views

Possible ERC-20 improvement: Token-specific ENS equivalent

With ENS still providing quite a difficult user experience for the average user, I'm wondering why standards like ERC-20 don't implement a simple mapping allowing people to set names equivalent to ...
0
votes
3answers
22 views

Is There any way to check if the entered key is having a corresponding value in a mapping or not?

Suppose In a banking system many people are enrolled (managed through mapping ) mapping (address => bool) enrolled; And only those can deposit who are enrolled in the bank. Can I check if ...
0
votes
1answer
23 views

How to initialize a new struct with an empty mapping? [duplicate]

For expl. mapping(uint => Test) tests; struct Test { uint id; mapping(address => uint) votes; } function newTest() public { test[0] = Test(0, <EMPTY_MAPPING>) }
0
votes
1answer
24 views

Is there a form of mapping with an even larger space?

I understand from here that the space for mapping() is drawn from a size of 2^256 * 32 bytes storage, which provides a 1 chance in 10^69 of overwrites. If I'm working with contracts on the order of ...
0
votes
1answer
17 views

Membership in a set of strings

I'm looking solidity help in storing a set of strings and checking for membership in that set. I have a concrete and an abstract question on that: Concrete What is the data structure in solidity ...
0
votes
2answers
59 views

How to delete or remove a key from mapping?

I have the following map: mapping (string => Category) categoryMap; Let's say the key was mistyped, so I want to remove the key and add a correct one, how would I do that? Function would be ...
1
vote
1answer
21 views

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

Mappings are normally declared in the top part of the contract, however is there any way to instantiate a mapping - which belongs to a struct - while in a function?
1
vote
3answers
58 views

How do I check if a bytes32 variable in a mapping has been assigned value?

For example, for: mapping(address => bytes32) public addressName; which one of the following syntax is correct? address _address = 0x...; //an actual address require(addressName[_address]!=""); ...
0
votes
1answer
14 views

Should I maintain an array of all the valid keys in a given mapping?

I have a contract which maintains a map of valid wallets. In this map, the keys are wallet addresses and the values are wallet parameters: struct WalletParams { bool valid; uint x; uint ...
1
vote
0answers
18 views

web3js send transaction failed when contract modify mapping data , but remix work

first, web3 version: 1.0.0-beta.36 the contract code is: pragma solidity ^0.4.25; contract Main { struct Model { uint256 key; uint64 createTime; } Model[] public models; mapping(...
0
votes
1answer
25 views

Mapping address to multidimensional uint

I'm trying to create an array contains addresses which belongs to particular transaction ID. Array structure: transactions[0x12345][0] = 123456 transactions[0x12345][1] = 789101 transactions[0x12345]...
1
vote
2answers
85 views

TypeError: Cannot read property 'call' of undefined

I am trying to read a mapping inside my smart contract that looks like this: mapping(address => User) public users; My web3js code looks like this. I am trying to read mapping users inside the ...
1
vote
1answer
42 views

Getting and storing address of erc20 contract after dynamically creating it

I have a function which dynamically creates an ERC20 contract on calling a function in another contract as follows: function createDao(string _tokenName) public payable { tokenNumberIndex = ...
-1
votes
0answers
21 views

How much records can a mapping store? [duplicate]

In my contract I figured out to store users balances (of ether and erc20s, that's why the mapping is nested) in a state variable: mapping(address => mapping(address => uint)) public balances; ...
0
votes
1answer
30 views

pagination when reading mappings in solidity

I am trying to read a lot of data from a smart contract mapping, How can I include pagination when retrieving data through smart contract methods?
2
votes
1answer
20 views

Do I need to delete mappings that I don't need anymore?

I have a struct like this: struct Game { string gameID; string[2] teams; string winningTeam; string losingTeam; mapping(string => uint) totalWeiBet; ...
0
votes
1answer
467 views

How to loop through a array of addresses?

I have a mapping and an array that contains a list of addresses of students. When I loop over that array, the method .length is not working. How can I loop through the array Student_list shown below?...
2
votes
3answers
227 views

How to map an address with a string array in solidity?

Goal: I wish to store an array of names with an address in a smart contract. It's more like Key-Value pairs where addresses are paired with a list of type strings. Can I use mapping to implement this?...
1
vote
1answer
28 views

How to dynamicaly edit a mapping

I want to be able to edit values in a struct. My struct is declared and mapped like this : struct entityLinks{ string linksUrl; string linksName; } mapping (uint => ...
2
votes
1answer
16 views

Gas used for the same deterministic operation is different

standard ICO function which exchanges Ether to ERC20 token balance. Call 1, used 49431: https://ropsten.etherscan.io/tx/0x6671c8fd39d195b09868d914d80f0e884e42259c7346b69afb483f2e18fae263 Call 2, ...
0
votes
1answer
49 views

Sorting elements from mapping according to certain value?

I have created a function that receive some values from users an store them in a mapping. How to arrange the stored values in mapping according to a certain value ( Priority as in the shown example ...
1
vote
3answers
50 views

Smart Contracts Mappings

I am trying to understand smart contracts mappings. Imagine I have smart contract that can create an object "car" and store in its mapping. This object has parameter like "tires" with black value. ...
1
vote
1answer
75 views

Updating a field in structure - One to many mapping - Solidity

I have a structure Student with one to many mapping and pushed values to it.Following is my code: pragma solidity ^0.4.20; struct Student{ uint id; string name; uint256 mark; } mapping(...
0
votes
2answers
95 views

Why use arrays and not mappings? [duplicate]

So I was implementing a trading contract and need to keep a list of products on sale. I was using arrays but later switched to mappings. So arrays implementation: uint[] public productsOnSale; uint ...
1
vote
1answer
64 views

Changing dynamic array index content

I'm trying to to make a contract which lets the user choose any number he likes to populate an array of integers used in a mapping. Then he can choose any index of this array to increase its value by ...
2
votes
2answers
61 views

How to maintain history of changes in mapping?

I have a mapping variable in my solidity code which maps address to name. I want to maintain the history/log of every change that happens in this mapping. What is the best possible solution to it?
2
votes
1answer
24 views

Array of items vs mapping+array of ids with web3js?

In most articles they recommend to use mapping. But mappings don't allow to iterate their items directly. And nobody says what to do if you need to get all the stored items. In my case I need store ...
2
votes
1answer
43 views

Can i create a new address this way?

I am busy with a project. So I have an array of a struct within another struct. In this case for example array of CattleHealth in Cattle. In my RecordHealth function, I am taking the address of the ...
1
vote
1answer
27 views

How to add an instance of a struct to an array of another?

Hi I am pretty new to solidity. I am busy with a project that records all kinds of information about cattle. In my code below my cattle struct has an array of CattleHealth and CattleGrowth which are ...
1
vote
1answer
110 views

How to map Array of Structs in Solidity [duplicate]

Need this architecture { address1 => [struct1, struct2], address2 => [struct1, struct2, struct3,], address3 => [struct1, struct2, struct3, struct4, struct5], ......
0
votes
1answer
77 views

Array of Struct always returns 0x0 at index 0

Here's my sample contract code. contract SimpleStore { uint public BetRound; uint public SelectedUser; struct Struct { uint _round; address _owner; uint _index; bool _active; ...
1
vote
1answer
46 views

Storing millions of values in mapping variable

Is it a good practice to store millions of values in a mapping variable for unique verification? For example, storing a customer name and unique number and later retrieve customer information from ...
2
votes
2answers
103 views

Adding an array in mapping

The main purpose of this code is to add an array of users in mapping. there are certain users who play a video game and are on a certain level now level will be considered as a mapping index and on ...
1
vote
1answer
124 views

Is there a need to remove entries from mapping?

I am adding approximately 3 ~ 5 new entries into the mapping, while the old one will be obsolete after a week. If the mapping grow larger, is it going to consume more gasses? Is there a need for me ...
2
votes
1answer
27 views

Access single value of a mapped struct

I want to access a single value of a mapped struct from another contract. For now, I know how to return all values of the struct by using the following code: function getUnitById(uint256 _id) public ...
0
votes
1answer
40 views

Mapping with values signifying set membership

I'm trying to achieve set membership functionality where keys are member IDs: mapping(uint => mapping(uint => bool)) s; s[0][1] = true; However, I'm getting: Expected identifier but got '=' ...