Skip to content

ldbld/solidity-contract-templates

Repository files navigation

Solidity Contract Templates

Production-ready smart contract templates with 100% test coverage, built with Foundry and OpenZeppelin v5.

Every template includes: contract source, comprehensive Foundry test suite, deployment script, and documentation.

Templates

Template Description
erc20-standard ERC-20 token with mint cap, burn, and EIP-2612 permit
erc721-basic ERC-721 NFT with public mint, reveal, royalties (ERC-2981), and enumerable
staking-single Synthetix-style single-token staking with configurable reward periods
vesting-linear Token vesting with optional cliff, multiple schedules, and revocable grants
erc20-with-tax ERC-20 with configurable buy/sell tax routed to treasury

Test Coverage

All contract source files at 100% coverage:

Template Tests Lines Statements Branches Functions
erc20-standard 21/21 100% 100% 100% 100%
erc721-basic 28/28 100% 100% 100% 100%
staking-single 25/25 100% 100% 100% 100%
vesting-linear 29/29 100% 100% 100% 100%
erc20-with-tax 28/28 100% 100% 100% 100%

Total: 131 tests, all passing.

Quick Start

# Clone
git clone https://github.com/ldbld/solidity-contract-templates.git

# Pick a template
cd solidity-contract-templates/erc20-standard

# Install dependencies
forge install

# Run tests
forge test -vvv

# Check coverage
forge coverage

Project Structure

Each template follows the same layout:

template-name/
├── src/          # Contract source code (fully commented)
├── test/         # Foundry test suite (100% coverage)
├── script/       # Deployment script (testnet + mainnet)
├── foundry.toml  # Foundry config with remappings
└── README.md     # Template-specific documentation

Security Features Included

Every template is built with security as a first-class concern:

  • Ownable2Step — Two-step ownership transfer prevents accidental loss of admin control
  • ReentrancyGuard — All state-changing external functions that transfer value are protected
  • SafeERC20 — Token transfers use OpenZeppelin's SafeERC20 to handle non-standard return values
  • Custom Errors — Gas-efficient reverts with descriptive error types (no string-based require)
  • Checks-Effects-Interactions — State changes before external calls throughout
  • Immutable/Constant — Config values that never change are marked immutable or constant
  • Input Validation — Zero-address checks, amount bounds, and parameter sanity checks on all entry points
  • No Unbounded Loops — No functions iterate over unbounded arrays (DoS protection)
  • Overflow Protection — Solidity 0.8.24 native overflow/underflow checks

Template-Specific Security

Template Additional Protections
erc20-standard Max supply hard cap enforced on mint; EIP-2612 permit for gasless approvals
erc721-basic One-time reveal prevents re-reveal manipulation; ERC-2981 on-chain royalties
staking-single Reward balance verification before period start; same-token staking edge case handled
vesting-linear Post-revoke claim for already-vested tokens; cliff enforcement; per-schedule isolation
erc20-with-tax 10% max tax hard cap (anti-rug); wallet-to-wallet untaxed; tax applied in _update (no bypass via transferFrom)

Deployment

Each template includes a Foundry deployment script. General steps:

# 1. Set environment variables
export PRIVATE_KEY=your_private_key
export SEPOLIA_RPC_URL=https://rpc.sepolia.org
export ETHERSCAN_API_KEY=your_key

# 2. Deploy to testnet
forge script script/Deploy.s.sol --rpc-url $SEPOLIA_RPC_URL --broadcast --verify

# 3. Deploy to mainnet (when ready)
forge script script/Deploy.s.sol --rpc-url $MAINNET_RPC_URL --broadcast --verify

See each template's README for specific constructor parameters and post-deployment steps.

Requirements

  • Foundry (forge, cast, anvil)
  • Solidity 0.8.24+

License

MIT

About

Production-ready Solidity smart contract templates with 100% test coverage. ERC-20, ERC-721, Staking, Vesting, Tax Token.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors