AGENT SKILL

erc-721

Add an ERC-721 NFT contract to a Scaffold-ETH 2 project. Use when the user wants to: create an NFT collection, deploy an ERC-721, add NFT minting, build an NFT gallery or transfer UI, or work with non-fungible tokens in SE-2.

License 许可
MIT
最近更新
2026-10-03
Stars
★ 35
Forks
6

01 前言 Front Matter

name
erc-721
description
Add an ERC-721 NFT contract to a Scaffold-ETH 2 project. Use when the user wants to: create an NFT collection, deploy an ERC-721, add NFT minting, build an NFT gallery or transfer UI, or work with non-fungible tokens in SE-2.

03 SKILL.md 正文

ERC-721 NFT Integration for Scaffold-ETH 2

Prerequisites

Check if ./packages/nextjs/scaffold.config.ts exists directly in the current working directory (do not search subdirectories). If it doesn't exist, this is not a Scaffold-ETH 2 project. Follow the instructions at https://docs.scaffoldeth.io/SKILL.md to scaffold it first. If it exists, continue directly with building.

Also read .agents/skills/openzeppelin/SKILL.md since ERC-721 contracts use OpenZeppelin, and that skill has critical guidance on reading the installed source for correct import syntax, override points, and constructor patterns.

Gotchas

Key pitfalls and gotchas to watch for when working with ERC-721.

1. _safeMint Reentrancy

_safeMint and safeTransferFrom invoke onERC721Received() on the recipient if it's a contract. This is an external call after the token has been minted, creating a reentrancy vector.

Real exploit (HypeBears, Feb 2022): State updated after _safeMint allowed attacker to re-enter and bypass per-address minting limits.

// VULNERABLE: state update after _safeMint
function mintNFT() public {
    require(!addressMinted[msg.sender], "Already minted");
    _safeMint(msg.sender, tokenId);
    addressMinted[msg.sender] = true;  // too late
}

// SAFE: state update before _safeMint
function mintNFT() public {
    require(!addressMinted[msg.sender], "Already minted");
    addressMinted[msg.sender] = true;  // update first
    _safeMint(msg.sender, tokenId);
}

2. On-Chain SVG Stack-Too-Deep

When generating SVG on-chain, the tokenURI or generateSVG function easily hits Solidity's 16-local-variable stack limit. Split SVG generation into multiple helper functions (e.g., _svgBackground, _svgShapes, _svgText) rather than building the entire SVG in one function.

3. Marketplace Metadata attributes Array

The attributes array in NFT metadata JSON is not in the ERC-721 EIP but is the de facto standard used by OpenSea, Blur, and every marketplace. Without it, traits won't display:

{
  "name": "My NFT #1",
  "description": "...",
  "image": "data:image/svg+xml;base64,...",
  "attributes": [
    { "trait_type": "Color", "value": "Blue" },
    { "trait_type": "Rarity", "value": "Rare" }
  ]
}

4. Required Overrides with ERC721Enumerable

When combining ERC721 + ERC721Enumerable, both define _update and _increaseBalance. You must explicitly override them or the contract won't compile:

function _update(address to, uint256 tokenId, address auth) internal override(ERC721, ERC721Enumerable) returns (address) {
    return super._update(to, tokenId, auth);
}

function _increaseBalance(address account, uint128 amount) internal override(ERC721, ERC721Enumerable) {
    super._increaseBalance(account, amount);
}

function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool) {
    return super.supportsInterface(interfaceId);
}

5. IPFS Base URI Trailing Slash

OpenZeppelin's tokenURI() concatenates _baseURI() + tokenId.toString(). If the base URI is ipfs://QmCID without a trailing slash, token 42 becomes ipfs://QmCID42 instead of ipfs://QmCID/42.

04 同仓库更多 Skills

austintgriffith
austintgriffith/picowallet

pico-emu

Write and test MicroPython for the Pico wallet (Pico 2 W + Waveshare Pico-LCD-1.3, 240x240 screen, joystick + A/B/X/Y) on the virtual wallet in emu/, then put it on the real board. Use for "build X for the Pico", "make a game/screen/animation for the wallet", "try this on the emulator", or "put it on the Pico".

★ 35
austintgriffith
austintgriffith/picowallet

x402

Add x402 payment-gated routes to a Scaffold-ETH 2 project. Use when the user wants to: monetize an API with micropayments, add HTTP 402 payment required to routes, gate content behind crypto payments, implement pay-per-call APIs, or integrate the x402 protocol.

★ 35
austintgriffith
austintgriffith/picowallet

subgraph

Integrate The Graph subgraph into a Scaffold-ETH 2 project for indexing blockchain events. Use when the user wants to: index contract events with The Graph, add a subgraph, query onchain data with GraphQL, set up a local graph node, or deploy a subgraph to Subgraph Studio.

★ 35
austintgriffith
austintgriffith/picowallet

siwe

Add Sign-In with Ethereum (SIWE) authentication to a Scaffold-ETH 2 project. Use when the user wants to: add wallet-based login, implement SIWE, authenticate users with their Ethereum wallet, add session management with wallet signing, build sign-in with Ethereum, or add Web3 authentication.

★ 35
austintgriffith
austintgriffith/picowallet

ponder

Integrate Ponder into a Scaffold-ETH 2 project for blockchain event indexing. Use when the user wants to: index contract events, add a blockchain backend, set up GraphQL for onchain data, use Ponder with SE-2, or build an indexer for their dApp.

★ 35
austintgriffith
austintgriffith/picowallet

openzeppelin

Develop smart contracts using OpenZeppelin Contracts library. Use when the user wants to create or modify Solidity contracts that use OpenZeppelin — including token standards (ERC20, ERC721, ERC1155), access control (Ownable, AccessControl), security primitives (Pausable, ReentrancyGuard), or any OZ extension. Covers library-first integration, pattern discovery from installed source, and version-safe development.

★ 35