0

This is my first smart contract that I have tried to build. Got some of this code from another forum (here) Solidity Smart Contract - Split and Send Contract ETH Balance Between Two Accounts.

I am trying to modify it to fit my needs. Essentially, I want a contract that splits earnings to two accounts equally. I was hoping to have the funds send automatically, however the first account (receiving funds from OpenSea) will likely have to manually send funds to smart contract address.

Either way, I thought this code would be nearly complete but I get this error:

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

Is this a new version thing that I am not catching?

Any help is appreciated, thank you.

Also if anyone has any tips on how I can make this contract automatically send funds to two accounts every time another account receives funds, I would really appreciate it.

My code so far:

pragma solidity ^0.8.9;

contract JointEarnings {

address payable account_one = 0x825Ecf093bcC4de26baf8116B74255ADC9b870C5;

address payable account_two = 0xD86Df7757176B75bDFE5783c0E40c0d05eBf7eB7;

uint public balanceContract;

function distribute(uint amount, address payable recipient) public { 
     recipient.transfer(amount);
     balanceContract = address(this).balance;
}

function distribute_equal() public {
     uint amount = balanceContract / 2;
     account_one.transfer(amount);
     account_two.transfer(amount);
     balanceContract = address(this).balance;
}

function deposit() public payable {
    balanceContract = address(this).balance;
 }

function recieve() external payable {}

}

1 Answer 1

1

Here is your issue :

address payable account_one = 0x825Ecf093bcC4de26baf8116B74255ADC9b870C5;
address payable account_two = 0xD86Df7757176B75bDFE5783c0E40c0d05eBf7eB7;

Solidity will never make an address type payable unless explicitly told to.

You have this error because the right hand side is of type address while you are trying to assign it to a variable of type address payable.

Change it to :

address payable account_one = payable(0x825Ecf093bcC4de26baf8116B74255ADC9b870C5);
address payable account_two = payable(0xD86Df7757176B75bDFE5783c0E40c0d05eBf7eB7);

Your function distribute equal could be improved by not relying on .transfer. See this answer.

And your variable :

uint public balanceContract;

is useless, as it's just a reflection of address(this).balance.

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.