What is actually the difference between address payable and payable(_address)
- 3,619
- 1
- 8
- 25
2 Answers
address payable defines a payable address, that can receive ETH.
payable(_address) casts _address into a payable one.
As an output, it's the same.
- 583
- 2
- 7
If you want an address to be able to accept ether, you should make it payable.
address payable ICanReceiveEth
Now lets say you want to assign an address to ICanReceiveEth variable, there you should wrap the address with the payable.
function(address Add_) public {
ICanReceiveEth = payable(Add_)
}
However, you can also declare like this.
function(address payable Add_) public {
ICanReceiveEth = Add_
}
It is entirely upto you!
Simply, by wrapping an address inside the payable you are telling the compiler that "this address is capable of accepting ether."
And if you try to declare without payable like this:
function(address Add_) public {
ICanReceiveEth = Add_
}
You will get an error like this:
TypeError: Type address is not implicitly convertible to expected type address payable.
From this, you can figure it out that the plain address, and payable address are an entirely different as former isn't capable of accepting ether while the later can.
Tell me if it helps!
- 958
- 2
- 12
address payable variable; (This is correct way)
address payable(variable); (Compiler will throw an error).
You can only wrap the variable or address with payable inside a function.
– Ad-h0c Sep 18 '22 at 03:14