send" and "transfer" are only available for objects of type "address payable", not "address".
See original GitHub issueHello,
I am working on an NFT contract and can’t figure how to withdraw the ETH from the contract when all my NFT will be minted.
I used the version 4.4 of the project openzeppelin-contracts
pragma solidity >=0.4.22 <0.9.0;
import "/app/openzeppelin-contracts/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "/app/openzeppelin-contracts/contracts/utils/Counters.sol";
import "/app/openzeppelin-contracts/contracts/access/Ownable.sol";
import "/app/openzeppelin-contracts/contracts/utils/math/SafeMath.sol";
contract SimpleContract is Ownable, ERC721Enumerable {
function withdraw() public onlyOwner {
uint balance = address(this).balance;
msg.sender.transfer(balance);
}
}
Here is the error message:
Error: "send" and "transfer" are only available for objects of type "address payable", not "address".
--> <stdin>:102:9:
|
102 | msg.sender.transfer(balance);
|
I got the example from BAYC contract: https://etherscan.io/address/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d#code
Do you know a way to implement this ? The only thing I see different is the code separation from ERC721
and ERC721Enumerable
.
Thanks,
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
ERROR send and transfer are only available for objects of ...
The global variables tx.origin and msg.sender have the type address instead of address payable . One can convert them into address payable ......
Read more >"send" and "transfer" are only available for objects of type ...
TypeError : "send" and "transfer" are only available for objects of type "address payable", not "address". The problem is in this line, I...
Read more >TypeError: "send" and "transfer" are only available ... - YouTube
TypeError: " send" and "transfer" are only available for objects of type " address payable ", not " address "I hope you found...
Read more >Solidity Tutorial : all about Addresses | by Jean Cvllr - Medium
So in Solidity, from the sender perspective: You can send Ether to a variable defined as address payable; You cannot send Ether to...
Read more >“send“ and “transfer“ are only available for objects of type ...
send“ and “transfer“ are only available for objects of type “address payable“, not “address,addresspublicbuyer;buyer.transfer(amount); ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @robinportigliatti
Address payable was introduced by solidity 0.6.0, about 2 years ago. This is documented in their changelog (which also include a section “how to update your code”).
I would also point out that using
msg.sender.transfer(balance)
is also not recommended since 2019: Check out this article to know more.I would encourage you use
Address.sendValue
instead (provided byutils/Address.sol
)Hello,guys this is my structure and function defintion am getting same error in my machine please help me out to solve this…
struct Image { uint id; string hash; string description; uint tipAmount; address payable author; }
images[1] = Image(imageCount, _imgHash, _description, 0, msg.sender);
am not able to use msg.sender