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
12 views

How to test the Solidity-By-Example Mapping smart contract in Remix?

I want to test the following code in Remix. But what is the procedure? What do I put in the input field for the function labeled set? Mapping.sol // https://solidity-by-example.org/mapping // Mapping /...
user avatar
  • 189
0 votes
1 answer
12 views

mapped struct storage layout (slots) and collsions

I want to establish a pattern that ensures no storage slot collisions between current and future (compliant) versions of a contract behind a transparent proxy. In particular, contracts that are meant ...
user avatar
  • 50.6k
0 votes
2 answers
28 views

How to store a large mapping in a smart contract?

I have a contract that need to access the address of different tokens given their name as a string. I thought about doing the below: contract MyContract{ mapping (string => address) public ...
user avatar
0 votes
0 answers
6 views

How do I use Mapping as a filter to return specific values in my struct?

I have a struct in my smart contract, that stores tokens in two different statuses, either as an unassigned gifts or as an assigned gifts. I would like to configure my mapping as a filter to return ...
user avatar
  • 107
0 votes
0 answers
6 views

How can i create a mapping properly?

I would like to create a mapping with a struct inside as key struct MyMap { bytes32 data1; address data2; string data3; } mapping(MyMap => bool) public currentMap; but i am getting ...
user avatar
  • 15
0 votes
1 answer
25 views

using struct with mapping in solidity

i am developing a locker smartcontract where user can lock their erc20 token. i have successfully develop the adding(lock) functionality but having difficulty developing the withdraw function. for ...
user avatar
0 votes
1 answer
23 views

Error: "Struct containing a (nested) mapping cannot be constructed"

While writing a contract that uses structs, I'm getting an error by the linter "Struct containing a (nested) mapping cannot be constructed". According to this, the problem with structs is ...
user avatar
  • 11
0 votes
2 answers
31 views

Deleting values from a struct

how do i go about removing values from inside a struct and or a mapping. For example iam creating a smart contract that acts kind of like a vault, iam not yet finished but i have a create an account ...
user avatar
0 votes
1 answer
20 views

Is it possible to have dynamic and fixed sized arrays in mapping?

I have a mapping: mapping(uint256 => uint256[]) public derivedTokens; In some cases, I want to define the size of the uint256[] dynamic array to 5. But if I try this: derivedTokens[tokenId] = ...
user avatar
  • 118
0 votes
0 answers
22 views

Transaction fails when function attempts to edit a mapping entry

I am trying to create a simple contract that lets a user deposit and withdraw eth at will pragma solidity ^0.8.0; contract DepositRefund { mapping(address => uint) public DepositedAmounts; ...
user avatar
  • 11
1 vote
1 answer
42 views

Solidity keyword delete is not working

I have used the keyword delete to delete mapping and array in Remix a couple of months ago, But now I have just noticed that the keyword delete is not working at all. Does anybody know the reason why ...
user avatar
  • 105
0 votes
0 answers
32 views

struct array in a mapping updating

mapping(address => trnsctn[]) private transactionsOfAdress; struct trnsctn{ uint256 when; uint256 amount; } uint256 public ege; function deposit() public payable {...
user avatar
  • 3
0 votes
0 answers
25 views

Retrieving Data from a Mapping Using Web3.py

I am having trouble accessing data from a mapping that I have created on the client-side. My smart contract has 2 functions 1 that sets the values for the mapping. The second one retrieves the values ...
user avatar
0 votes
1 answer
25 views

Get data from mapping whose values are struct and keys as address (msg.sender)

Hey so this is my solidity code, when I am running the getter functions, I am not seeing any output. And as for a fact I don't even know whether the setter functions are even working or not. Please ...
user avatar
0 votes
1 answer
28 views

Iterating over an array Vs Mapping solidity

Which of the two is more efficient. Assuming I have this, uint[] public availableRooms = [1,2,3,4,5,6,7]; And I need to know whether 5 is present in the array above. Which of the two is more ...
user avatar
  • 11
0 votes
1 answer
46 views

How to override an interface function that returns a struct with a mapping

I have an interface with a public function foo that consumes a single address parameter and returns a Point struct: //SPDX-License-Identifier: MIT pragma solidity ^0.8.4; interface IFoo { struct ...
user avatar
0 votes
0 answers
16 views

funtion trigger by user upon claim instead of admin to less GAS fee in solidity

Source code full:https://testnet.bscscan.com/address/0x15c0eb8f845e43a8a46aaa6b025d0e43990f7ec3#code This function is used to allocate winners and only agents can trigger this function. The problem is ...
user avatar
0 votes
1 answer
62 views

How to transfer ERC1155 data(Ownership) mapping from one smart contract to another?

I am developing an NFT Marketplace where I am distributing free NFTs(out of 3 defined categories, Diamond,Gold,Silver). I have developed a dropsite smart contract for this distribution. The dropsite ...
user avatar
0 votes
1 answer
30 views

How to update a struct field from different contract

pragma solidity ^0.8.0; contract Contract1 { struct User { bool isValid; uint value; } mapping(address => User) public party; } ...
user avatar
  • 880
0 votes
1 answer
81 views

"Stack limit reached 1024 (1023)" Error

as you can see in the title, I have the following problem: I have two different types of NFTs in the same contract and I wanted to make transactions way cheaper using a single mapping for knowing the ...
user avatar
0 votes
1 answer
55 views

Is the _numberMinted() function of ERC721A a good replacement for a mapping that stores values for addresses?

The way I've seen it (very stripped down example) (ERC721): uint256 public maxPer = 5; mapping(address => uint256) public countsByAddress; function myMint(uint256 qty) external payable { ...
user avatar
1 vote
1 answer
39 views

Solidity - Struct Array Inside Mapping | How to reference Struct Array Elements?

I am unable to reference struct elements which are inside mapping. Mapping: struct VoterData { string iD; address voterEthAddress; } // One to Many mapping; one Eth ...
user avatar
0 votes
0 answers
75 views

Create an efficient data structure for an order book

I built an NFT marketplace in solidity with Sell, Buy, and Ask orders stored in arrays. I've done some quick test to send a lot of transactions to this contract and fill the arrays with buy orders, ...
user avatar
  • 149
0 votes
0 answers
12 views

I have made a DAO handler by using mapping of daoName and bytes32 and generated a random no. using keccak but the output is still coming 0;

// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; contract DAOManager { mapping(bytes32 => string) public daos; function _registerDAO(string memory daoName) public returns(bytes32){ ...
user avatar
  • 1
-1 votes
2 answers
135 views

How to store all user's data separately to smart contract

What is the best way to store users data on smart contract? Suppose we have n number of users and we want to store each user's username and his/her other details. For example if i enter my wallet ...
user avatar
0 votes
1 answer
130 views

Different number of components on the left hand side (1) than on the right hand side (0)

Need this architecture { address1 => [struct1, struct2], address2 => [struct1, struct2, struct3,], address3 => [struct1, struct2, struct3, struct4, struct5], ... } My ...
user avatar
0 votes
0 answers
16 views

Add the same number to every element in a mapping Solidity

I have a mapping of people providing liquidity to my dex: mapping(address => uint) providers; Every time a swap occurs, a small fee is subtracted for the liquidity providers. I am stuck on how I ...
user avatar
0 votes
1 answer
15 views

Doubt regarding out of gas issue for large data sets

Will this function cause any issues on chain how ever large the mapping becomes? Thank you. mapping (uint256 => TradeHistory[]) public allTrades; //Trade details structure struct TradeHistory {...
user avatar
0 votes
1 answer
64 views

Incrementing a unique return value from a mapping

Let's say I have a mapping called Tries. each time a function is called I want to increment the return value from 0 to x depending on the number of tries (trying to call the function). here's the ...
user avatar
  • 15
0 votes
1 answer
25 views

return a struct from a mapping of addres-struct

I'm trying to return a struct called Trainer from a mapping of addresses -> Trainer Is there any way to easily retrieve the Trainer struct from the trainersMap? struct Trainer { address owner; ...
user avatar
  • 1
0 votes
1 answer
39 views

Array of nested structs

I am trying to write a simple election contract, currently trying to add candidates to an array of Candidates in my Election struct. Can this be done and if so how can it be implemented? The code ...
user avatar
0 votes
1 answer
34 views

Can I take a mapping from one contract, and access it with an interface from anther contract?

Lets say I have a mapping in contract A, which is already deployed.. Can I use an interface in contract B to access the mapping (and the values it links)? If not, is there any way to do this?
user avatar
  • 11
0 votes
0 answers
23 views

Ways to convert for loops in solidity to less gas fee

This function creates games and set the status to create struct Game { uint betId; State state; } uint256 public gameId = 0; mapping(uint => Game) public gameInfo; enum State {...
user avatar
0 votes
0 answers
13 views

Deleting elements in a mapping of mapping in Solidity

I'm using a Solidity mapping of mapping to manage associations between files and users in my application and deleting elements from it like this: mapping(address => mapping(address => uint)) ...
user avatar
  • 111
0 votes
1 answer
27 views

implementing balanceOf in an ERC20 contract (not using openzepellin)

I'm a noob and trying to implement the balanceOf function in a solidity. The standard API is function balanceOf (address account) public returns(uint256) However, I suspect that it needs to read the ...
user avatar
0 votes
1 answer
115 views

Get array in mapping from another contract

I have contract Users, that contains users list and nftInstance: contract Users { struct UserData{ User user; bool exists; } mapping (address => UserData) public users; ...
user avatar
1 vote
1 answer
37 views

Is it safe to check a uint mapping's value >0 in a require?

Context: A common access check or modifier is to use something like: require(boolMapping[msg.sender] == true); to ensure the caller is approved to use a function. Since mapping (address => uint256) ...
user avatar
  • 59
0 votes
0 answers
54 views

Gas cost of mapping lookup and update inside mint transaction compared to getting a variable and then interfacing with another contract function

I have a mint function that does a lookup in a mapping to get some data and then after some computation updates that keys value, and mints. For the specific use case, i've identified an option of ...
user avatar
0 votes
1 answer
60 views

Logical negation, conditions on struct, mappings

I'm still playing around with my first bigger smart contract, and I'm creating something like public sale, ICO, etc. Now I'm at the point where I want to specify some conditions like: one address can ...
user avatar
1 vote
0 answers
159 views

How to change/set values of a mapping through a function in solidity?

I have the following structure, with the mentioned mapping struct A { uint a; bool[100] b; } mapping(uint => A) public arr; I am using this function to set/...
user avatar
1 vote
0 answers
10 views

What are the consequences of a nested mapping?

I'm wondering what the consequences of using a nested mapping are. If I have a mapping that is 4 levels deep, for example: mapping(address => mapping(address => mapping(uint256 => uint256))) ...
user avatar
  • 35
0 votes
1 answer
31 views

How loop on Mapping built with struct?

In my stacking smart contract, User can staken any ERC20 token : struct Token { address tokenAddress; uint256 stakedAmount; uint256 lastTransactionDate; } ... //...
user avatar
  • 157
0 votes
1 answer
42 views

What is the most gas efficient way to read and write to global contract state?

Say I have a complex(list, mapping or struct) global/contract variable. What is the most gas efficient way to update that variable in a function that changes the value of one or more indexes, values ...
user avatar
  • 170
1 vote
2 answers
47 views

How Retrieve a specific entity on mapping

I'm trying to start a stacking smart contract. Each user can stake different ERC20 Token. I'm using follwing struct : struct Token { address tokenAddress; uint256 stakedAmount; ...
user avatar
  • 157
1 vote
1 answer
27 views

Access arrays from public struct mapping?

I have this struct: struct Amendment { string text; uint24 textColor; bool isRadialGradient; uint8[2] radialGradientCenterPct; uint16 linearGradientAngleDeg; uint24[2][11] ...
user avatar
  • 123
0 votes
1 answer
27 views

Requiring a bytes32 mapping to be empty, why does my transaction fail?

I have a contract here: contract source code It's a simple one that allows users to create new key:value mappings with bytes32 variables, as well as update the value of a key given that: the key is ...
user avatar
0 votes
0 answers
35 views

What is the best way to check if a value mapped to an address is smaller than something?

I have a simple mapping of an address mapped to a value. I need to be able to see if any value associated with an address is smaller than a given value. What would be the best way of doing this. I ...
user avatar
0 votes
1 answer
221 views

How to declare getter function signature in interface for a mapping?

I have a contract that implements an interface, the contract has a state variable mapping(address => bytes32[]) public usersLists, I defined a getter function signature in the interface for this ...
user avatar
  • 170
0 votes
1 answer
27 views

How to check if an element exists in mapping?

Let's say I have a custom struct and a mapping: struct MyStruct { uint var1 string var2 bool var3 } mapping(address => MyStruct) myMapping; If I did this: //....... MyStruct elem1 = ...
user avatar
  • 13
0 votes
1 answer
15 views

Mapping both ways

if I want to have a mapping both ways (getting value by key and key by value) is it the most efficient approach to simply initialize 2 mappings pointing in the opposite directions? mapping(uint64 =>...
user avatar

1
2 3 4 5
9