Solidity casting address to address payable

0 votes

I have written a solidity program in which one function has an address that I have to send tokens to. I read somewhere that to send tokens to an address, it should be declared as payable. I am not able to figure out how to do it. I tried direct casting:

address payable variable_name;

It is not working for me. Please help.

Jan 23, 2019 in Blockchain by Kunal
8,061 views

1 answer to this question.

0 votes

I don’t see why direct casting isn’t working, maybe some permission issues. Anyways, you can cast address using different ways. Try this:

address addr = 0x****;
address payable wallet = address(uint160(addr));

Let me know if it works.

answered Jan 23, 2019 by Omkar
• 69,220 points

According to Solidity documentation:

"Implicit conversions from address payable to address are allowed, whereas conversions from address to address payable are not possible (the only way to perform such a conversion is by using an intermediate conversion to uint160)."

Thus,  address(uint160(addr)); works fine!





Related Questions In Blockchain

0 votes
1 answer

How to get all address and send ethers in solidity using a loop?

I found a similar code somewhere: contract  Holders{ uint ...READ MORE

answered Jul 31, 2018 in Blockchain by digger
• 26,740 points
2,769 views
0 votes
1 answer

Solidity: Code to hide message sender address (msg.sender) when writing on a contract

Hey @Wilson, You can use a smart contract ...READ MORE

answered Sep 14, 2020 in Blockchain by Rajiv
• 8,870 points
2,024 views
+1 vote
2 answers

How to convert INT to STRING in Solidity?

Look at the following code : function uintToString(uint ...READ MORE

answered Jun 27, 2018 in Blockchain by Christine
• 15,790 points
12,503 views
0 votes
1 answer

How to set web3 solidity variable value?

The setLog transaction has not yet been mined by ...READ MORE

answered Jul 6, 2018 in Blockchain by Christine
• 15,790 points
2,160 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,946 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,470 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,220 points
1,487 views
0 votes
0 answers

Error: Unexpected token o in JSON at position 1

I have been working with Interacting a ...READ MORE

Mar 6, 2019 in Blockchain by saeedi
• 120 points

edited Mar 6, 2019 by Omkar 2,511 views
+3 votes
3 answers

How to validate bitcoin address?

I found these 2 scripts online: Javascript: <html> <head> <script type="text/javascript" ...READ MORE

answered Aug 17, 2018 in Blockchain by slayer
• 29,370 points
6,569 views
0 votes
2 answers

How to check if bitcoin address is valid?

For Java, have a look at the ...READ MORE

answered Aug 20, 2018 in Blockchain by Omkar
• 69,220 points
3,258 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP