Want to start off by saying thanks in advance. I'm very new to solidity, so really appreciate your time.

I've built a basic smart contract for testing purposes, and I'm running it on Remix.

I want to define a function (withdraw_equal) that allows the balance of the smart contract (say 4 eth) to be split in half and sent out to the two accounts evenly) (i.e. 2 eth to account_one as well as 2 eth to account_2.

Here's my code:

pragma solidity ^0.5.0;

contract JointSavings {
  address payable account_one = 0xc3879B456DAA348a16B6524CBC558d2CC784722b;
  address payable account_two = 0xA29f7E79ECEA4cE30DD78cfeb9605D9aFt5143a3;

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

  function withdraw_equal() public {
    uint amount = balanceContract / 2;
    balanceContract = address(this).balance;

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

  function() external payable {}


I'm conscious that the 'withdraw' function works because 'address payable' is included as an input parameter. However, as the 'withdraw_even" function doesn't take any parameters, I'm not quite sure how to adapt my code.

P.S. I'm just messing around and experimenting here, so feel free to send through any fun tweaks / suggestions / additions you might have to fix / update /enhance the code. Thanks in advance!

  • Can you clarify what's the issue? What are you trying to achieve and what you do not understand?
    – Ismael
    Commented Jul 4, 2021 at 18:30

2 Answers 2


seems pretty explanatory to me.... in case you missed it he wants to create a function and then call that function from the pay address function. i interpret his question as asking, "can i hand off the payment to a subfunction". look at payment splitter under open zeppelin. you should be able to fathom your own code from that. https://forum.openzeppelin.com/t/using-paymentsplitter-with-remix/3007


I agree with @macguyver about using open zeppelin's payment splitter, you can either import it into your contract or deploy it as a seperate contract.

You can also spawn a cloneable instance of a payment splitter at PaymentSplitter.io. Cloning an instance is cheaper on gas than deploying the contract code, no matter whether it's an independent contract or part of another contract bundle. Full disclosure, I built the Web UI for it!

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.