6

I've switched from Solidity 0.7.2 to 0.8.2

And the addresses declared as payable (owner) are reporting they are "NOT payable" in the contract.

pragma solidity ^0.8.2;

contract MyContract {
  address payable public owner;

  constructor(address oracleAddress) {
    owner = msg.sender;
    priceFeed = AggregatorV3Interface(oracleAddress);
  }

Results in..

TypeError: Type address is not implicitly convertible to expected type address payable

Was there a change that in 0.8.2 that causes this? What is the work around?

1
  • i have the same problem, i did whut you said, but iam still getting: ParserError: Expected primary expression. payable(owner).transfer(address(this).balance); ^-----^ any suggestions? – Angelo May 10 at 17:45
12

From Solidity 0.8.0 you don't need to declare the address as payable explicitly, but when you are transferring an amount to such address.

See your example below in 0.8.x, adding a function to transfer funds to the owner:

contract MyContract {
  address public owner;

  constructor(address oracleAddress) {
      owner = msg.sender;
      priceFeed = AggregatorV3Interface(oracleAddress);
  }
  
  function transfer() public payable {
      payable(owner).transfer(msg.value);
  }
}

For further reference, you can check the breaking changes in Solidity documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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