Reputation: 55
I am confused on why this Error is appearing. Verified that my compiler version is above 0.8.0 version.
Are there best practices when trying to explicitly convert an address to a payable address?
I receive ParserError: Expected ',' but got 'payable' whenever I have "Address" and "payable" next to each other. Like the compiler is not expecting these two keywords together.
function _make_payable(address x) internal pure returns (address payable) {
return payable(address(uint160(x)));
}
The return is where the ParseError appears.
Upvotes: 0
Views: 776
Reputation: 796
I suspect that you tried to do the conversion by writing address payable(uint160(x))
. This is not a valid syntax:
contract C {
function _make_payable(address x) internal pure returns (address payable) {
return (address payable(uint160(x)));
}
}
Error: Expected ',' but got 'payable'
--> test.sol:3:25:
|
3 | return (address payable(uint160(x)));
| ^^^^^^^
Only single-word type names are allowed in type conversions in Solidity. For this reason address payable
can be shortened to just payable
in conversions: payable(uint160(x))
. Note that you need an extra address
conversion there because uint160
cannot be converted to address payable
directly: payable(address(uint160(x)))
. Apparently you have already figured that out because that's the version you're using in your question so the question seems to make no sense.
Upvotes: 0
Reputation: 424
first of all you did not write enough code to see the error you mentioned! But this code you wrote does not give an error!
Also it seems you are trying to convert an address into a payable address, so you declared a function but a simple way to do this conversion is to use payable(address)
build-in function which does the same thing. Also I should mention this may not to be the answer you seek but due to your explanation and code provided I can understand this!
Upvotes: 1