Skip to content

Burstall/hedera-SC-minter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

103 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hedera Smart Contract Minter Suite

A comprehensive collection of NFT minting contracts for the Hedera network
Version: 2.0 (v1.0 for ForeverMinter, SoulboundBadgeMinter)
Solidity: 0.8.18
Branch: refactor-base-minter


Overview

This repository provides four specialized NFT minting contracts, each optimized for different use cases on the Hedera network. All contracts support $LAZY token integration, whitelist systems, and are production-ready with comprehensive testing.

🎯 Quick Contract Selector

Need transferable NFTs?

  • Standard sales β†’ MinterContract
  • Pool-based distribution with royalties β†’ ForeverMinter

Need soulbound (non-transferable) NFTs?

  • Single badge/certificate type β†’ SoulboundMinter
  • Multiple badge types in one contract β†’ SoulboundBadgeMinter

Contract Comparison

Feature MinterContract SoulboundMinter ForeverMinter SoulboundBadgeMinter
Token Type Transferable NFT Soulbound NFT Transferable NFT Soulbound NFT
Distribution Create & mint Create & mint Pool-based Create & mint
Primary Use Case Standard NFT sales Badges/Certificates Complex distribution Multi-badge system
Transferability βœ… Yes ❌ No (Frozen) βœ… Yes ❌ No (Frozen)
Royalty Compliance ❌ Bypassed N/A βœ… Respected N/A
Whitelist System βœ… Address + Token-gated βœ… Address + Token-gated βœ… Address + Holder βœ… Per-badge whitelist
Payment Types HBAR + $LAZY HBAR + $LAZY HBAR + $LAZY HBAR only
Discount Types WL only WL only WL + Holder + Sacrifice Per-badge config
Discount Stacking ❌ No ❌ No βœ… WL+Holder ❌ No
Refund System βœ… Time-based βœ… Time-based βœ… Pool return ❌ No
Batch Minting βœ… Unlimited βœ… Unlimited βœ… 50 max βœ… Unlimited
On-Behalf Minting ❌ No βœ… Yes ❌ No βœ… Yes
Revocation ❌ No βœ… Optional ❌ No βœ… Optional
Sacrifice System ❌ No ❌ No βœ… Burn NFTs for discount ❌ No
Admin System Owner only Owner only Multi-admin Multi-admin
Supply Management Fixed/Unlimited Fixed/Unlimited Pool-based Fixed per badge
Contract Size 19.402 KiB 20.436 KiB 18.874 KiB 14.824 KiB
Architecture v2.0 (Refactored) v2.0 (Refactored) v1.0 v1.0
Documentation βœ… Complete βœ… Complete βœ… Extensive (6 docs) βœ… Complete

Detailed Contract Overview

1. MinterContract

πŸ“„ Documentation: MinterContract-README.md
πŸ”§ Contract: contracts/MinterContract.sol
πŸ§ͺ Tests: test/MinterContract.test.js
πŸ“¦ Size: 19.402 KiB | Headroom: 5.174 KiB

Purpose

Standard transferable NFT minting with flexible pricing, whitelist access, and refund mechanics.

When to Use

βœ… Traditional NFT collection launches
βœ… Transferable collectibles with standard economics
βœ… Projects needing refund/burn mechanics
βœ… Token-gated NFT access
βœ… Simple whitelist discount systems

Key Features

  • Create and mint NFTs on-demand
  • HBAR + $LAZY dual payment system
  • Time-based refund window with burn mechanism
  • Whitelist + token-gated access
  • Fixed or unlimited supply options
  • Sequential or random metadata selection
  • Comprehensive refund tracking

Architecture (v2.0)

MinterContract
  β”œβ”€ ExpiryHelperV2 (NFT expiry management)
  β”œβ”€ FeeHelperV2 (custom fee handling)
  β”œβ”€ KeyHelperV2 (key management with Bits library)
  β”œβ”€ HederaTokenServiceV2 (HTS integration)
  β”œβ”€ ReentrancyGuard (security)
  └─ Ownable (ownership)

