Deploy an ERC-721 Token
This tutorial will walk you through deploying an ERC-721 (Non-Fungible Token) on SKALE using Foundry and OpenZeppelin Contracts. ERC-721 tokens are unique, non-fungible tokens commonly used for NFTs, collectibles, and digital assets.Prerequisites
- Rust installed on your machine
- Foundry installed
- A wallet with sFUEL
- Basic knowledge of Solidity
- A SKALE Chain endpoint
If you are on a Windows machine, you will need to use Windows Subsystem for Linux (WSL), since Foundry doesn’t work natively on Windows.
Step 1: Install Foundry
If you haven’t already installed Foundry, run:Step 2: Create a New Foundry Project
Run the following in your terminal:Step 3: Install OpenZeppelin Contracts
Install OpenZeppelin Contracts using Foundry:lib directory.
Step 4: Configure Remappings
Update yourremappings.txt file (or create it if it doesn’t exist) to include:
Step 5: Update Foundry Configuration
Update thefoundry.toml file to add your SKALE Chain endpoint:
Step 6: Create the ERC-721 Contract
Create a new filesrc/MyERC721.sol:
- Inherits from OpenZeppelin’s
ERC721contract - Sets the token name to “MyNFT” and symbol to “MNFT”
- Includes a
mintfunction that allows anyone to mint NFTs - Uses
_safeMintwhich checks if the recipient can handle ERC-721 tokens - Tracks the next token ID automatically
Step 7: Compile the Contract
Compile your contract:Step 8: Prepare Signer for Deployment
This tutorial uses the Foundry Keystore for increased security. Create a new keystore:Provide a password to encrypt the keystore file when running the above command. If you forget this password, you will not be able to recover it.
Step 9: Deploy the Contract
Deploy your ERC-721 token to SKALE:The
--legacy flag is required for SKALE Chains. For more information, see Troubleshooting.Step 10: Mint Your First NFT
After deployment, you can mint NFTs by calling themint function. You can do this using cast:
<DEPLOYED_ADDRESS> with your deployed contract address and <RECIPIENT_ADDRESS> with the address that should receive the NFT.
Step 11: Verify Your Smart Contract
Verify your smart contract on the block explorer:<DEPLOYED_ADDRESS> with your deployed contract address.
Advanced: Adding Metadata Support
To add metadata support (like token URIs), you can extend your contract withERC721URIStorage:
Next Steps
Congratulations! You’ve successfully deployed an ERC-721 token on SKALE. You can now:- Mint unique NFTs
- Transfer NFTs between addresses
- Approve operators to manage your NFTs
- Build NFT marketplaces or applications
