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.

0
votes
1answer
21 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
15 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
15 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 ...
0
votes
1answer
9 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
39 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
11 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
10 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
10 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
27 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
23 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 = ...
0
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
23 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
19 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
86 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
98 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
20 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
14 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
31 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
2answers
34 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. ...
0
votes
1answer
45 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
58 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
37 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 ...
1
vote
2answers
48 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
18 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
34 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
21 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
64 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
54 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; ...
0
votes
0answers
30 views

update enum in mapping ( only in ganache )

my test code gives "base limit exist gas limit" when i try to update enum value in mapping with two diff method. if one method execute successfully then other one gives above exception. my logic is, ...
2
votes
2answers
50 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
76 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
24 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
27 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 '=' ...
2
votes
2answers
266 views

Error: Couldn't decode bytes32 from ABI: 0x The size doesn't match

I am querying a mapping via a web3 call like this: var Web3 = require('web3'); const web3 = new Web3(new Web3.providers.HttpProvider('https://kovan.infura.io/key...')); var contractABI = new web3....
0
votes
1answer
53 views

Unable to retrieve struct from mapping

I have a mapping like this: pragma solidity 0.4.24; pragma experimental ABIEncoderV2; pragma experimental "v0.5.0"; ... mapping(bytes32 => LibMarket.Market) public hashToMarket; where each ...
0
votes
0answers
116 views

Dynamic arrays VS mappings when it comes to gas usage?

I'm puzzled what is more efficient to use, from the point of gas consumption (storage and execution), dynamic array or the mapping and element counter. To be more clear, I'm not asking the basic data ...
0
votes
1answer
20 views

How does EtherDelta migrates mapping?

I'm looking at EtherDelta contract, and -- provided it had been migrated several times in the past and probably foresees future migrations -- I'm confused as I don't see any method by which the owner ...
1
vote
2answers
35 views

Retrieving key value while setting mapping

Im new to solidity and trying to figure out if there is any way to retrieve a mappings key value for example from the transaction data in which you set it? mapping (uint => bool) private solution; ...
1
vote
1answer
124 views

Unable to declare public mapping in Solidity

When I try compiling the following on Remix: contract Betting{ struct Player{ mapping(uint => uint) amounts; } struct Match{ address [] playerAdresses; uint []...
0
votes
1answer
43 views

copying bytes32 values from map to array

I am trying to copy stored values from a map to an array. I have the following code: pragma solidity ^0.4.21; contract test { event LogTest( bytes32[5] a ); bytes32[5] arr; mapping (uint=...
1
vote
1answer
91 views

Test if a map element has been deleted or does not exist?

I have a map of game IDs to game structs in my Solidity contract. I want to test if a game struct for a given ID does not exist or has been deleted. I am using the code below: // The map that maps ...
0
votes
2answers
125 views

Can't access nested mapping in another contract in Solidity

I have a contract: contract KeyValueStorage { mapping (address => mapping(bytes32 => uint256)) refreshTime; .... } and in another file: import "./KeyValueStorage.sol"; contract ...
0
votes
1answer
111 views

Empty string in mapping(address => string[])

I have a mapping(address => string[]). How can I check if, given an address and a position of the array string[] corresponding at that address, it exists a value in that position or not? Thank ...
1
vote
1answer
78 views

Contract owner address changing

I was trying to create a simple quote registry having a mapping defined as: mapping (string => quoteOwner) quoteRegistry; where quoteOwner structure is: struct quoteOwner{ address ownerAdd; ...
0
votes
1answer
146 views

Solidity: substitute for returns (strings[])

I have a mapping mapping (address => string[]) myMap; How can I return the list of all the strings associated to a given address? I know that in Solidity one can't return an array of strings, ...
0
votes
1answer
18 views

How can I add an element to a mapping array (mapping[])?

Remix accepts the following code and allows me to deploy the contract: pragma solidity 0.4.24; contract bytes32array { mapping(address => uint)[] balances; function addBalance(...
1
vote
1answer
40 views

Is it possible to have a signature as the mapping key type?

If I have someone's signature and I want to use it in a mapping, is there a way to have it serve as the key in that mapping? Would I need to use mapping (string => uint), or mapping (bytes32 => ...
2
votes
2answers
298 views

Syntax: How do you require a string to be null (or anything but null)?

I want to make sure that when doSomething() is called, the string variable is always populated (that it can't be left blank): function doSomething (string hash) public { require(hash != ...
1
vote
1answer
111 views

How does crypto kitties lists their auctions?

Crypto Kitties offers a marketplace where you can buy kitties. The functionality is handeled by a contract called SaleClockAuction. This contract inherits from ClockAuctionBase where all auctions are ...
0
votes
2answers
113 views

Solidity inserting data that maps addresses to arrays of bytes32 error

My contract is as follows: pragma solidity ^0.4.21; contract try { mapping (address=>bytes32[10]) Map; function try(){} function fill_map(bytes32[10] _attributes) public { ...