Skip to main content

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
1 vote
2 answers
26 views

How can I byte pack these datastructures in solidity to be more efficient?

I have a bunch of mappings that I want to optimize in my Solidity smart contract, is there a way that I can use byte-packing to reduce the size needed to store all the data in these mappings? ...
Barney Chambers's user avatar
5 votes
4 answers
119 views

Does it make sense to remove unused entries from contract mapping in 2024

im wondering if it still makes sense to remove entries from mappings in ethereum contract. It seems like initially there was a relatively big benefit of cleaning up the storage but from what i read ...
mat13mn's user avatar
  • 51
1 vote
1 answer
79 views

Inline assembly, how to get string from struct in mapping with Yul?

I don't get how to get next element in struct. I can take id value, but what to do next? i assume, i need to add 1 to slot, to get string value but what it return, reference to the string? and what i ...
Gleb Protasov's user avatar
1 vote
1 answer
26 views

Populate mapping in global scope returns error

I'm confused about mappings. I always used them by populating them through functions. Now I need a simple mapping with a handful of items and wanted to populate it like this: mapping(uint8 => ...
user130657's user avatar
0 votes
1 answer
22 views

What could go wrong with saving data on mapping for the sake of UI use?

I have a Token contract and I want to record the token price once per day. So I was thinking that to cut the trouble of going trough creating a server to save the data or using a service API I would ...
The matador's user avatar
0 votes
1 answer
63 views

What's the cheapest way to store a large amount of data into a smart contract?

I'm working on a smart contract in which we need to store some addresses along with their pending rewards periodically, so the most first approach is to have a mapping of addresses to an int, like ...
S Arv's user avatar
  • 11
0 votes
1 answer
90 views

how to access to a public mapping from test script

i'm in hardhat i'v this public mapping mapping (address user => uint[] commentIds) public userComments; and i'm trying to call it inside my test Script console.log(`user1 comments: ${...
Yassine's user avatar
  • 11
0 votes
0 answers
13 views

Can I delete the Values in the mappings using delete keyword [duplicate]

mapping(IERC => contract) public testing; delete testing[IERC]; In the above code snippet I want to delete contract type (value) using the delete keyword can it be possible?
kumar's user avatar
  • 61
0 votes
1 answer
8 views

How to get the array index by a perticular condition

// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; contract final_year_project { struct hospital_record { address patient; string hospital; string docter; ...
Asad Arslan's user avatar
0 votes
1 answer
19 views

How much would be too much data to save in a public mapping?

So I know that in solidity for larger data we wouldn't use contract to save the data but rather we'd use some kind of external database. But I'm not sure how large is too large and what would happen ...
The matador's user avatar
0 votes
1 answer
37 views

What is the best gas efficient way to reset all values for keys in a mapping?

As far as I understand there is no way to automatically reset all values of a mapping to default in solidity. now lets say I have a mapping mapping with 7 keys and values set. to refresh all the ...
The matador's user avatar
1 vote
1 answer
73 views

How to create a hash based on struct array types?

I have the following arguments to call a function in a smart contract: ERC20Reward[] calldata _erc20Rewards ERC721Reward[] calldata _erc721Rewards ERC1155Reward[] calldata _erc1155Rewards ...
Falcon Stakepool's user avatar
0 votes
1 answer
47 views

How to identify a specific ERC1155 token instance?

I'm trying to write a game item contract where the player can upgrade the items. For this, I need to be able to clearly distinct the different instances of the same tokenID. Let me explain, if : ID=0 -...
Building Dwarf's user avatar
1 vote
1 answer
24 views

i have an upgradable smart contract with 3 mappings, i set only the first two in the initialize function

