Created
June 19, 2022 12:43
-
-
Save Chmarusso/1238d60200be64caca965b9e31245101 to your computer and use it in GitHub Desktop.
This smart contract will automatically divide the payment amount and push it to specified recipients.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
hi, you can split the earnings / eth by below method as well
`// SPDX-License-Identifier: MIT
// Author BABAR R.
pragma solidity >=0.8.9 <0.9.0;
import 'erc721a/contracts/ERC721A.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/utils/Strings.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
contract SendOnMint is ERC721A, Ownable, ReentrancyGuard {
using Strings for uint;
string public uriPrefix = '';
string public uriSuffix = '.json';
uint public cost = 0.003 ether;
uint public maxSupply = 20;
uint public maxMintAmountPerTx = 20;
address[] private teamAddress;
uint[] private teamSplit;
bool public paused = false;
constructor(
address[] memory _team,
uint[] memory _split,
string memory _baseUri
) ERC721A("Send", "SND") {
addTeam(_team, _split);
setUriPrefix(_baseUri);
}
// ~~~~~~~~~~~~~~~~~~~~ Modifiers ~~~~~~~~~~~~~~~~~~~~
modifier mintCompliance(uint256 _mintAmount) {
require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, 'Invalid mint amount!');
require(totalSupply() + _mintAmount <= maxSupply, 'Max supply exceeded!');
_;
}
// ~~~~~~~~~~~~~~~~~~~~ Mint Functions ~~~~~~~~~~~~~~~~~~~~
function mint(uint _mintAmount) public payable {
require(!paused, 'The contract is paused!');
require(msg.value >= cost * _mintAmount, 'Insufficient funds!');
internalWithdraw(msg.value);
_safeMint(_msgSender(), _mintAmount);
}
function mintForAddress(uint _mintAmount, address _receiver) public mintCompliance(_mintAmount) onlyOwner {
_safeMint(_receiver, _mintAmount);
}
// ~~~~~~~~~~~~~~~~~~~~ Various Checks ~~~~~~~~~~~~~~~~~~~~
function _baseURI() internal view virtual override returns (string memory) {
return uriPrefix;
}
function tokenURI(uint _tokenId) public view virtual override returns (string memory) {
require(_exists(_tokenId), 'ERC721Metadata: URI query for nonexistent token');
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix))
: '';
}
// ~~~~~~~~~~~~~~~~~~~~ onlyOwner Functions ~~~~~~~~~~~~~~~~~~~~
function setCost(uint _cost) public onlyOwner {
cost = _cost;
}
function setMaxMintAmountPerTx(uint _maxMintAmountPerTx) public onlyOwner {
maxMintAmountPerTx = _maxMintAmountPerTx;
}
function setUriPrefix(string memory _uriPrefix) public onlyOwner {
uriPrefix = _uriPrefix;
}
function setUriSuffix(string memory _uriSuffix) public onlyOwner {
uriSuffix = _uriSuffix;
}
function setPaused(bool _state) public onlyOwner {
paused = _state;
}
function addTeam(address[] memory _team, uint[] memory _split) public onlyOwner {
require(_team.length == _split.length,'Team array and amount array must be the same length!');
teamAddress = _team;
teamSplit = _split;
}
// ~~~~~~~~~~~~~~~~~~~~ Withdraw Functions ~~~~~~~~~~~~~~~~~~~~
function internalWithdraw(uint _amount) internal {
for(uint i = 0; i < teamAddress.length; i++) {
uint split = teamSplit[i];
(bool os, ) = payable(teamAddress[i]).call{value: _amount * split / 100}('');
require(os);
}
}
function teamWithdraw() public {
internalWithdraw(address(this).balance);
}
function emergencyWithdraw() public onlyOwner nonReentrant {
(bool os, ) = payable(owner()).call{value: address(this).balance}('');
require(os);
}
fallback() external payable {
// custom function code
}
receive() external payable {
// custom function code
}
}`
This is my approach
Great code! thanks for the contribution, ill try it
ipfsHash transfers the multiple account . is that possible to work this method.
@iamrakki can you explain more please??
One ipfsHash share the multiple account addresses
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
its transferring amount equally, is it possible to transfer amount as per share like one wallet 45%, and another wallet 55% and so on.