v2.0 Improvements

  • βœ… Custom errors (~90% gas savings on errors)
  • βœ… MinterLibrary eliminated (DRY with KeyHelper)
  • βœ… KeyHelper Bits library integration
  • βœ… 86-byte contract size reduction
  • βœ… ~40% cheaper deployment
  • βœ… Enhanced maintainability

2. SoulboundMinter

πŸ“„ Documentation: SoulboundMinter-README.md
πŸ”§ Contract: contracts/SoulboundMinter.sol
πŸ§ͺ Tests: test/SoulboundMinter.test.js
πŸ“¦ Size: 20.436 KiB | Headroom: 4.140 KiB

Purpose

Non-transferable (soulbound) NFT minting for badges, certificates, and identity tokens.

When to Use

βœ… Educational certificates & credentials
βœ… Achievement/completion badges
βœ… Non-transferable membership tokens
βœ… Attendance/participation proofs
βœ… Identity verification NFTs
βœ… Single-type soulbound token systems
βœ… Gas abstraction (on-behalf minting)

Key Features

  • Frozen tokens - Non-transferable by design
  • Optional revocation system
  • On-behalf minting (gas abstraction for users)
  • HBAR + $LAZY dual payment
  • Time-based refunds
  • Whitelist + token-gated access
  • Optional FREEZE + WIPE keys

Soulbound Mechanism

// Tokens are frozen at mint
IHederaTokenService.TokenKey[] memory keys = new IHederaTokenService.TokenKey[](2);
keys[0] = getSingleKey(KeyType.FREEZE, ...);  // Required
keys[1] = getSingleKey(KeyType.WIPE, ...);    // Optional (for revocation)

Architecture (v2.0)

SoulboundMinter
  β”œβ”€ ExpiryHelperV2 (NFT expiry management)
  β”œβ”€ FeeHelperV2 (custom fee handling)
  β”œβ”€ KeyHelperV2 (unified key management)
  β”œβ”€ HederaTokenServiceV2 (HTS integration)
  β”œβ”€ ReentrancyGuard (security)
  └─ Ownable (ownership)

v2.0 Improvements

  • βœ… Custom errors (gas efficient)
  • βœ… Unified KeyType enum with KeyHelper
  • βœ… MinterLibrary dependency removed
  • βœ… 78-byte contract size reduction
  • βœ… Improved code quality via DRY

3. ForeverMinter

πŸ“„ Documentation: ForeverMinter-README.md
πŸ“š Extended Docs: docs/ForeverMinter-*.md (6 comprehensive documents)
πŸ”§ Contract: contracts/ForeverMinter.sol
πŸ§ͺ Tests: test/ForeverMinter.test.js
πŸ“¦ Size: 18.874 KiB | Headroom: 5.702 KiB

Purpose

Pool-based distribution of existing NFT collections with advanced discount mechanics and royalty compliance.

When to Use

βœ… Distributing existing NFT collections
βœ… Respecting creator royalties is critical
βœ… Complex discount mechanics (holder incentives, sacrifice)
βœ… Staking/recycling systems for NFTs
βœ… Multiple discount tiers with stacking
βœ… Large collections requiring efficient distribution
βœ… Multi-admin team management

Key Features

  • Pool-based distribution (not minting new tokens)
  • Royalty compliance via TokenStakerV2
  • Triple discount system:
    1. Whitelist discount (stackable)
    2. Holder discount (global per-serial tracking, stackable)
    3. Sacrifice discount (exclusive, highest %)
  • Burn existing NFTs for discounts
  • Time-based refund with pool return
  • PRNG serial selection
  • Multi-admin system

Unique Mechanics

// Sacrifice existing NFTs for discount
await foreverMinter.mintNFT(
    quantity,
    lazyAmount,
    true,              // Use holder discount
    true,              // Use sacrifice discount
    [serial1, serial2] // NFTs to burn
);

