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
1answer
9 views

One Mapping of Structs vs Multiple one variable mappings

I'm developing a contract to manage multiple NFTs. The contract is an instance of ERC721, which manages some common attributes for every NFT. Which could be the most efficient way to do it? Option 1: ...
0
votes
1answer
21 views

How can i directly access array from ` mapping(string => uint256[]) public _didToDealIndexes`?

I have mapping - mapping(string => uint256[]) public _didToDealIndexes; and I am trying to access it like this - await deals._didToDealIndexes( "did1", ethers.BigNumber.from(...
1
vote
1answer
623 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
193 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 ...
11
votes
4answers
16k views

Solidity - List contains

given address[] wallets. What is the correct method to check that the list contains a given address? Does solidity provide any native list contains function? If not, is the only way to do a full ...
0
votes
0answers
19 views

How to make an array with custom indexes(MAPPING)?

UPDATE: struct TotalVotes { uint256 value; } mapping(uint256 => TotalVotes) public allVotes; This works, BUT WHY DO I NEED TO use a struct? I only want single value which is an integer? Can't ...
0
votes
0answers
15 views

Transfer to multiple addresses without a Loop

I an in search way to send tokens from a contract to a list of all addresses (an array or mapping) without using a loop(as I know gas fees for this can become a huge issue). I have a contract, that ...
5
votes
1answer
2k 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
19 views

Get a value of a nested mapping with only one key?

I have a mapping of a mapping that stores 3 things 1 Address of buyer 2 Address of seller 3 Amount spent. The goal is to store the amount spent by both parties, so that if buyer B something from ...
1
vote
5answers
705 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 ...
3
votes
1answer
643 views

Loop with optimal gas usage

I currently have the following loop (some stuff left out) mapping (address => uint) pendingWithdrawals; function example () private{ address[] tempList = List; for(uint k = 0; k < ...
2
votes
2answers
2k 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
1answer
19 views

Referencing common array in multiple mappings

Trying to understand memory in blockchain for sharing reference of array as common storage for multiple mappings. Let's say there is a need for following relationships. So there will be products keep ...
0
votes
0answers
15 views

Possible to have variable value for ERC721 instead storing on IPFS? And how to retrieve all mapping value?

contract GalaxyExplorer is ERC721Enumerable{ struct Land { string name; address tenant; uint256 x; uint256 y; } struct Planet { string name; ...
0
votes
1answer
15 views

Get mapping value in hardhat

I have a mapping in my contract mapping (uint256 => uint256) totalBoostedPercent; I am using hardhat and typechain to generate type from my contract. In my test file.ts, I tried to access the ...
0
votes
1answer
137 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
580 views

Error encoding arguments: invalid BigNumber string after deploying to Remix

I wanna create a system allowing a company to save several data in the contract, and at the same time many companies can save data in this system. So I create the mapping of struct, and there's array ...
0
votes
0answers
17 views

How can I get this mapping function in an interface? [duplicate]

I have this mapping in a smart contract: mapping (uint256 => mapping (address => UserInfo)) public userInfo; I want to call this in a interface like function view returns: Can someone tell me ...
0
votes
2answers
16 views

How does `mapping(address => uint) public balances` get balances?

I noticed that balances as a mapping mapping(address => uint) public balances; and acts as a dictionary where addresses are mapped to balances.(address -> balance). For a typical dictionary to ...
0
votes
0answers
14 views

how to display/get all the data stores in an address using mapping?

How to display all data stored in an address, function getPlayerInfo(address account) public view returns (uint256, uint16, uint16, uint){ return (playerInfo[account].amountBet, playerInfo[...
0
votes
0answers
25 views

How to check if an address is included in a mapping of address' key from Web3?

I would like to check if a specific address is included in an address key mapping from web3? Here is my Solidity Smart Contract: pragma solidity >=0.4.21 <0.7.0; contract Election { //...
0
votes
1answer
26 views

How to check if data populate in mapping and how to get and display the data?(SOLIDITY)

How to check if data populates in mapping and how to get the value and display for checking? address[] public players; address public owner; struct Bet { uint256 amountBet; ...
0
votes
0answers
13 views

Name has to refer to a struct, enum or contract when compiling on remix

This is betting smart contract, the issue is the user/address need to bet on different matches. The smart contract design only on one mapping value. Full source code:https://github.com/laronlineworld/...
0
votes
1answer
464 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 ...
0
votes
0answers
23 views

Mapping member not initializing

I am experimenting with smart contracts. So I declare two state mapping objects: mapping(address => Val) private _balances mapping (address => Stk) private _stakes; Value types are following ...
0
votes
1answer
203 views

What are the truffle console commands to interact with a mapping function of struct

Im writing a simple smart contract to store and retrieve data of series of patients' name and blood group with an id using mapping function in solidity. I don't know the commands to interact with the ...
0
votes
1answer
3k 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; ...
1
vote
1answer
108 views

How to return an array of structs that has mappings nested within them?

This is the code. And I want to return the Requests array. pragma solidity >=0.8.4; contract Contract { struct Requests { string description; uint value; address ...
1
vote
1answer
22 views

How do I retrieve user data once I have incremented count?

I am building a web application that can store and retrieve user data. Once I add A User i increment count by 1. Once incremented the users data is added and I can fetch the data by the fetchUser(...
0
votes
1answer
16 views

Mapping with Arrays Error

I'm trying to be able to add strings to the array inside the mapping but I keep getting this error on line 13: TypeError Member "push" not found or not visible after argument-dependant ...
0
votes
0answers
17 views

Infinte Gas Estimation by Remix

New to Solidity here but heres my issue. Here are the mappings I'm calling: mapping1 (address => uint32[7]) mapping1; mapping1 (address => uint32[7]) mapping2; function myFunction() external ...
0
votes
1answer
52 views

How to get array of items from nested mapping in Solidity

Suppose I have a struct as follows: struct Item { uint groupId; uint itemId; // more data here } Each groupId is unique. Each itemId is unique only to the given group. So, each Item is ...
0
votes
2answers
28 views

How do I iterate a mapping of strings?

Here is my code: contract MappingsC { mapping(string => uint) public person; function addPerson() external { person["Jhon"] = 34; person["Doe"] = 11;...
0
votes
1answer
240 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
0answers
17 views

Search inside mapping by key value

I have a struct for a Customer contract, and I need to deploy the contract on the blockchain, and be able to search it after by a value that I will give. I have this error: "TypeError: Name has ...
14
votes
4answers
12k views

How to delete a mapping?

Fixed question: I have a mapping: mapping (bytes32 => mapping (bytes32 => bytes32[])) items; With some elements in it: items["fruits"]["apples"].push("first apple"); items["fruits"]["apples"]...
0
votes
1answer
34 views

Can I see who holds my token in solidity

I'm learning to code in solidity and have started learning through making an ERC-20 token. I want to be able to see who is holding the tokens without using a for loop. So far I've mapped each address ...
1
vote
1answer
71 views

Copy contents of one mappings to another

I know this had been answered before but that's with the solc v0.4.x, with v0.8.6 is there any way to copy mappings from one storage variable to another without looping over the mapping index as it ...
0
votes
1answer
39 views

What does variable _allowances mean?

i was trying to understand this ERC20 Contract in OpenZeppelin. In 36th line there is a mapping which defines _allowances, it is being used in multiple lines (120, 155, 177, 196, 311) and i don't get ...
0
votes
1answer
17 views

How to store large amount of addresses

I was looking into how to store large amount of addreses for example to adding atributes to different token holders. As far as i know, most people use mapping, i was researching how that works but the ...
1
vote
1answer
116 views

Smart contract returning values as zeros

pragma solidity ^0.4.18; contract TransManager { //state variables // contract owner address private creator; uint transCounter; // File Meta metaData struct metaData{ uint id; ...
0
votes
2answers
4k views

Default getter and setter for mapping in solidity

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

Browsing a mapping variable

This is my contract where I am building a list of members who will use a addVote function. The allMembersVoted function always seems to return false even though the Remix debugger shows that, the ...
42
votes
2answers
40k views

How can you figure out if a certain key exists in a mapping, Struct defined inside Library (in Solidity)?

pragma solidity ^0.4.8; library Library { struct data { unit val; } } - contract Array{ using Library for Library.data; mapping(address => Library.data) clusterContract; ...
0
votes
1answer
437 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 ...
5
votes
2answers
527 views

How to access dynamic list from web3?

In my application players can create and join games. I store every game in a mapping(uint => Game), and send out a GameCreated event whenever a game is created. My issue is efficiently getting a list ...
0
votes
1answer
29 views

Can we update a mapping in parent contract from child contract?

I had passed the value(key value pair) to a mapping in parent contract from child contract for updating and the program executes without any error. But when I enter key in the mapping from parent ...
1
vote
1answer
62 views

How to input key-value pairs into a constant mapping in a library in solidity?

How can I input key-value pairs into foo? Is there something like below that can be done? library abc { mapping(int256 => int256) internal constant foo = {1: 10, 2: 20, ...}; \\ rest of ...
28
votes
2answers
13k views

Can I save structs in a Mapping?

Is it possible to store structs in a Mapping or any dynamic memory structure in my Solidity SmartContract?
6
votes
4answers
4k views

Is it possible to have enum as a mapping key type?

When trying to compile the following code in browser-solidity: pragma solidity ^0.4.4; contract TestContract { enum TestEnum { ONE, TWO, THREE } mapping (TestEnum => uint) testMapping; } ...

1
2 3 4 5
8