A simple ERC-721 NFT Collection built with Solidity, OpenZeppelin, and Foundry. This project demonstrates the core functionality of an NFT collection, including minting, metadata management through baseURI, and tokenURI implementation.
- 🖼️ ERC-721 compliant NFT collection
- 🎨 Mint new NFTs
- 🔗 Configurable
baseURIoverride - 📄 Custom
tokenURIoverride
- Solidity ^0.8.x
- Foundry
- OpenZeppelin Contracts
.
├── src/
│ └── NFTCollection.sol
├── uris/
│ └── 0.json
│ └── 1.json
├── script/
│ └── DeployNFTCollection.s.sol
├── lib/
├── foundry.toml
└── README.md
Install the following tools before running the project:
- Git
- Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryupVerify the installation:
forge --versionClone the repository:
git clone https://github.com/<your-username>/nft-collection.git
cd nft-collectionInstall dependencies:
forge installBuild the project:
forge buildforge buildRun all tests:
forge testVerbose output:
forge test -vvvvGenerate a gas report:
forge test --gas-reportGenerate coverage:
forge coverageFormat Solidity files:
forge fmtStart a local blockchain:
anvilDeploy the contract:
forge script script/DeployNFTCollection.s.sol \
--rpc-url http://127.0.0.1:8545 \
--private-key <PRIVATE_KEY> \
--broadcastCreates a new NFT and assigns it to a recipient.
mint(address to);Updates the base URI used for metadata.
setBaseURI(string memory newBaseURI);Example:
https://example.com/metadata/
Returns the complete metadata URI for a token.
Example:
https://example.com/metadata/1.json
Implemented by overriding OpenZeppelin's tokenURI() function.
{
"name": "NFT #1",
"description": "Example NFT Collection",
"image": "ipfs://QmExampleHash/1.png",
"attributes": [
{
"trait_type": "Rarity",
"value": "Common"
}
]
}The test suite covers:
- Contract deployment
- NFT minting
- Ownership verification
- Token URI generation
- Base URI updates
- Invalid token lookups
- Revert conditions
Run:
forge testBuild
forge buildRun tests
forge testVerbose tests
forge test -vvvvGas report
forge test --gas-reportCoverage
forge coverageFormat code
forge fmtClean artifacts
forge cleanStart local node
anvilInteract with contracts
cast- OpenZeppelin Contracts
- Forge Standard Library (
forge-std)
This project is licensed under the MIT License.
Developed with Solidity and Foundry for educational purposes and as a foundation for more advanced NFT projects.