3

What is actually the difference between address payable and payable(_address)

2 Answers 2

1

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!

2
  • It means both the functions are same. either I make the address payable in the function parameter or wrap it inside payable in the function body, it means the same ,right? Commented Sep 18, 2022 at 3:01
  • 1
    Yup! It is upto your convenience. Though I am used to wrap address inside payable because I found it cool. However, do remember you can't wrap the address inside payable when you are declaring a variable. 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
    Commented Sep 18, 2022 at 3:14
3

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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