// Refund returns NFT to pool
await foreverMinter.refundNFT(serial);
// Serial back in availableSerials, 95% payment returned

Architecture (v1.0)

ForeverMinter
  β”œβ”€ TokenStakerV2 (royalty-compliant transfers)
  β”œβ”€ Ownable (ownership)
  └─ ReentrancyGuard (security)

Extended Documentation

  • ForeverMinter-SUMMARY.md: Documentation overview & roadmap
  • ForeverMinter-DESIGN.md: Complete technical specification (1700+ lines)
  • ForeverMinter-BUSINESS-LOGIC.md: User guide with 40+ FAQs
  • ForeverMinter-TODO.md: 23-phase implementation checklist
  • ForeverMinter-TESTING.md: 200+ test cases
  • ForeverMinter-IMPLEMENTATION-SUMMARY.md: Progress tracking

4. SoulboundBadgeMinter

πŸ“„ Documentation: SoulboundBadgeMinter-README.md
πŸ”§ Contract: contracts/SoulboundBadgeMinter.sol
πŸ§ͺ Tests: test/SoulboundBadgeMinter.test.js
πŸ“¦ Size: 14.824 KiB | Headroom: 9.752 KiB

Purpose

Multi-badge soulbound NFT system with per-badge configuration and team management.

When to Use

βœ… Multiple badge types in one contract
βœ… Organization/company badge programs
βœ… Per-badge supply limits and whitelists
βœ… Flexible multi-tier badge systems
βœ… Team-based admin management
βœ… Badge-specific pricing and configuration

Key Features

  • Multiple badge types in single contract
  • Per-badge configuration:
    • Individual supply limits
    • Separate whitelists
    • Badge-specific pricing
    • Custom metadata per badge
  • Multi-admin team system
  • On-behalf minting (gas abstraction)
  • Optional revocation per badge
  • HBAR-only payments (simpler)

Badge Management

// Each badge is independent
struct BadgeConfig {
    string name;
    string symbol;
    uint256 maxSupply;
    uint256 price;
    bool revocable;
    address[] whitelist;
    string metadataURI;
}

Architecture (v1.0)

SoulboundBadgeMinter
  β”œβ”€ KeyHelper (key management)
  β”œβ”€ HederaTokenService (HTS integration)
  β”œβ”€ ReentrancyGuard (security)
  └─ Ownable (ownership)

Repository Structure

hedera-SC-minter/
β”œβ”€β”€ contracts/
β”‚   β”œβ”€β”€ MinterContract.sol          # v2.0 - Standard NFT minting
β”‚   β”œβ”€β”€ SoulboundMinter.sol         # v2.0 - Single soulbound type
β”‚   β”œβ”€β”€ ForeverMinter.sol           # v1.0 - Pool distribution
β”‚   β”œβ”€β”€ SoulboundBadgeMinter.sol    # v1.0 - Multi-badge system
β”‚   β”œβ”€β”€ ExpiryHelperV2.sol          # NFT expiry management
β”‚   β”œβ”€β”€ FeeHelperV2.sol             # Custom fee handling
β”‚   β”œβ”€β”€ KeyHelperV2.sol             # Key management (Bits library)
β”‚   β”œβ”€β”€ HederaTokenServiceV2.sol    # HTS integration
β”‚   β”œβ”€β”€ TokenStakerV2.sol           # Staking mechanics
β”‚   β”œβ”€β”€ FungibleTokenCreator.sol    # v2.0 - Fungible token support
β”‚   └── interfaces/                 # Contract interfaces
β”‚
β”œβ”€β”€ test/
β”‚   β”œβ”€β”€ MinterContract.test.js
β”‚   β”œβ”€β”€ SoulboundMinter.test.js
β”‚   β”œβ”€β”€ ForeverMinter.test.js
β”‚   β”œβ”€β”€ SoulboundBadgeMinter.test.js
β”‚   └── FungibleTokenCreator.test.js
β”‚
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ ForeverMinter-SUMMARY.md
β”‚   β”œβ”€β”€ ForeverMinter-DESIGN.md
β”‚   β”œβ”€β”€ ForeverMinter-BUSINESS-LOGIC.md
β”‚   β”œβ”€β”€ ForeverMinter-TODO.md
β”‚   β”œβ”€β”€ ForeverMinter-TESTING.md
β”‚   └── ForeverMinter-IMPLEMENTATION-SUMMARY.md
β”‚
β”œβ”€β”€ abi/                            # Contract ABIs
β”œβ”€β”€ scripts/                        # Deployment & interaction scripts
β”œβ”€β”€ utils/                          # Helper utilities
β”œβ”€β”€ MinterContract-README.md        # Complete documentation
β”œβ”€β”€ SoulboundMinter-README.md       # Complete documentation
β”œβ”€β”€ ForeverMinter-README.md         # Quick reference (NEW)
β”œβ”€β”€ SoulboundBadgeMinter-README.md  # Complete documentation
β”œβ”€β”€ DEV-README.md                   # Development setup
└── README.md                       # This file

