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
+------------------+
| 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 |
+-----------------+ +-----------------+
| 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 |
| 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 |
| 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 |
| 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 |
# 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 test25+ 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 testSupports 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:sepoliaThe deploy script automatically:
- Deploys TokenFactory, Marketplace, ProductNFT
- Links Marketplace to Factory
- Verifies contracts on Etherscan
- 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
MIT