In Solidity, this sentence:
(bool sent, ) = msg.sender.call{value: _amount}("");
What is the sense of that "," after sent variable?
Any link to offcial documentation?
Many thanks.
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 communityIn Solidity, this sentence:
(bool sent, ) = msg.sender.call{value: _amount}("");
What is the sense of that "," after sent variable?
Any link to offcial documentation?
Many thanks.
address.call
returns two things: the status of the call (as a boolean), and the returned data of the call (as bytes), in the form of a tuple. The type looks something like (bool success, bytes data)
.
This is a destructuring assignment, as mentinoned by Richard Horrocks in the comments:
(bool foo, bytes bar) = someFunction()
It takes the values in the returned tuple, and assigns them to the variables foo
and bar
. If someFunction
returns two (or more) values in the tuple, but we only care about the first one, we can write it as:
(bool foo, ) = someFunction()
In which case we are not assigning the second variable. Doing this can potentially save some gas. Note that the other way around is also possible:
(, bytes bar) = someFunction()