Technology Stack

  • Blockchain: Hedera Hashgraph
  • Solidity: 0.8.18
  • Framework: Hardhat
  • Testing: Mocha, Chai, Hedera SDK
  • Libraries:
    • OpenZeppelin (ReentrancyGuard, Ownable, SafeCast, Math, EnumerableMap/Set, Address, Strings)
    • Hedera Token Service (HTS)
    • Custom: KeyHelper with Bits library

Key Features Across All Contracts

πŸ” Security

  • ReentrancyGuard on all payment functions
  • Custom errors for gas-efficient error handling
  • Comprehensive testing with edge case coverage
  • Access control via Ownable or multi-admin systems

πŸ’° Economics

  • Dual payment: HBAR + $LAZY token integration
  • Burn mechanism: Configurable $LAZY burn percentage
  • Whitelist discounts: Incentivize early supporters
  • Flexible pricing: Per-contract or per-badge configuration

🎲 Randomization

  • PRNG integration for fair metadata/serial selection
  • Hedera VRF support via IPrngGenerator
  • Configurable: Sequential or random distribution

♻️ Refund Systems

  • Time-based windows (configurable)
  • Partial refunds (e.g., 95% return)
  • Burn tracking for accountability
  • Gas optimization via efficient data structures

πŸ“Š Metadata

  • IPFS integration for decentralized storage
  • Flexible URIs per-token or per-badge
  • Sequential or random metadata assignment

Getting Started

Installation

# Clone repository
git clone https://github.com/Burstall/hedera-SC-minter.git
cd hedera-SC-minter
git checkout refactor-base-minter

# Install dependencies
npm install

Configuration

# Copy environment template
cp .env.example .env

# Configure Hedera credentials
OPERATOR_ID=0.0.xxxxx
OPERATOR_KEY=your-private-key
NETWORK=testnet

Compilation

# Compile all contracts
npx hardhat compile

# Check contract sizes
npx hardhat compile --force

Testing

# Run all tests
npm test

# Test specific contracts
npm run test-minter          # MinterContract
npm run test-soulbound       # SoulboundMinter
npm run test-forever         # ForeverMinter
npm run test-badges          # SoulboundBadgeMinter
npm run test-ft              # FungibleTokenCreator

# Run with gas reporting
REPORT_GAS=true npm test

Deployment

# Deploy to testnet
npx hardhat run scripts/deployment/deploy-minter.js --network testnet

# Deploy specific contract
npx hardhat run scripts/deployment/deploy-soulbound.js --network testnet

Gas Estimates

MinterContract

  • Deploy: ~6.5M gas (~40% cheaper with v2.0 custom errors)
  • Single Mint: ~800k gas (with PRNG)
  • Batch Mint (10): ~6.0M gas base + 325k per NFT
  • Refund: ~300k gas

