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
0answers
11 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
11 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
18 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
25 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
26 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
36 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
36 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
31 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
104 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
33 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
63 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
19 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
20 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
34 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
30 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
21 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
67 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
16 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
8 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
27 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
26 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
58 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
35 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
38 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
25 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
20 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
34 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
46 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
45 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
85 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
79 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
24 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
370 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
27 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
40 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
46 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
30 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
29 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
238 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
48 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
251 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
363 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
118 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
57 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
178 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
61 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
90 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
11 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?

1
2 3 4 5 6