Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use returns function to receive multiple values in Solidity

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces how to use the returns function to receive multiple values in Solidity, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Function returns multiple values

/ / function can return multiple values function multipleReturns () returns (uint a, uint b, uint c) {return (1,2,3);}

Receive all return values at the same time

Function processMultipleReturns () {uint a; uint b; uint c; / / do batch assignment like this: (a, b, c) = multipleReturns ();}

Only partial return values are received

/ / or if we just want to return one of the variables: function getLastReturnValue () {uint c; / / you can leave the other fields blank: (, c) = multipleReturns ();}

Problems actually encountered in the project

Function multipleReturns () returns (string memory a, uint b, uint c) {return ("1", 2, 3);} function processMultipleReturns () {string memory a; uint b; uint c; / / to do batch assignment: (a, b, c) = multipleReturns ();} mapping (uint256 = > Tree) public dnaToTree / / obtain encryption asset details function getTreeByDna (uint256 _ Dna) public constant returns (string memory treeByDna_user, uint256 treeByDna_dna,string memory treeByDna_treeName, uint64 treeByDna_birthTime, uint256 treeByDna_needFooder, bytes32 treeByDna_status, bool treeByDna_isAdult) {return (dnaToTree [_ Dna] .user, dnaToTree [_ Dna] .DNA, dnaToTree [_ Dna] .treeName, dnaToTree [_ Dna] .encryption time, dnaToTree [_ Dna]. NeedFooder, dnaToTree [_ Dna]. Status, dnaToTree [_ Dna] .isAdult) } function getTreeByDna_d (uint256 _ Dna) public constant {string memory treeByDna_user; uint256 treeByDna_dna; string memory treeByDna_treeName; uint64 treeByDna_birthTime; uint256 treeByDna_needFooder; bytes32 treeByDna_status; bool treeByDna_isAdult; (treeByDna_user, treeByDna_dna, treeByDna_treeName, treeByDna_birthTime, treeByDna_needFooder, treeByDna_status, treeByDna_isAdult) = getTreeByDna (_ Dna) } on how to use the returns function in Solidity to receive multiple values is shared here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report