Skip to content

Instantly share code, notes, and snippets.

@legaciespanda
Forked from Chmarusso/PaymentSplitter.sol
Created June 23, 2022 08:43
Show Gist options
  • Save legaciespanda/09f7a4b325d4736ebdcef75a0420fe54 to your computer and use it in GitHub Desktop.
Save legaciespanda/09f7a4b325d4736ebdcef75a0420fe54 to your computer and use it in GitHub Desktop.
This smart contract will automatically divide the payment amount and push it to specified recipients.
pragma solidity ^0.8.15;
// SPDX-License-Identifier: MIT
contract PaymentSplitter {
address payable [] public recipients;
event TransferReceived(address _from, uint _amount);
constructor(address payable [] memory _addrs) {
for(uint i=0; i<_addrs.length; i++){
recipients.push(_addrs[i]);
}
}
receive() payable external {
uint256 share = msg.value / recipients.length;
for(uint i=0; i < recipients.length; i++){
recipients[i].transfer(share);
}
emit TransferReceived(msg.sender, msg.value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment