In my contract I have a map with a principal as its key and a tuple as its value. I want to get a particular value from the value-tuple for every principal in the map.
Let's say I want to get the salary for every member from the map below.
(define-map members principal {position: (string-ascii 30), salary: uint})
How to get a particular value from a map
122 Views Asked by Oyeinbomo At
2
There are 2 best solutions below
0
Kenny
On
You can use Clarity's get function in conjunction with map-get:
Example:
(define-map members principal {position: (string-ascii 30), salary: uint})
(map-set members 'ST3QFME3CANQFQNR86TYVKQYCFT7QX4PRXM1V9W6H {position: "test", salary: u500})
(print (get salary (map-get? members 'ST3QFME3CANQFQNR86TYVKQYCFT7QX4PRXM1V9W6H)))
And a link to Clarity's get function demonstrating this usage: https://docs.stacks.co/docs/write-smart-contracts/clarity-language/language-functions#get
However, you can't iterate through a map, you need to know the key to look up data, so if you wanted to iterate, you would need a list of all the principals and iterate through that using the map function, looking up the corresponding principal in the map on each iteration.
Related Questions in STACK
- What is causing my towers of hanoi logic to infinitely loop?
- Asking code suggestions about data structure and algorithm
- Why is 'EDITBIN /STACK:2097152 w3wp.exe' cmd is giving me an LNK1342 error?
- issues with circular queues
- Missing PAGE_GUARD flag on the memory of stack for one windows application
- Purpose of stack register(s) in holding 0x7c00
- Split Dataframe and stack horizontally
- segmentation fault (core dumped) in C programming
- How to find Find max right using stack?
- Does an Stackoverflow occur in the JVM if the Activation Record is too small but there is still space left in the general stack?
- How to create 100 maps with bootstrapping using stacked ensemble fit with tidymodels
- How does the class Exchanger in Java actually work?
- How can I improve the iterative approach to be faster than recursive implementation, as usual?
- Need to make Stack cards on nav click as well ass page scroll with help of jquery
- Puncover: Stack column is empty after analysis
Related Questions in BLOCKCHAIN
- Sepolia test network ID
- Gas Estimation Fee on Tron Mainnet
- This is the solidity code to list nft in marketplace after minting but while calling makeItem function Error is showing that Faliled to estimate gas
- Trying to send transactions via a signer using my private key
- My question is regarding installation of a package in VS code but im getting an error in installing it
- Historical data scrapping / collection for Ethereum
- Installation Private Blockchain
- How to import rpc information without importing .env file or hardcoding on frontend?
- How do I speed up transaction filtering on solan blockchain?
- Undeclared identifier: VRF_V2_Wrapper.calculateRequestPrice()
- how to interpret and format iterest rates and index returned by aave event
- Can I swap with 1inch swap apis with forked hardhart?
- How to connect metamask to flutter mobile app
- Scraping 'offers' data from OpenSea
- Which web3 decentralized wallet is suitable to store my crypto assets and lock some of the tokens for certain time?
Related Questions in SMARTCONTRACTS
- Gas estimation failed | Returned error: gas required exceeds allowance (16966)
- This is the solidity code to list nft in marketplace after minting but while calling makeItem function Error is showing that Faliled to estimate gas
- how i need place arg in code for funtion send?
- Uniswap v3 flashloan remainging balance not correct after paying off the loan
- Blind signing when trying to send USDT over Arbitrum network
- connecting trust wallet mobile to my dapp
- Solidity Smart Contract & Hedera Hashgraph Javascript SDK Integration
- Trying to interact with a contract using is function selector, how do i get the block hash?
- a sales tax on stonfi or dedust (The Open Network)
- After issuing the NFT smart contract I made, it cannot be viewed by OpenSea
- no scripts folder in hardhat framework instead there's ignition folder with a subfolder named modules
- Ensure smart contract integrity in web applications
- How to generate multi hop swap path with ethers.js?
- How does the fee get calculated in hardhat?
- Function for returning a wallet balance
Related Questions in CLARITY
- Where does this PrimeNG element get its color and how do I change it?
- 403 Forbidden error when trying to access the Clarity REST API
- MS Clarity cpaturing unformated page when bluring info
- Clarity does not give insights in traffic when combined with Viva connection?
- Image clarity is losses after executing some codes in flutter
- Microsoft Clarity: screen recording pauses when there is inactivity
- By deleting microsoft clarity script my nextjs application breaks
- Deactivating Custom ARIA Label in Clarity Design Table (AngularJS)
- reduce same function call inside ngFor loop
- Can I make an action before delete an entity that already selected in clarity combobox?
- VMware Clarity Wizard: How to make all pages active or clickable
- Has there been a recent update with Microsoft Clarity identifiers?
- How to correctly use react-native-clarity in a React Native app?
- Microsoft’s Clarity breaks down CSS and does not upload background images
- Website interface does not appear in recordings and heatmaps
Related Questions in CLARITY-LANG
- Public function smart contract Clarity Stacks
- Unit Test Clarity Language
- Fold or map function & pass in list as parameter Clarity Smart contracts
- Question regarding this notice in Clarity extension
- Print current value of missing variables during manual testing - Clarity Smart Contract
- Clarity Smart contract function loop if error
- Where can I find a list of all operations possible on lists and maps for Clarity Smart Contracts?
- Clarity Smart contract validate principal calling public function
- Define Non Fungible Token - Stacks Clarity Smart Contract
- Define functions expression - Clarity Smart contract Stacks
- Running Clarity Smart Contracts u0 u1 u2 function
- Start new project, time-locked wallet - Clarity Smart Contracts for Stacks
- Clarity Smart Contracts Check if function caller is contract
- Stacks Clarity Smart Contracts with question mark
- Stacks Clarity language Post-Conditions
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You need to use
map-getCheck this examples
Or