Blockchain technology has revolutionized digital ownership through tokens, which are broadly categorized into fungible and non-fungible tokens (NFTs). This blog post explains the differences between these token types, provides a comparison table, and includes step-by-step, deployable code examples using a free online tech stack. We’ll use Ethereum’s Sepolia testnet, Solidity for smart contracts, Remix IDE for development, and MetaMask for deployment, all of which are free and accessible.
Fungible Tokens
Fungible tokens are interchangeable and identical in value. Think of them like dollar bills: one $10 bill is equivalent to another $10 bill. Common examples include cryptocurrencies like ETH or tokens like ERC-20 tokens (e.g., USDC).
Real-World Example: A Voting Token (VOTE)
Imagine a decentralized community where members use a fungible token called “VOTE” to participate in governance decisions. Each VOTE token represents one vote, and tokens can be freely exchanged.
Step-by-Step Code Example: ERC-20 Fungible Token
We’ll create an ERC-20 token called “VOTE” using Solidity and deploy it on the Sepolia testnet.
-
Set Up Environment:
- Go to Remix IDE.
- Install MetaMask browser extension and create a wallet.
- Connect MetaMask to the Sepolia testnet and get free Sepolia ETH from a faucet like Sepolia Faucet.
-
Write the ERC-20 Smart Contract: Create a new file in Remix named
VoteToken.sol
.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract VoteToken is ERC20 {
constructor(uint256 initialSupply) ERC20("VoteToken", "VOTE") {
_mint(msg.sender, initialSupply * 10 ** decimals());
}
}
Explanation:
- We use OpenZeppelin’s ERC-20 contract for standard token functionality.
- The contract defines a token named “VoteToken” with symbol “VOTE”.
- The constructor mints an initial supply to the deployer’s address.
-
Deploy the Contract:
- In Remix, go to the “Deploy & Run Transactions” tab.
- Select “Injected Provider - MetaMask” as the environment.
- Choose the
VoteToken
contract and enter an initial supply (e.g.,1000
for 1000 VOTE tokens). - Click “Deploy” and confirm the transaction in MetaMask.
- After deployment, copy the contract address from Remix.
-
Interact with the Token:
- In Remix, under “Deployed Contracts,” use the
transfer
function to send VOTE tokens to another address. - Verify the token balance using the
balanceOf
function. - View the token on Sepolia’s block explorer (e.g., Sepolia Etherscan) by searching the contract address.
- In Remix, under “Deployed Contracts,” use the
Why This Is Fungible: Each VOTE token is identical and interchangeable, suitable for voting or trading within the community.
Non-Fungible Tokens (NFTs)
Non-fungible tokens are unique and indivisible, representing distinct assets. Think of them like concert tickets: each ticket is unique due to its seat number or event details. ERC-721 tokens are a common NFT standard, used for digital art, collectibles, or real-world assets.
Real-World Example: Digital Concert Tickets
Imagine a music festival issuing NFT tickets, where each ticket is unique and tied to a specific seat or attendee. We’ll create an ERC-721 NFT called “ConcertTicket” to demonstrate this.
Step-by-Step Code Example: ERC-721 Non-Fungible Token
We’ll create an ERC-721 NFT using Solidity and deploy it on Sepolia.
-
Set Up Environment:
- Use the same Remix IDE and MetaMask setup as above.
- Ensure you have Sepolia ETH for gas fees.
-
Write the ERC-721 Smart Contract: Create a new file in Remix named
ConcertTicket.sol
.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
contract ConcertTicket is ERC721 {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721("ConcertTicket", "TICKET") {}
function mintTicket(address recipient) public returns (uint256) {
_tokenIds.increment();
uint256 newTokenId = _tokenIds.current();
_mint(recipient, newTokenId);
return newTokenId;
}
}
Explanation:
- We use OpenZeppelin’s ERC-721 contract for NFT functionality.
- The contract defines an NFT named “ConcertTicket” with symbol “TICKET”.
- The
mintTicket
function creates a unique token ID for each new ticket and assigns it to the recipient.
-
Deploy the Contract:
- In Remix, select the
ConcertTicket
contract and deploy it using MetaMask on Sepolia. - Copy the contract address after deployment.
- In Remix, select the
-
Mint and Verify NFTs:
- In Remix, call the
mintTicket
function with your MetaMask address as the recipient. - Each call creates a new, unique token ID (e.g., 1, 2, 3).
- Use the
ownerOf
function to verify the owner of a specific token ID. - Check the NFT on Sepolia Etherscan by searching the contract address.
- In Remix, call the
Why This Is Non-Fungible: Each ConcertTicket NFT is unique, representing a specific ticket that cannot be swapped interchangeably.
Comparison of Fungible and Non-Fungible Tokens
The following table highlights the key differences between fungible and non-fungible tokens:
Feature | Fungible Tokens (e.g., VOTE) | Non-Fungible Tokens (e.g., ConcertTicket) |
---|---|---|
Fungibility | Identical and interchangeable | Unique and non-interchangeable |
Standard | ERC-20 | ERC-721 (or ERC-1155) |
Divisibility | Divisible (e.g., 0.5 VOTE) | Indivisible (whole tokens only) |
Use Case | Currencies, voting, rewards | Collectibles, digital art, tickets, unique assets |
Example | Voting token for governance | Unique concert ticket with specific seat number |
Smart Contract | ERC20.sol (VoteToken.sol) | ERC721.sol (ConcertTicket.sol) |
Value | Equal value per token | Value varies based on uniqueness or rarity |
Deploying and Demonstrating Online
Both examples use Remix IDE and Sepolia testnet, which are free and accessible. You can:
- Deploy the contracts as described.
- Share the contract addresses to demonstrate token transfers (VOTE) or NFT ownership (ConcertTicket) via Sepolia Etherscan.
- Use Remix’s interface to interact with the contracts publicly.
Conclusion
Fungible and non-fungible tokens serve distinct purposes in blockchain ecosystems. Fungible tokens like VOTE enable standardized, interchangeable assets, while NFTs like ConcertTicket represent unique, indivisible assets. By deploying these examples on Sepolia using Remix and MetaMask, you can explore and demonstrate their functionality for free.