SoulboundMinter

  • Deploy: ~6.8M gas
  • Single Mint: ~850k gas (FREEZE key adds overhead)
  • On-Behalf Mint: +50k gas (gas abstraction)
  • Revoke: ~250k gas (if enabled)

ForeverMinter

  • Deploy: ~7.2M gas
  • Single Mint: ~700k gas (no token creation)
  • Sacrifice Mint: ~900k gas (includes burns)
  • Refund with Pool Return: ~350k gas

SoulboundBadgeMinter

  • Deploy: ~5.5M gas (smallest contract)
  • Single Badge Mint: ~800k gas
  • Multi-Badge Setup: ~200k per badge configuration

Note: Hedera suggests 20% gas buffer over estimates. Hedera refunds up to 20% of unused gas.


v2.0 Refactoring Summary

MinterContract & SoulboundMinter (v2.0)

Major Changes:

  • βœ… MinterLibrary Eliminated: Single-use helpers inlined
  • βœ… Custom Errors: Replaced all string-based reverts (~90% gas savings)
  • βœ… KeyHelper Integration: Uses Bits library and unified KeyType enum
  • βœ… DRY Principles: Removed code duplication with helper contracts
  • βœ… Size Optimization: 78-86 byte reduction per contract

Performance Improvements:

  • Deployment: ~40% cheaper
  • Error handling: ~90% gas savings
  • Runtime: Eliminated JUMP operations for inlined functions
  • Maintainability: Better code organization via DRY

Breaking Changes:

  • ❌ None - All public interfaces unchanged
  • βœ… Frontend error handling should parse custom errors (recommended, not required)

ForeverMinter & SoulboundBadgeMinter (v1.0)

  • Original implementations (no refactoring yet)
  • May receive v2.0 updates in future

Frontend Integration

Error Handling (v2.0 Contracts)

// Modern approach (v2.0) - parse custom errors
try {
    await contract.mintNFT(amount, { value: cost });
} catch (error) {
    if (error.data) {
        const parsedError = contract.interface.parseError(error.data);
        
        if (parsedError.name === 'InsufficientPayment') {
            const [required, provided] = parsedError.args;
            console.log(`Need ${required}, got ${provided}`);
        }
    }
}

// Legacy approach (still works)
catch (error) {
    if (error.message.includes("InsufficientPayment")) {
        // Handle error
    }
}

Cost Calculation

// MinterContract & SoulboundMinter
const cost = await contract.calculateCost(quantity, useWhitelist);

// ForeverMinter (v1.0.5+)
const result = await foreverMinter.calculateMintCost(
    userAddress,
    quantity,
    useHolderDiscount,
    useSacrifice
);
// Returns: {hbarCost, lazyCost, totalDiscount, holderSlotsUsed, wlSlotsUsed}

Documentation Quick Links

Contract Documentation

Extended Documentation (ForeverMinter)

Development

  • DEV-README.md - Development environment setup
  • Test Files: test/*.test.js - Comprehensive test suites

Use Case Matrix

Requirement Recommended Contract
Standard NFT sale MinterContract
Educational certificates SoulboundMinter
Achievement badges (single type) SoulboundMinter
Achievement badges (multiple types) SoulboundBadgeMinter
Pool-based distribution ForeverMinter
Holder incentive discounts ForeverMinter
NFT sacrifice mechanics ForeverMinter
Royalty compliance required ForeverMinter
Multi-admin team ForeverMinter or SoulboundBadgeMinter
On-behalf minting (gas abstraction) SoulboundMinter or SoulboundBadgeMinter
Revocable credentials SoulboundMinter or SoulboundBadgeMinter
Organization badge programs SoulboundBadgeMinter

Support & Community


License

See LICENSE file for details.


Last Updated: October 2025
Repository Status: βœ… Production Ready
Latest Version: v2.0 (MinterContract, SoulboundMinter), v1.0 (ForeverMinter, SoulboundBadgeMinter)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors