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
121 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
- SQL FIFO STACK using two tables
- C++ assign const reference to instance variable (memory issues?)
- Efficient retrieval of last and second to last element of ArrayStack in Scala?
- How to implement Exception for function isFull() on Stack
- Merging two sorted stacks
- MASM console window creation troubles (maybe my stack frame??)
- Why does the Java.Util.Stack not pop last element in the loop?
- popStack pops out data that I didn't push (stack adt)
- kill function from ISR on cortex-m0
- Why in C++ overwritingis is slower than writing?
- why does a integer type need to be little-endian?
- fread(), solaris to unix portability and use of uninitialised values
- How can I have different color for each bar of stack barplots? in R
- Stack with push and pop functions not working
- c++ memory allocated at compile time
Related Questions in BLOCKCHAIN
- Blockchain receive API with same address
- panic: runtime error: invalid memory address or nil pointer dereference when running Blockchainr
- Cannot "Query" hyperledger-fabric, error code -32003
- Why is transactions not always record to the block? - Blockchain PBFT
- Hyperledger on Bluemix: Failed to launch chaincode spec(Could not get deployment transaction
- Connect to Multichain network using aws EC2
- Deploying Ethereum Private Network
- Does the "holy trinity" (Ethereum, Swarm and Whisper) support multimedia streaming?
- Hyperledger Fabric v0.6 using Docker Toolbox
- What is the ibm bluemix blockchain port for events?
- Unable to deploy Hyperledger Java chaincode via Github
- How to accurately measure the effort required to reduce a λ-term?
- IBM Blockchain (Hyperledger) - "Error when deploying chaincode"
- Transaction via Blockchain API using Multiple recipients
- Computing acoustic fingerprint in a distributed manner without exposing the whole file to any participant
Related Questions in SMARTCONTRACTS
- Automatic Transfer of Token in Solidity Contract
- How to test smart contract with cross-contract invoke using truffle?
- How to accurately measure the effort required to reduce a λ-term?
- How do display all the events logs from a smart contract?
- sending ether to external address using fallback function in an ethereum contract
- Creating instance of contract inside another contract and calling it's methods results in thrown exception
- How can I include real world data in a smart contract?
- Where in Ethereum blockchain do transaction details of a smart contract get written?
- Is is possible to access public structure fileds in NEAR smart-contract without a function?
- NEAR Protocol - What happens when Rust contract method args are declared as (&mut self, ...) vs. (&self, ...)?
- NEAR Protocol Rust contracts - what's the difference between near-sdk-rs data structures and std ones?
- smart contract gas cost
- How to check if a NEAR account has a smart-contract deployed and implements a required interface?
- Making a Dapp, getting an error: setProvider is not defined?
- Solidity: problem creating a struct containing mappings inside a mapping
Related Questions in CLARITY
- How can I disable check box that is part of Clarity datagrid?
- Set stepper in second step in clarity design angular
- How to get rid of the blurry fonts for menus when using WPF?
- CA Clarity and TFS integration
- reduce same function call inside ngFor loop
- Deactivating Custom ARIA Label in Clarity Design Table (AngularJS)
- Microsoft Clarity: screen recording pauses when there is inactivity
- By deleting microsoft clarity script my nextjs application breaks
- Image clarity is losses after executing some codes in flutter
- How to join two utf8 strings together in Clarity?
- Clarity + Angular6: Tree View Node Listener (clr-tree-node)
- How to perform the calculation details for field ETC(Cost) in Clarity PPM?
- Clarity modal does not work properly with ngFor
- Tree View W/ the Vertical Nav
- Clarity Wizard - Jump to page X on open (clrWizardOpenChange)
Related Questions in CLARITY-LANG
- How to join two utf8 strings together in Clarity?
- 'clarinet integrate' quickly fails and nothing is logged to console?
- How to set up an environment to write/test Clarity smart contracts within a Django project
- Is there a way to externally listen to (contract-call? ...) calls on a contract?
- Can not get .bns name from userSession.loadUserData() in React app using the Stacksjs package
- Clarity conversion string to uint
- How to get a particular value from a map
- How to require a true value in Clarity smart contract?
- Define Non Fungible Token - Stacks Clarity Smart Contract
- Clarity Smart contract validate principal calling public function
- Clarity Smart Contracts Check if function caller is contract
- Start new project, time-locked wallet - Clarity Smart Contracts for Stacks
- Stacks Clarity language Post-Conditions
- Stacks Clarity Smart Contracts with question mark
- Print current value of missing variables during manual testing - Clarity Smart Contract
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 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