0
address[] emp = [address1,address2];
amount = total/emp.length;
for(uint256 i=0;i<employees.length;i++)
{
    wallet = emp[i];
    wallet.transfer(amount);
}

So This is the error I get.

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

wallet = emp[i]; ^-----^

Help would be appreciated!

1 Answer 1

0

An address needs to be of type payable if you want to send Ethers into it.

Looking at the answer here (and its comments): Member function "transfer" not found or not visible after argument-dependent lookup in contract? you can convert a regular address into address payable through uint160:

Converting address to address payable is possible via conversion through uint160

So something like this seems to be at least compile:

address a = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c;
uint160 b = uint160(a);
address payable c = address(b);
6
  • 1
    Just change address[] emp to address payable[] emp, right?
    – user19510
    Commented Sep 27, 2019 at 6:45
  • I guess that'd work, if the address1 and address2 are actually written out and not variables of type address. Commented Sep 27, 2019 at 7:43
  • No @smarx that wouldn't work I have tried it says "identifier expected but got payable"
    – vteja711
    Commented Sep 27, 2019 at 8:36
  • 1
    The solution of converting it works perfectly
    – vteja711
    Commented Sep 27, 2019 at 8:36
  • @vteja711 Not sure what went wrong, but address payable[] emp is certainly legal Solidity syntax and how you declare an array of address payables.
    – user19510
    Commented Sep 27, 2019 at 16:40

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.