TransWikia.com

Access Tuples elements

Ethereum Asked by martasaparicio on December 13, 2021

I have the following tuple:

( , , uint256 standardDepositAmount, , )

I need to use the standardDepositAmount in a require, like:

require(standardDepositAmount == something)

how can i do that?

One Answer

You can find more information in the Solidity official documentation, but it's important to note that:

Tuples are not proper types in Solidity, they can only be used to form syntactic groupings of expressions.

For this reason, in your case you should be able to read the standardDepositAmount variable without doing anything more, because it is already defined as uint256 and it is (probably) already assigned.

Here a working example where the require function is satisfied:

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.8.0;

contract myContract {
    uint index;

    function myFunction() public {
        ( , , uint256 standardDepositAmount, , ) = returnTuple();
        require(standardDepositAmount == 3);
        // do something...
    }
    
    function returnTuple() public pure returns (uint, uint, uint, uint, uint) {
        return (1, 2, 3, 4, 5);
    }
}

I created a gist for you. You can also do other experiments using Remix and the above smart contract following this link.

Answered by Giuseppe Bertone on December 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP