Skip to content

sovrgn/paymentDistributor

Repository files navigation

paymentsDistributor

Overview

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.

Key Features:

  • 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.

Contract Functions

Constructor

constructor(address _websiteAddress, uint256 _websiteFeePercent)

Initializes the website's address and fee percentage.

setWebsiteAddress

function setWebsiteAddress(address _websiteAddress) external onlyOwner

Updates the website's address.

setWebsiteFeePercent

function setWebsiteFeePercent(uint256 _websiteFeePercent) external onlyOwner

Updates the website's fee percentage.

pay

function pay(
  address payable sellerAddress,
  address payable referrerAddress,
  uint256 referrerFeePercent,
  uint256 contentID
) external payable

Handles payment and distribution to the seller, referrer, and website.

withdraw

function withdraw() external onlyOwner

Allows the contract owner to withdraw undistributed or accidental Ether.

Testing the PaymentDistributor Contract

Pre-requisites

  • Node.js and NPM
  • Hardhat and necessary dependencies

Installation

  1. Clone the repository.
  2. Navigate to the project directory.
  3. Run npm install.

Running Tests

Execute npx hardhat test in the terminal.

Test Suite Overview

  • Deployment Tests: Validate contract initialization.
  • Transaction Tests: Confirm correct Ether distribution among parties.
  • Owner Functionality Tests: Validate owner-specific operations and state changes.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •