2

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?

2

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.