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
1 answer
5 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
11 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 in solidity 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 ...
The matador's user avatar
1 vote
1 answer
10 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
29 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
14 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
  • 328
1 vote
1 answer
92 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
  • 202
0 votes
3 answers
38 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
  • 1
0 votes
2 answers
10 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
34 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
25 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
  • 47
0 votes
0 answers
14 views

Gas fees differ for updating different values?

I've did some gas efficiency tests on the testnet and wonder why the following is the case... Updating values can be done with both of these methods: x += y; /// or /// x = x + y; For mappings, like ...
Andy's user avatar
  • 185
0 votes
0 answers
27 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
65 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
15 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
  • 47
1 vote
1 answer
766 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
63 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
21 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
17 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
21 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
255 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
41 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
67 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
117 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
0 answers
36 views

Using a nested mapping as a substitute of an mapping with array as value

I have an parent (address) which can have a collection of children linked to it. First I did this with a mapping of an address to a array of Children[] named parentToChildMapping. This was not really ...
Bram's user avatar
  • 126
0 votes
1 answer
18 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
  • 350
0 votes
0 answers
32 views

How to compare two values of structs of the same msg.sender from different mappings

I'm having a Smart Contract contest among friends about who loses the most weight. Each competitor is expected to enter its weight at the beginning of the week and at the end of the week. The ...
Jean Paul Laclau's user avatar
0 votes
1 answer
54 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,039
1 vote
1 answer
43 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
50 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
72 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
96 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
84 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
222 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
183 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
100 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
  • 271
0 votes
2 answers
31 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
66 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
  • 21
0 votes
2 answers
27 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
59 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
177 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
  • 153
0 votes
0 answers
47 views

Mapping or Struct to store data in NFT : gas fee and best practice

What is the best practice and gas less to store data inside the nft, not in metadata. First exemple with 3 writes and second with 1 write. But it seems Struct is more expensive. And when it will be ...
Cryptopowa's user avatar
1 vote
2 answers
238 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 vote
1 answer
96 views

How to loop through mapping in solidity with least gas cost possible?

I have a mapping defined in my contract like below. mapping(address => uint256) public stakers I need to loop through it to get all of them for my frontend and other contract. function getStakers() ...
SanjayDefi's user avatar
0 votes
1 answer
19 views

how can i use mapping on structure inside another structure and create some elements

i want to create some Pledges for Startup there are these structures: struct Startup { address payable founder; string title; string startupDescription; uint goal; uint ...
FunD's user avatar
  • 1
0 votes
1 answer
26 views

Mappings cannot be assigned to error Solidity

pragma solidity >=0.4.21 <0.7.0; contract Bid{ mapping(string=>uint) propertyVoteCount; mapping(string=>mapping(string => bool)) propertyUserVoted; function vote(...
Shubhankar Kumar's user avatar
1 vote
1 answer
48 views

When declaring an Interface, do i have to declare the mappings of the contract too?

Actually im wondering if in order to use a mapping from a 3d party contract in an other contract, can i devlare the mapping in the interface and use it like Mycontract.mapping() and view/modifiy it ,...
cutedwannabe's user avatar
0 votes
0 answers
21 views

Get next highest number / bidder in solidity

I am building an auction contract, every 7 days the highest bidder will get chosen and the non-winning bidders will participate for next week's auction. My question is: lets say bidders sends bids in ...
Fariha Abbasi's user avatar

1
2 3 4 5
11