Passar al contingut principal

Ajudeu a traduir aquesta pàgina


Esteu veient aquest pàgina en anglès perquè encara no l'hem traduïda. Ajudeu-nos a traduir aquest contingut.

Traduïu la pàgina

No conté errors!🐛

Aquesta pàgina no està essent traduïda. De moment hem deixat aquesta pàgina intencionadament en anglès.

ERC-721 Non-Fungible Token Standard

Darrera edició: , Invalid DateTime
Edita la pàgina


What is a Non-Fungible Token?

A Non-Fungible Token (NFT) is used to identify something or someone in a unique way. This type of Token is perfect to be used on platforms that offer collectible items, access keys, lottery tickets, numbered seats for concerts and sports matches, etc. This special type of Token has amazing possibilities so it deserves a proper Standard, the ERC-721 came to solve that!

What is ERC-721?

The ERC-721 introduces a standard for NFT, in other words, this type of Token is unique and can have different value than another Token from the same Smart Contract, maybe due to its age, rarity or even something else like its visual. Wait, visual?

Yes! All NFTs have a uint256 variable called tokenId, so for any ERC-721 Contract, the pair contract address, uint256 tokenId must be globally unique. That said, a dapp can have a "converter" that uses the tokenId as input and outputs an image of something cool, like zombies, weapons, skills or amazing kitties!


  • Accounts
  • Smart Contracts
  • Token standards


The ERC-721 (Ethereum Request for Comments 721), proposed by William Entriken, Dieter Shirley, Jacob Evans, Nastassia Sachs in January 2018, is a Non-Fungible Token Standard that implements an API for tokens within Smart Contracts.

It provides functionalities like to transfer tokens from one account to another, to get the current token balance of an account, to get the owner of a specific token and also the total supply of the token available on the network. Besides these it also has some other functionalities like to approve that an amount of token from an account can be moved by a third party account.

If a Smart Contract implements the following methods and events it can be called an ERC-721 Non-Fungible Token Contract and, once deployed, it will be responsible to keep track of the created tokens on Ethereum.

From EIP-721:


1 function balanceOf(address _owner) external view returns (uint256);
2 function ownerOf(uint256 _tokenId) external view returns (address);
3 function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
4 function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
5 function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
6 function approve(address _approved, uint256 _tokenId) external payable;
7 function setApprovalForAll(address _operator, bool _approved) external;
8 function getApproved(uint256 _tokenId) external view returns (address);
9 function isApprovedForAll(address _owner, address _operator) external view returns (bool);
Mostrar-ho tot
📋 Copiar


1 event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
2 event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);
3 event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
📋 Copiar


Let's see how a Standard is so important to make things simple for us to inspect any ERC-721 Token Contract on Ethereum. We just need the Contract Application Binary Interface (ABI) to create an interface to any ERC-721 Token. As you can see below we will use a simplified ABI, to make it a low friction example. Example

First, make sure you have installed Python library:

