NFT và Digital Assets - Sở hữu Kỹ thuật số trên Blockchain
· 6 min read

NFT và Digital Assets - Sở hữu Kỹ thuật số trên Blockchain
NFT (Non-Fungible Tokens) đã trở thành hiện tượng, thay đổi cách chúng ta sở hữu và giao dịch digital assets. Bài viết này khám phá thế giới NFT.
NFT là gì?
Non-Fungible Token
NFT là token unique, không thể thay thế, đại diện cho quyền sở hữu một asset cụ thể.
Fungible vs Non-Fungible
| Fungible (ERC-20) | Non-Fungible (NFT) |
|---|---|
| Interchangeable | Unique |
| 1 BTC = 1 BTC | Each NFT is different |
| Divisible | Indivisible (usually) |
| Example: Tokens | Example: Art, collectibles |
Characteristics
- Unique: Mỗi NFT là duy nhất
- Indivisible: Không thể chia nhỏ (thường)
- Ownership: Provenance trên blockchain
- Verifiable: Dễ dàng verify authenticity
NFT Standards
ERC-721
Standard cho unique tokens trên Ethereum.
// ERC-721 Interface
interface IERC721 {
function balanceOf(address owner) external view returns (uint256);
function ownerOf(uint256 tokenId) external view returns (address);
function transferFrom(address from, address to, uint256 tokenId) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address);
}
Basic ERC-721 Implementation
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract MyNFT is ERC721 {
uint256 private _tokenIds;
mapping(uint256 => string) private _tokenURIs;
constructor() ERC721("MyNFT", "MNFT") {}
function mint(address to, string memory tokenURI) public returns (uint256) {
_tokenIds++;
uint256 newTokenId = _tokenIds;
_mint(to, newTokenId);
_setTokenURI(newTokenId, tokenURI);
return newTokenId;
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
return _tokenURIs[tokenId];
}
}
ERC-1155
Multi-token standard, có thể represent cả fungible và non-fungible tokens.
// ERC-1155 allows both
contract MyMultiToken is ERC1155 {
// Fungible: amount > 1
// Non-fungible: amount = 1
function mint(
address to,
uint256 id,
uint256 amount,
bytes memory data
) public {
_mint(to, id, amount, data);
}
}
So sánh Standards
| Feature | ERC-721 | ERC-1155 |
|---|---|---|
| Use Case | Unique items | Both fungible & unique |
| Batch Transfer | No | Yes |
| Gas Efficiency | Higher | Lower (for batches) |
| Metadata | Per token | Per token ID |
NFT Metadata
Token URI
NFTs thường store metadata off-chain:
{
"name": "My Awesome NFT",
"description": "This is a unique digital artwork",
"image": "https://ipfs.io/ipfs/QmXxXxXx...",
"attributes": [
{
"trait_type": "Color",
"value": "Blue"
},
{
"trait_type": "Rarity",
"value": "Legendary"
}
]
}
Storage Options
- IPFS: Decentralized storage (recommended)
- Arweave: Permanent storage
- Centralized: HTTP/HTTPS URLs (not recommended)
NFT Use Cases
Digital Art
- Artists: Sell artwork directly
- Collectors: Build collections
- Platforms: OpenSea, Foundation, SuperRare
Gaming
- In-game Items: Weapons, skins, characters
- Play-to-Earn: Earn NFTs by playing
- Virtual Real Estate: Land in metaverse
Music
- Albums: Exclusive releases
- Royalties: Artists earn from resales
- Concerts: Access tokens
Collectibles
- Sports: NBA Top Shot, Sorare
- Trading Cards: Digital collectibles
- Memes: Viral content as NFTs
Identity và Credentials
- Certificates: Educational certificates
- Memberships: Club memberships
- Licenses: Professional licenses
Real Estate
- Property Titles: Ownership records
- Fractional Ownership: Share properties
- Rental Agreements: Smart contracts
NFT Marketplaces
OpenSea
- Largest: Most popular marketplace
- Multi-chain: Ethereum, Polygon, Solana
- User-friendly: Easy to use interface
Other Marketplaces
- Foundation: Curated platform
- SuperRare: Exclusive art
- Rarible: Community-owned
- LooksRare: Token rewards for trading
Building NFT Marketplace
contract NFTMarketplace {
struct Listing {
address seller;
uint256 price;
bool active;
}
mapping(uint256 => Listing) public listings;
IERC721 public nftContract;
function listNFT(uint256 tokenId, uint256 price) external {
require(nftContract.ownerOf(tokenId) == msg.sender, "Not owner");
require(nftContract.isApprovedForAll(msg.sender, address(this)), "Not approved");
listings[tokenId] = Listing({
seller: msg.sender,
price: price,
active: true
});
}
function buyNFT(uint256 tokenId) external payable {
Listing memory listing = listings[tokenId];
require(listing.active, "Not for sale");
require(msg.value >= listing.price, "Insufficient payment");
nftContract.safeTransferFrom(listing.seller, msg.sender, tokenId);
payable(listing.seller).transfer(listing.price);
delete listings[tokenId];
}
}
Royalties và Secondary Sales
Royalty Mechanism
Artists có thể earn từ mỗi resale:
contract RoyaltyNFT is ERC721 {
uint256 public royaltyPercentage = 5; // 5%
address public artist;
function _calculateRoyalty(uint256 salePrice) internal view returns (uint256) {
return (salePrice * royaltyPercentage) / 100;
}
}
EIP-2981 (Royalty Standard)
interface IERC2981 {
function royaltyInfo(uint256 tokenId, uint256 salePrice)
external
view
returns (address receiver, uint256 royaltyAmount);
}
NFT Minting Strategies
Standard Minting
function mint(address to) public {
uint256 tokenId = totalSupply() + 1;
_mint(to, tokenId);
}
Presale và Whitelist
mapping(address => bool) public whitelist;
bool public presaleActive;
function presaleMint() external {
require(presaleActive, "Presale not active");
require(whitelist[msg.sender], "Not whitelisted");
// Mint logic
}
Dutch Auction
Giá giảm dần theo thời gian:
uint256 public startPrice = 1 ether;
uint256 public endPrice = 0.1 ether;
uint256 public duration = 1 hours;
function getCurrentPrice() public view returns (uint256) {
uint256 elapsed = block.timestamp - startTime;
if (elapsed >= duration) return endPrice;
uint256 priceRange = startPrice - endPrice;
return startPrice - (priceRange * elapsed / duration);
}
Gas Optimization cho NFTs
Batch Minting
// Inefficient ❌
function mintMultiple(address[] memory to) public {
for (uint i = 0; i < to.length; i++) {
_mint(to[i], i + 1);
}
}
// More efficient ✅
function batchMint(address[] memory to) public {
for (uint i = 0; i < to.length; i++) {
_mint(to[i], totalSupply() + i + 1);
}
}
Storage Optimization
- Use
uint8for small numbers - Pack structs
- Use events for non-essential data
Security Considerations
Reentrancy Protection
bool private locked;
modifier nonReentrant() {
require(!locked, "Reentrant call");
locked = true;
_;
locked = false;
}
Access Control
mapping(address => bool) public authorizedMinters;
modifier onlyAuthorized() {
require(authorizedMinters[msg.sender] || msg.sender == owner, "Not authorized");
_;
}
Input Validation
function mint(address to, string memory uri) external {
require(to != address(0), "Invalid address");
require(bytes(uri).length > 0, "Empty URI");
// Mint logic
}
NFT Analytics
Key Metrics
- Floor Price: Lowest listed price
- Volume: Total trading volume
- Holders: Number of unique owners
- Rarity: Statistical rarity scores
Tools
- NFTGo: NFT analytics platform
- Rarity.tools: Rarity rankings
- DappRadar: NFT market data
Future of NFTs
Trends
- Utility NFTs: More than just art
- Gaming: Play-to-earn integration
- Metaverse: Virtual items
- Fractionalization: Split ownership
Challenges
- Gas Costs: Expensive on Ethereum
- Scams: Rug pulls và fake projects
- Market Volatility: Price fluctuations
Kết luận
NFTs đang mở ra khả năng mới cho digital ownership và creativity. Hiểu về standards, marketplaces và security best practices giúp bạn tham gia ecosystem một cách an toàn và hiệu quả.
Tiếp tục học về Blockchain Security trong Bootcamp Blockchain Mastery!
