question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

send" and "transfer" are only available for objects of type "address payable", not "address".

See original GitHub issue

Hello,

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:closed
  • Created 2 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Amxxcommented, Dec 9, 2021

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 by utils/Address.sol)

0reactions
Keyur5123commented, Aug 5, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found