Smart Contract Development: ERC Standards, Security, and Chainlink VRF
March 1, 2026
Master EVM smart contract development with this comprehensive guide covering ERC-20, ERC-721, ERC-1155 standards, security best practices, and Chainlink VRF for provably fair randomness.
Smart contracts are the backbone of decentralized applications, DeFi protocols, and NFT ecosystems. At M.D.N Tech, we've deployed over 50 production smart contracts across multiple chains — from token launches and NFT collections to complex DeFi mechanisms and on-chain lotteries. This guide distills everything we've learned about building secure, gas-efficient, and production-ready smart contracts.
Chainlink secures over $100 billion in Total Value Secured (TVS) and has enabled $27+ trillion in transaction value across 60+ blockchains.
Whether you're building your first ERC-20 token or implementing Chainlink VRF for provably fair NFT minting, this guide covers the standards, security practices, and real-world patterns that separate amateur contracts from production-grade infrastructure.
The State of Smart Contract Security in 2026
Before diving into development, let's look at the current landscape. The numbers are sobering — and instructive.
$3.1 billion was lost across Web3 in the first half of 2025 alone — already surpassing all of 2024. 9 out of 10 hacked protocols had passed security audits.
The key insight? Audits are necessary but not sufficient. The median time between a protocol passing an audit and getting exploited is just 47 days. The teams that survive build multiple defense layers: development-time analysis, pre-launch audits, live bug bounties, on-chain monitoring, and financial backstops.
- Access control exploits caused $1.83 billion in losses (mostly Q1 2025)
- Reentrancy and logic bugs led to $325 million in stolen assets
- Phishing and social engineering spiked to $600 million
- Smart contract bugs caused approximately $263 million in damages
- About 70% of smart contracts on Ethereum are inactive or vulnerable
With this context, let's explore how to build contracts that don't become statistics.
ERC-20: Token Contracts Done Right
ERC-20 remains the foundation of fungible tokens on Ethereum and EVM-compatible chains. Despite being well-established, ERC-20 implementations still account for significant vulnerabilities.
Common ERC-20 Vulnerabilities
- Integer Overflow/Underflow: The BeautyChain (BEC) hack exploited batch overflow to mint astronomical token amounts. Always use SafeMath or Solidity 0.8+ built-in checks
- Approval Frontrunning: The approve() function directly sets allowance, enabling frontrunning attacks. Use safeIncreaseAllowance and safeDecreaseAllowance instead
- Lost Token Problem: Users sending tokens to contracts without extraction functions have caused $27+ million in permanent losses
- Reentrancy via Hooks: ERC-777's receive hooks, while useful, enable both reentrancy and DoS attacks
A secure ERC-20 implementation extends OpenZeppelin's ERC20, ERC20Burnable, and Ownable contracts. Key features include: a maximum supply constant, constructor that mints the full supply to the deployer, and a rescue function that allows the owner to recover accidentally sent tokens (with a safeguard preventing rescue of the contract's own tokens).
Always use OpenZeppelin's battle-tested implementations as your foundation. Their contracts are audited, widely used, and continuously maintained.
ERC-20 Security Best Practices
- Use Solidity 0.8+ for built-in overflow protection
- Implement rescue functions for accidentally sent tokens
- Use pull over push patterns for distributions (airdrops, bonuses)
- Limit approval amounts — avoid unlimited approvals
- Include pause functionality for emergency situations
- Test on testnets with realistic scenarios before mainnet
ERC-721 vs ERC-1155: Choosing the Right NFT Standard
Both standards serve NFT use cases, but they're designed for different scenarios. Understanding when to use each is crucial for gas efficiency and user experience.
ERC-721: The Original NFT Standard
ERC-721, introduced in 2017, established the foundation for NFTs. Each token is unique and requires individual tracking. This makes it ideal for truly unique assets like digital art, domain names, or real estate tokens.
- One contract per collection
- Each token has unique metadata
- Higher gas costs for batch operations
- Universal wallet and marketplace support
- Best for: 1/1 art, PFP collections, unique collectibles
ERC-1155: The Multi-Token Standard
ERC-1155 allows a single contract to manage multiple token types — both fungible and non-fungible. It supports batch transfers, reducing gas costs by up to 90% for multi-item operations.
- Multiple token types in one contract
- Batch transfers in single transaction (up to 150-200 tokens)
- Built-in safe transfer verification
- Semi-fungible token support (editions)
- Best for: Gaming items, trading cards, multi-edition collectibles
For gaming items with random attributes, the implementation extends ERC-1155 and integrates Chainlink VRF. Token IDs represent different rarity tiers (common, rare, legendary). When a user mints, the contract requests randomness from Chainlink. Once fulfilled, the random number determines rarity — typically 5% legendary, 15% rare, 80% common. The token is then minted to the user's address with the determined rarity.
Real-world example: Axie Infinity used Chainlink VRF to give each of 4,088 Origin Axies truly random characteristics across six body parts, ensuring provably fair distribution.
Chainlink VRF: Provably Fair Randomness
Blockchain networks are deterministic by design — every node executes the same transactions and reaches identical results. This creates a fundamental challenge: how do you generate truly random numbers on a predictable system?
Chainlink VRF (Verifiable Random Function) solves this by generating random values off-chain with cryptographic proof that the results weren't tampered with. The proof is verified on-chain before any consuming application can use it.
Chainlink VRF has fulfilled 20+ million request transactions for thousands of smart contracts across multiple blockchains, making it the most widely adopted RNG in Web3.
VRF Use Cases We've Implemented
At M.D.N Tech, we've used Chainlink VRF extensively. Here are the primary patterns:
- On-chain Lotteries: Fair winner selection for raffles and prize pools. PancakeSwap's Lottery V2 uses VRF for publicly auditable drawings
- Random NFT Attributes: Generating rarity traits during minting. Bored Ape Yacht Club used VRF to distribute Mutant Serum NFTs fairly
- Loot Box Mechanics: Provably fair item drops for gaming. CryptoBlades uses VRF for unpredictable battle pairings
- Random Matchmaking: Fair player pairing in competitive games without manipulation
- Dynamic NFTs: NFTs that 'evolve' with random characteristics over time
Implementing VRF v2.5
Chainlink VRF v2.5 offers two payment models: subscription-based (best for frequent requests) and direct funding (best for one-off requests like NFT distributions).
A VRF-powered lottery contract manages player entries, prize pool accumulation, and provably fair winner selection. Players enter by sending ETH above the minimum threshold. When the owner triggers winner selection, the contract enters a 'calculating' state and requests randomness from Chainlink VRF. Once the random number arrives, it's used to select a winner index from the player array. The prize pool is transferred to the winner, and the lottery resets for the next round.
For gaming platforms with frequent randomness needs, use the subscription model. For NFT mints and one-time contests, direct funding keeps things simple.
Smart Contract Security Best Practices
Based on our 50+ deployments and analysis of major exploits, here are the security practices that actually prevent hacks:
1. Follow the Checks-Effects-Interactions Pattern
The most important defense against reentrancy attacks. Always: check conditions, update state, then interact with external contracts.
The vulnerable pattern makes an external call before updating state — allowing attackers to re-enter the function before the balance is zeroed. The correct pattern follows three steps: Check (verify balance exists), Effect (set balance to zero), Interaction (transfer funds). By updating state before the external call, even if the recipient tries to re-enter, they'll find their balance already zeroed.
2. Implement Proper Access Control
Access control failures caused $1.83 billion in losses in early 2025. Use OpenZeppelin's AccessControl or Ownable2Step for safe ownership transfers.
- Use multi-sig wallets for admin functions
- Implement timelocks for critical operations
- Separate roles: admin, pauser, minter, upgrader
- Never use tx.origin for authentication
- Consider social recovery mechanisms
3. Validate All Inputs
Lack of input validation accounts for 34.6% of direct contract exploits. Validate every external input, especially:
- Array lengths (prevent gas griefing)
- Address parameters (check for zero address)
- Numeric bounds (amounts, percentages, timestamps)
- String/bytes length limits
- Token decimals assumptions
4. Use Upgradeable Patterns Carefully
Upgradeability is now critical infrastructure — and one of the most severe attack vectors. UUPS has won the efficiency battle but requires rigorous deployment discipline.
By 2026, AI-driven audit processes compare bytecode between versions to detect storage slot shifts and invariant violations before upgrade transactions are signed. Consider integrating these tools.
Development Tools: Foundry vs Hardhat
The tooling ecosystem has consolidated around two frameworks: Hardhat (60% market share) and Foundry (30% and growing). Many teams use both.
Hardhat
- JavaScript-first approach with rich plugin ecosystem
- console.log() debugging inside Solidity
- Detailed stack traces and error messages
- Mainnet forking for local testing
- Hardhat 3 now supports both Solidity and TypeScript tests natively
Foundry
- Solidity-native testing (write tests in Solidity)
- 2-5x faster compilation, up to 100x faster tests
- Powerful cheatcodes for EVM state manipulation
- Built-in fuzz testing for edge case discovery
- CLI tools: forge (build/test), cast (EVM CLI), anvil (local node)
Foundry's fuzz testing automatically generates hundreds of random inputs to test edge cases. A fuzz test for token transfers might verify that for any transfer amount (bounded to available balance), the sender's balance decreases by exactly that amount while the receiver's increases by exactly that amount. This catches edge cases like boundary conditions and overflow scenarios that manual tests often miss.
Start with Hardhat if you're comfortable with JavaScript. Move to Foundry for faster iteration and Solidity-native testing. Many production teams use both.
Chainlink Ecosystem: Beyond VRF
Chainlink dominates the oracle market with 67% market share. On Ethereum, it secures over 83% of Total Value Secured; on Base, nearly 100%. Here's what else the ecosystem offers:
- Price Feeds: Real-time asset prices for DeFi protocols (Aave alone secures $70+ billion using Chainlink)
- Automation (Keepers): Decentralized contract automation for periodic tasks
- CCIP: Cross-chain interoperability across 60+ blockchains
- Functions: Run custom computations off-chain with on-chain verification
- Data Streams: High-frequency data with 777% throughput increase in Q1 2025
- Proof of Reserve: Verify off-chain collateral for wrapped assets
Real-World Architecture: NFT Collection with Random Traits
Here's a production architecture we've used for NFT collections requiring provably fair attribute generation:
A production NFT collection with random traits combines ERC-721 Enumerable, Ownable, ReentrancyGuard, and Chainlink VRF. Each trait category (background, body, accessory, head, eyes) has its own range of possible values. When minting, the contract first mints the NFT, then requests randomness. Once Chainlink fulfills the request, the single random number is bit-shifted to derive independent random values for each trait category, plus an overall rarity score. The traits are stored on-chain and an event is emitted for indexers.
Audit Checklist: Before You Deploy
Comprehensive audits cost $25,000-$150,000 depending on complexity. Simple ERC-20 audits run $8,000-$20,000, while complex DeFi protocols can exceed $150,000. Here's what to verify before seeking an audit:
- All external calls follow checks-effects-interactions
- Access control covers all admin functions
- Input validation on all public/external functions
- No hardcoded addresses that should be configurable
- Events emitted for all state changes
- Reentrancy guards on functions with external calls
- Proper handling of ETH transfers (check return values)
- Gas optimization reviewed (loops, storage, calldata vs memory)
- Emergency pause functionality implemented
- Upgrade mechanisms tested thoroughly
- 100% test coverage with edge cases
- Fuzz testing for mathematical operations
Conclusion
Smart contract development has matured significantly, but the stakes have never been higher. With billions at risk and increasingly sophisticated attackers, building secure contracts requires deep understanding of standards, security patterns, and battle-tested tooling.
At M.D.N Tech, we've learned that success comes from combining proven patterns (OpenZeppelin, Chainlink), rigorous testing (Foundry fuzz testing), and multiple security layers. The contracts that survive are the ones built with security as a first principle, not an afterthought.
Whether you're building a simple token, a complex NFT collection with random traits, or a full DeFi protocol, the fundamentals remain the same: use established standards, verify everything, and never underestimate the creativity of attackers.
Ready to build secure smart contracts? Our Web3 team has deployed 50+ production contracts across multiple chains. Contact us to discuss your project.