i have an upgradable smart contract with 3 mappings, i set only the first two in the initialize function . pragma solidity ^0.8.0; contract ContractA { mapping(uint256 => address) public ...
noro meb's user avatar
  • 368
1 vote
1 answer
165 views

What are the possible security threats when using mappings in Solidity?

Does the use of a nested mapping possess any threats to the security of the contract below? contract Users { struct User { address payable regAddress; uint64 timestamp; ...
Mila A's user avatar
  • 1,264
1 vote
3 answers
55 views

How to access a mapping from another contract with enums

The second contract needs to check the mapping in the first contract to see if the person finished the required course. I checked a few old threads but they said it wasn't possibly with that version ...
Shrimp's user avatar
  • 11
0 votes
2 answers
22 views

Representing Price in a Mapping

I want to use a mapping that stores prices for each token in my ERC721 contract but am hitting an issue with the default uint value being 0. I'd like for my getPrice(uint256 tokenId) function to ...
Emanegux's user avatar
  • 123
0 votes
1 answer
40 views

Brownie not returning Mapping Values

Good day to everyone, I've been working with brownie for sometime now and have been running into a lot of challenges. I created a struct basically and a mapping to that struct, however when I deploy ...
Tolu's user avatar
  • 3
1 vote
1 answer
28 views

How many strings can i store inside a mapping before the contract fails to work?

I have a single contract that is on the verge of its size limit (One more function and i wont be able to deploy anymore) Within this contract, there is a mapping that I want to feed with strings after ...
PupSt4r's user avatar
  • 61
0 votes
0 answers
62 views

Is there any way to get the array length inside a mapping without a getter function or count variable?

mapping(address => uint256[]) public submitterAddressToFormIdsAssigned; This is a mapping from an address to an array of uint256s. I want to get the length of array. I used a count variable before ...
Gaurav Pant's user avatar
2 votes
1 answer
136 views

Storage collision in vyper hashmap?

Can you get a storage collision in vyper? The HashMap value is stored at the keccack256 of the key. So wouldn't this mean storage collisions are possible?
Patrick Collins's user avatar
0 votes
1 answer
23 views

Why we can't initial a public mapping in a struct?

contract MyContract { struct Balance { uint numDeposit; mapping(address=> uint) public Deposit; //It will give an error due the public keyword uint numWithdraw; ...
Arkonomi's user avatar
0 votes
2 answers
24 views

Initializing string variables from mapping values doesnt work

I try something like this: mapping (uint256 =>string) public example; then i initialze 'example' in the constructor example[0]="apple"; example[1]="peach"; then i define a ...
PupSt4r's user avatar
  • 61
1 vote
1 answer
2k views

Error encoding arguments: Error: types/values length mismatch (count={"types":1,"values":3}

Can you please explain me why it's happening and how I can solve it ? Error: call to GameItem.storeWalletAddress errored: Error encoding arguments: Error: types/values length mismatch (count={"...
Akshar Prajapati's user avatar
0 votes
1 answer
147 views

Do keys in a map also packed to storage as well?

If we have this mapping mapping(uint128 => uint256) private first; mapping(uint128 => uint256) private second; Do the keys of uint128 from both first and second gets stored together in one ...
Ric's user avatar
  • 1
1 vote
1 answer
25 views

Return a reference of map item from a function

Hello Solidity Community, I have a chunk of code that repeats a lot, wondering if I could make a function or something to shorten it. Similar chunks of code appear a lot as well. Skin memory skin = ...
Milos Krstic's user avatar
1 vote
0 answers
29 views

How do I conduct Presale off chain? Keeping the address and the amount of coins purchased

I'm creating a presale website and a presale coin in solidity. How do I keep tract of the poeple who bought it something like whitelisting right
jacobs david's user avatar
1 vote
1 answer
23 views

Dynamic update of struct field inside mapping

I have a struct struct Shots{ uint coverDrive; uint straightDrive; uint pull; uint squareCut; } and I used a mapping mapping(address => Shots) public BattingSkill; Now I want to ...
Bappa Banerjee's user avatar
2 votes
1 answer
419 views

Gas limit for calling a smart contract function varies greatly upon address list parameter

Consider the following smart contract: pragma solidity ^0.8.19; contract Test { mapping (address => bool) registered; function test(address[] calldata addresses) external { ...
Ahmet Yazıcı's user avatar
0 votes
1 answer
16 views

Variable Values do not persist in between function calls

I am new to Solidity, and I am experimenting on smart contracts using Remix-IDE connected to a deployed local Geth instance. What I am trying to do is to create a struct containing multiple fields for ...
AAA's user avatar
  • 1
1 vote
1 answer
61 views

Gas cost of mapping operations

Suppose, your contract has something like if (_balances[account] >= someNumber) { _balances[account] = _balances[account] - _balances[account]/10; } What is the gas cost of this operation? I ...
dnnagy's user avatar
  • 111
0 votes
1 answer
89 views

Function isn't returning the uint256 value after initializing mapping

I'm facing a problem with the function return type in solidity. Here is my code: // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; contract Birth { mapping(uint256 => bool) public ...
Asir Shahriar Roudra's user avatar
1 vote
1 answer
273 views

Mapping String to uint

I'm trying to map string to uint but for some reason I'm not able to return the value. However on the demo contract it is working fine. Can somebody help me find the difference? // SPDX-License-...
psyfi-eth's user avatar
0 votes
1 answer
24 views

Which one is gas efficient?

Lets say i want to store some data about each address ,through the mapping. My first idea is: store in struct this way: struct user { address userAddress; uint256 someUint: string someString; ...
Alireza's user avatar
  • 360
0 votes
1 answer
76 views

How to find all non zero mapping values?

This question is tightly related to how mappings are stored in the storage. Is there a way to search the storage and find all non-zero values of the mapping?
Nal Luksic's user avatar
  • 1,187
1 vote
1 answer
73 views

Using an Array to Delete Mappings

BEFORE YOU DOWNVOTE I know questions on deleting mappings have come up thousands of times but I'd like to pose a question... can you delete it if it's in an array? the following code allows the caller ...
chriscrutt's user avatar
0 votes
1 answer
95 views

Get mapping value with JSON-RPC → eth_getStorageAt || eth_call

How do I get mapping values from my contract with JSON-RPC (without using web3.js)? In my contract: struct Data { address key; string value; } mapping(bytes32 => Data) public values; I can't ...
Alberto4543's user avatar
0 votes
1 answer
131 views

cost fee according to the size of a mapping

I try to improve my skills in solidity programming, for that i try to ode a dynamic NFT, which evolve according to 2 variables stored in a mapping. struct NFTInfo { uint32 nbOwners; ...
Myhaw's user avatar
  • 1
0 votes
2 answers
205 views

Storing address in a mapping

Is this code sufficient to store an address in a mapping? mapping (address => bool) public registeredAddresses; function register(address addr) public { // check if Address hasn't been ...
AAMCODE's user avatar
  • 133
2 votes
1 answer
95 views

Struct returns indexed numbers and property names

I'm using ethers and hardhat to run my React application. I want to pass an object as a parameter to a Solidity function. The function should map the object (struct) to the id provided as a property ...
Justin Stephens's user avatar
0 votes
1 answer
418 views

Retreive a mapping nested inside a struct from Ethers

Hello Ethereum community, I have couple of structs in my solidity code to organize things. Here is one struct from the code: struct Staking { uint total; uint currentIndex; mapping(address => ...
Milos Krstic's user avatar
1 vote
0 answers
21 views

Why not repurpose mapping as array in solidity?

An array T[] can be implemented as a mapping(uint -> T) with indices acting as key in mapping and storing array length as separate uint. I want to understand, if it is more gas efficient to use ...
explorer's user avatar
0 votes
1 answer
388 views

ParserError: Source "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol" not found: File outside of allowed directories

I'm trying to compile a "FundMe.sol" contract: the issue is that when I try to compile it I keep getting the following Compiler Error: Brownie v1.19.2 - Python development framework for ...
waterlilyjack's user avatar
0 votes
1 answer
155 views

Copying an array of structs to memory

I have some code that attempts to copy an array to mapping: // Mapping of user addresses to their payment configuration mapping(address => PaymentConfiguration[]) internal configurations; // Event ...
Ritzy Dev's user avatar
  • 283
0 votes
2 answers
36 views

How can I return multiple value?

How can I return multiple value. If I get string ,it return the last value. How to get string ,its return multiple value? pragma solidity ^0.8.0 ; contract Simple { mapping(string => uint) ...
Elli's user avatar
  • 11
1 vote
1 answer
67 views

Unable to reach storage struct via mapping

Gm, I've got a smart contract for 2D board game purposes. There is a struct Unit struct Unit { UnitType unitType; uint16 x; uint16 y; int8 hp; int8 dmg; ...
Ghinter's user avatar
  • 31
0 votes
2 answers
30 views

Updating a struct property in an array stored as mapping value

This is my data structure for storing a list of questions which will be different for every address struct Question{ uint16 id; string question_string; string answer; } and this is stored ...
Aditi Polkam's user avatar
0 votes
2 answers
101 views

Is this the right way to assign values to struct array with mapping?

struct userdata { string task; bool isdone; } userdata[] public userinfo; address public user; // mapping (uint[]=>string) public tasksno; mapping (address=>userdata[]) ...
Naveed Ahmad's user avatar
0 votes
1 answer
257 views

Operator == Not compatible with types address[] storage ref and address

I have a mapping which maps uniqueids to an array of structs called Listing: mapping(uint256 => Market.Listing[]) private _listings; // the struct in the Market.sol struct Listing { address[] ...
Potion's user avatar
  • 163
1 vote
2 answers
396 views

Delete an entry from mapping vs. setting it to zero

In most ERC721 setApprovalForAll() implementations, to revoke approval, the mapping is set to 0, instead of deleting the entry. I wonder what happens if many users have many approvals revoked, wouldn'...
peizhao's user avatar
  • 115

1
2 3 4 5
11