I haven't seen this question asked and answered, so I decided to post it myself.
How to read only some variables from a tuple returned by a function in Solidity?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityI haven't seen this question asked and answered, so I decided to post it myself.
How to read only some variables from a tuple returned by a function in Solidity?
It's simple! Just use commas:
/* SPDX-License-Identifier: LGPL-3.0-or-later */
pragma solidity ^0.7.1;
contract TupleTest {
function foo() public pure returns (uint256 left, uint256 middle, uint256 right) {
return (8, 16, 32);
}
function bar() external pure returns (uint256) {
uint256 middle;
(, middle, ) = foo();
return middle;
}
}
Copy-paste this into Remix and see for yourself.