Skip to content

Repository files navigation

Web3 Contract

Smart Contract Infrastructure for E-Collector Marketplace

Solidity Hardhat OpenZeppelin License: MIT

A production-grade Solidity smart contract suite powering decentralized product voucher trading with escrow, royalties, and role-based access control.


Architecture | Contracts | Quick Start | Testing | Deployment

Architecture

                    +------------------+
                    |  TokenFactory    |  Permissionless token deployer
                    |  (Registry)      |  with on-chain registry
                    +--------+---------+
                             |
                    deploys  |  creates Token instances
                             v
              +-----------------------------+
              |          Token (ERC20)       |
              |  Permit | Pausable | RBAC   |
              +-------------+---------------+
                            |
              +-------------+---------------+
              |                             |
     +--------v--------+          +--------v--------+
     |   Marketplace    |          |   ProductNFT    |
     |  Escrow Trading  |          |  ERC721+ERC2981 |
     |  Dispute Arbitr. |          |  Royalties &    |
     |  Platform Fees   |          |  Provenance     |
     +-----------------+          +-----------------+

Contracts

Token.sol -- Product Voucher Token

Feature Detail
Standard ERC20 + Burnable + EIP-2612 Permit (gasless approvals)
Access AccessControl -- MINTER_ROLE, PAUSER_ROLE
Safety ReentrancyGuard, Pausable emergency circuit breaker
Supply Immutable maxSupply cap (0 = unlimited)
Gas Custom errors save ~30% vs require strings

TokenFactory.sol -- Token Deployer & Registry

Feature Detail
Pattern Factory + full on-chain registry
Index Global list + per-creator mapping + isRegistered check
Query Single / batch / paginated (getTokensBatch)
Economics Configurable deploy fee with admin withdrawal

Marketplace.sol -- Trustless Escrow Trading

Feature Detail
Model Escrow-based: tokens locked on list, ETH locked on purchase
Flow List -> Purchase -> Ship -> Confirm Delivery
Disputes ARBITER_ROLE resolves -- refund buyer or release to seller
Fees Configurable platform fee (default 2.5%, max 10%)
Safety ReentrancyGuard, Pausable, SafeERC20

ProductNFT.sol -- Product Certificate NFT

Feature Detail
Standard ERC721URIStorage + Enumerable + ERC2981 Royalties
State Machine Minted -> Listed -> Sold -> Redeemed -> Shipped -> Delivered
Provenance Auto-incremented tradeCount on every transfer
Query By merchant, batch query support

Quick Start

# Clone
git clone https://github.com/MichaelYang-lyx/Web3_contract.git
cd Web3_contract

# Install
npm install

# Compile
npx hardhat compile

# Test
npx hardhat test

# Test with gas report
REPORT_GAS=true npx hardhat test

Testing

25+ test cases covering:

  • Token creation, minting, burning, role-based access
  • Factory registry, batch queries, deploy fees, pause mechanism
  • Full marketplace flow: list -> purchase -> ship -> confirm
  • Dispute resolution and arbiter refund
  • Platform fee collection and withdrawal
  • Edge cases: excess ETH refund, unregistered tokens, empty inputs
npx hardhat test

Deployment

Supports multi-chain deployment:

Network Command
Local npm run deploy:local
Sepolia Testnet npm run deploy:sepolia
Axiomesh npm run deploy:axiomesh
# Create .env
cp .env.example .env
# Edit with your PRIVATE_KEY, RPC URLs, ETHERSCAN_API_KEY

# Deploy to Sepolia
npm run deploy:sepolia

The deploy script automatically:

  1. Deploys TokenFactory, Marketplace, ProductNFT
  2. Links Marketplace to Factory
  3. Verifies contracts on Etherscan

Tech Stack

  • Solidity 0.8.20 with IR optimizer
  • OpenZeppelin Contracts v5 (AccessControl, ERC2981, SafeERC20, Pausable)
  • Hardhat with TypeScript, gas reporter, Etherscan verification
  • EIP-2612 Permit for gasless token approvals

License

MIT

About

Web3 smart contract

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages