ESHStoreSales

ESHStoreSales

Shop for Sells of services or properties using the USDC as payment and your ESH Coin as a stock and rewards

  • Publish Date

    Jan 25, 2026

  • Licenses

    MIT,

ESHStoreSales Smart Contract

A robust Solidity-based retail management system designed for secure product sales, automated reward distribution, and verifiable digital receipts using NFTs. This contract integrates with an invoice system to mint receipt NFTs and supports a multi-tier distribution model for store profits.


🚀 Key Features

  • Inventory Management: Add, edit, and track products using unique barcodes.
  • Secure Purchases: Off-chain signature verification (ECDSA) to ensure only authorized requests from your server can trigger a purchase.
  • Refund System: A built-in 14-day refund window with automatic NFT burning upon refund.
  • Reward Pool: Incentivize buyers with a secondary reward token for every purchase made.
  • Automated Distributions: Ability to distribute store profits quarterly to stakeholders via an external distribution interface.
  • Financial Security: Uses ReentrancyGuard to prevent reentrancy attacks and multi-step balance releases.

🏗 Workflow Diagram


🛠 Contract Architecture

Core Components

  • Token Interface: Interacts with IERC20Flat for primary payments and a reward token for loyalty points.
  • Invoicing: Integrates with an IInvoice contract to mint/burn NFTs that represent proof of purchase.
  • Signer Verification: Requires a serverSigner signature for purchaseProduct to prevent front-running or unauthorized price manipulation.

Important Constants

  • Refund Period: 14 days
  • Transaction Fee: Fixed at 5% for worker payments and profit distributions.

📖 Function Reference

For the Store Owner

FunctionDescription
addProductInitializes a new product with name, price, quantity, and metadata.
editProductUpdates existing product details (description, images, category).
batchReleaseFundsMoves funds from "pending" (purchased) to "available balance" once the 14-day refund period passes.
refundClientManually processes a refund, burns the associated NFT, and returns tokens to the user.
distributeQuarterlyBalanceStarts a multi-call distribution process for a percentage of the store's balance.

For the Customer

FunctionDescription
purchaseProductThe primary entry point. Requires an amount, metadata, and a valid server signature.
verifyReceiptAllows a user to verify if a specific receipt ID belongs to them.
getAllReceiptsByWalletAddressReturns the full history of purchases for a specific user.

🔒 Security & Roles

  • Owner Only: Critical administrative tasks like setting the serverSigner, adding products, and triggering distributions are protected by the onlyOwner modifier.
  • Non-Reentrant: All state-changing functions dealing with token transfers are protected against reentrancy.
  • Signature Deadline: The purchase function includes a _deadline parameter to prevent replay attacks using old signatures.

📦 Deployment & Setup

  1. Prerequisites: Ensure you have the addresses for the Payment Token (ERC20), the Reward Token, and the Invoice NFT Contract.
  2. Constructor:
  • _ERCUltra: The address of your Reward Token.
  • _invoices: The address of the IInvoice NFT contract.
  • _contractOwner: The initial admin address.
  1. Post-Deployment: Call setServerSigner() to designate the backend wallet that will authorize purchases.

📄 Events

The contract emits detailed logs for transparency:

  • ProductAdded: When new inventory is stocked.
  • NewReceipt: Detailed data for every successful purchase.
  • FundsReleasedToBalance: When the owner claims funds after the refund window.
  • DistributionStarted: Tracks the initiation of profit sharing.

Balance

view

No inputs required