1pip install web3
1from web3 import Web3
2from import get_event_data
5w3 = Web3(Web3.HTTPProvider(""))
7ck_token_addr = "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d" # CryptoKitties Contract
9acc_address = "0xb1690C08E213a35Ed9bAb7B318DE14420FB57d8C" # CryptoKitties Sales Auction
11# This is a simplified Contract Application Binary Interface (ABI) of an ERC-721 NFT Contract.
12# It will expose only the methods: balanceOf(address), name(), ownerOf(tokenId), symbol(), totalSupply()
13simplified_abi = [
14 {
15 'inputs': [{'internalType': 'address', 'name': 'owner', 'type': 'address'}],
16 'name': 'balanceOf',
17 'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}],
18 'payable': False, 'stateMutability': 'view', 'type': 'function', 'constant': True
19 },
20 {
21 'inputs': [],
22 'name': 'name',
23 'outputs': [{'internalType': 'string', 'name': '', 'type': 'string'}],
24 'stateMutability': 'view', 'type': 'function', 'constant': True
25 },
26 {
27 'inputs': [{'internalType': 'uint256', 'name': 'tokenId', 'type': 'uint256'}],
28 'name': 'ownerOf',
29 'outputs': [{'internalType': 'address', 'name': '', 'type': 'address'}],
30 'payable': False, 'stateMutability': 'view', 'type': 'function', 'constant': True
31 },
32 {
33 'inputs': [],
34 'name': 'symbol',
35 'outputs': [{'internalType': 'string', 'name': '', 'type': 'string'}],
36 'stateMutability': 'view', 'type': 'function', 'constant': True
37 },
38 {
39 'inputs': [],
40 'name': 'totalSupply',
41 'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}],
42 'stateMutability': 'view', 'type': 'function', 'constant': True
43 },
46ck_extra_abi = [
47 {
48 'inputs': [],
49 'name': 'pregnantKitties',
50 'outputs': [{'name': '', 'type': 'uint256'}],
51 'payable': False, 'stateMutability': 'view', 'type': 'function', 'constant': True
52 },
53 {
54 'inputs': [{'name': '_kittyId', 'type': 'uint256'}],
55 'name': 'isPregnant',
56 'outputs': [{'name': '', 'type': 'bool'}],
57 'payable': False, 'stateMutability': 'view', 'type': 'function', 'constant': True
58 }
61ck_contract = w3.eth.contract(address=w3.toChecksumAddress(ck_token_addr), abi=simplified_abi+ck_extra_abi)
62name =
63symbol = ck_contract.functions.symbol().call()
64kitties_auctions = ck_contract.functions.balanceOf(acc_address).call()
65print(f"{name} [{symbol}] NFTs in Auctions: {kitties_auctions}")
67pregnant_kitties = ck_contract.functions.pregnantKitties().call()
68print(f"{name} [{symbol}] NFTs Pregnants: {pregnant_kitties}")
70# Using the Transfer Event ABI to get info about transferred Kitties.
71tx_event_abi = {
72 'anonymous': False,
73 'inputs': [
74 {'indexed': False, 'name': 'from', 'type': 'address'},
75 {'indexed': False, 'name': 'to', 'type': 'address'},
76 {'indexed': False, 'name': 'tokenId', 'type': 'uint256'}],
77 'name': 'Transfer',
78 'type': 'event'
81# We need the event's signature to filter the logs
82event_signature = w3.sha3(text="Transfer(address,address,uint256)").hex()
84logs = w3.eth.getLogs({
85 "fromBlock": w3.eth.blockNumber - 120,
86 "address": w3.toChecksumAddress(ck_token_addr),
87 "topics": [event_signature]
90# Notes:
91# - 120 blocks is the max range for CloudFlare Provider
92# - If you didn't find any Transfer event you can also try to get a tokenId at:
94# Click to expand the event's logs and copy its "tokenId" argument
96recent_tx = [get_event_data(w3.codec, tx_event_abi, log)["args"] for log in logs]
98kitty_id = recent_tx[0]['tokenId'] # Paste the "tokenId" here from the link above
99is_pregnant = ck_contract.functions.isPregnant(kitty_id).call()
100print(f"{name} [{symbol}] NFTs {kitty_id} is pregnant: {is_pregnant}")
Mostrar-ho tot
📋 Copiar

CryptoKitties Contract has some interesting Events other than the Standard ones.

Let's check two of them, Pregnant and Birth.

1# Using the Pregnant and Birth Events ABI to get info about new Kitties.
2ck_extra_events_abi = [
3 {
4 'anonymous': False,
5 'inputs': [
6 {'indexed': False, 'name': 'owner', 'type': 'address'},
7 {'indexed': False, 'name': 'matronId', 'type': 'uint256'},
8 {'indexed': False, 'name': 'sireId', 'type': 'uint256'},
9 {'indexed': False, 'name': 'cooldownEndBlock', 'type': 'uint256'}],
10 'name': 'Pregnant',
11 'type': 'event'
12 },
13 {
14 'anonymous': False,
15 'inputs': [
16 {'indexed': False, 'name': 'owner', 'type': 'address'},
17 {'indexed': False, 'name': 'kittyId', 'type': 'uint256'},
18 {'indexed': False, 'name': 'matronId', 'type': 'uint256'},
19 {'indexed': False, 'name': 'sireId', 'type': 'uint256'},
20 {'indexed': False, 'name': 'genes', 'type': 'uint256'}],
21 'name': 'Birth',
22 'type': 'event'
23 }]
25# We need the event's signature to filter the logs
26ck_event_signatures = [
27 w3.sha3(text="Pregnant(address,uint256,uint256,uint256)").hex(),
28 w3.sha3(text="Birth(address,uint256,uint256,uint256,uint256)").hex(),
31# Here is a Pregnant Event:
32# -
33pregnant_logs = w3.eth.getLogs({
34 "fromBlock": w3.eth.blockNumber - 120,
35 "address": w3.toChecksumAddress(ck_token_addr),
36 "topics": [ck_event_signatures[0]]
39recent_pregnants = [get_event_data(w3.codec, ck_extra_events_abi[0], log)["args"] for log in pregnant_logs]
41# Here is a Birth Event:
42# -
43birth_logs = w3.eth.getLogs({
44 "fromBlock": w3.eth.blockNumber - 120,
45 "address": w3.toChecksumAddress(ck_token_addr),
46 "topics": [ck_event_signatures[1]]
49recent_births = [get_event_data(w3.codec, ck_extra_events_abi[1], log)["args"] for log in birth_logs]
Mostrar-ho tot
📋 Copiar
  • Etherscan NFT Tracker list the top NFT on Ethereum by transfers volume.
  • CryptoKitties is a game centered around breedable, collectible, and oh-so-adorable creatures we call CryptoKitties.
  • Sorare is a global fantasy football game where you can collect limited editions collectibles, manage your teams and compete to earn prizes.
  • The Ethereum Name Service (ENS) offers a secure & decentralised way to address resources both on and off the blockchain using simple, human-readable names.
  • POAP delivers free NFTs to people who attend events or complete specific actions. POAPs are free to create and distribute.
  • Unstoppable Domains is a San Francisco-based company building domains on blockchains. Blockchain domains replace cryptocurrency addresses with human-readable names and can be used to enable censorship-resistant websites.
  • Gods Unchained Cards is a TCG on the Ethereum blockchain that uses NFT's to bring real ownership to in-game assets.
  • Bored Ape Yacht Club is a collection of 10,000 unique NFTs, which, as well as being a provably-rare piece of art, acts as a membership token to the club, providing member perks and benefits that increase over time as a result of community efforts.

Further reading

Ha estat útil aquest article?