The PaymentDistributor
contract is an Ethereum smart contract designed to automate the process of accepting and distributing Ether payments. The main functionality allows a sender to submit a payment that will be automatically distributed among a seller, a referrer, and the website's address.
- Ownable: Inherits from OpenZeppelin's
Ownable
, making certain functions accessible only by the contract's owner. - Website Fee: Takes a percentage fee from each payment for the website's address.
- Referrer Fee: Optionally assigns a fee for a referrer if the address is not the zero address.
- Safety Checks: Ensures percentages do not exceed 100% and validates non-zero addresses for sellers.
constructor(address _websiteAddress, uint256 _websiteFeePercent)
Initializes the website's address and fee percentage.
function setWebsiteAddress(address _websiteAddress) external onlyOwner
Updates the website's address.
function setWebsiteFeePercent(uint256 _websiteFeePercent) external onlyOwner
Updates the website's fee percentage.
function pay(
address payable sellerAddress,
address payable referrerAddress,
uint256 referrerFeePercent,
uint256 contentID
) external payable
Handles payment and distribution to the seller, referrer, and website.
function withdraw() external onlyOwner
Allows the contract owner to withdraw undistributed or accidental Ether.
- Node.js and NPM
- Hardhat and necessary dependencies
- Clone the repository.
- Navigate to the project directory.
- Run
npm install
.
Execute npx hardhat test
in the terminal.
- Deployment Tests: Validate contract initialization.
- Transaction Tests: Confirm correct Ether distribution among parties.
- Owner Functionality Tests: Validate owner-specific operations and state changes.