Ostatnia edycja:, Nieprawidłowa data/godzina
Wstęp
Co to jest niezamienny token?
Non-Fungible Token (NFT) służy do identyfikacji czegoś lub kogoś w unikalny sposób. Ten typ Tokena doskonale nadaje się do wykorzystania na platformach oferujących przedmioty kolekcjonerskie, klucze dostępu, bilety na loterię, numerowane miejsca na koncerty, mecze sportowe itp. Ten specjalny rodzaj Tokena ma niesamowite możliwości, więc zasługuje na odpowiedni Standard, do którego trafił ERC-721 rozwiązać to!
Co to jest ERC-721?
ERC-721 wprowadza standard dla NFT, innymi słowy, ten typ Tokena jest unikalny i może mieć inną wartość niż inny Token z tego samego Smart Contracta, być może ze względu na jego wiek, rzadkość lub nawet coś innego, jak jego wygląd. wizualny?
Tak! Wszystkie NFT mająuint256
zmienna tzwIdentyfikator tokena
, więc dla dowolnego kontraktu ERC-721 paraadres kontraktu, uint256 tokenId
musi być globalnie unikalny. To powiedziawszy, dapp może mieć „konwerter”, który używaIdentyfikator tokena
jako dane wejściowe i wyjściowe obraz czegoś fajnego, na przykład zombie, broń, umiejętności lub niesamowite kotki!
Wymagania wstępne
- Konta
- Inteligentne kontrakty
- Standardy tokenów
Ciało
ERC-721 (Ethereum Request for Comments 721), zaproponowany przez Williama Entrikena, Dietera Shirleya, Jacoba Evansa, Nastassię Sachs w styczniu 2018 r., to standard tokenów niezamiennych, który implementuje interfejs API dla tokenów w ramach inteligentnych kontraktów.
Zapewnia takie funkcjonalności, jak przenoszenie tokenów z jednego konta na drugie, uzyskiwanie aktualnego salda tokenów na koncie, uzyskiwanie właściciela konkretnego tokena, a także całkowitej podaży tokena dostępnego w sieci. Oprócz tego posiada również kilka innych funkcjonalności takie jak zatwierdzanie, że ilość tokena z konta może zostać pobrana przez konto osoby trzeciej.
Jeśli Smart Contract implementuje następujące metody i zdarzenia, można go nazwać kontraktem ERC-721 Non-Fungible Token Contract, a po wdrożeniu będzie odpowiedzialny za śledzenie utworzonych tokenów w Ethereum.
ZEIP-721(otwiera się w nowej karcie)↗:
Metody
1
funkcja balanceOf(address _owner) zwraca widok zewnętrzny (uint256);
2funkcja OwnerOf(uint256 _tokenId) zwraca widok zewnętrzny (adres);
3funkcja safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) zewnętrzna płatna;
4funkcja safeTransferFrom(adres _from, adres _to, uint256 _tokenId) zewnętrzna płatna;
5funkcja transferFrom(adres _from, adres _to, uint256 _tokenId) zewnętrzna płatna;
6funkcja zatwierdzenie(adres _approved, uint256 _tokenId) zewnętrzne płatne;
7funkcja setApprovalForAll(address _operator, bool _approved) zewnętrzna;
8funkcja getApproved(uint256 _tokenId) zwraca widok zewnętrzny (adres);
9funkcja isApprovedForAll(address _owner, address _operator) zwraca widok zewnętrzny (bool);
10
Pokaż wszystko
Kopiuj
Wydarzenia
1transfer zdarzenia (adres indeksowany _from, adres indeksowany _to, uint256 indeksowany _tokenId);
2zatwierdzenie zdarzenia (adres indeksowany _właściciel, adres indeksowany _zatwierdzony, uint256 indeksowany _tokenId);
3event ApprovalForAll(adres indeksowany _właściciel, adres indeksowany _operator, bool _zatwierdzony);
4
Kopiuj
Przykłady
Zobaczmy, w jaki sposób standard jest tak ważny, aby ułatwić nam kontrolę dowolnego kontraktu tokena ERC-721 w Ethereum. Potrzebujemy tylko binarnego interfejsu aplikacji kontraktu (ABI), aby utworzyć interfejs do dowolnego tokena ERC-721. Jak widać poniżej, użyjemy uproszczonego ABI, aby był to przykład o niskim współczynniku tarcia.
Web3.py Przykład
Najpierw upewnij się, że zainstalowałeśWeb3.py(otwiera się w nowej karcie)↗Biblioteka Pythona:
1pip zainstaluj web3
2
1zweb3importWeb3
2zweb3._utils.wydarzeniaimportget_event_data
3
4
5w3=Web3(Web3.Dostawca HTTP(„https://cloudflare-eth.com”))
6
7ck_token_addr= "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d" # Umowa CryptoKitties
8
9adres_akta= "0xb1690C08E213a35Ed9bAb7B318DE14420FB57d8C" # Aukcja sprzedaży CryptoKitties
10
11# To jest uproszczony interfejs binarny aplikacji kontraktowej (ABI) kontraktu ERC-721 NFT.
12# Ujawni tylko metody: balanceOf(address), name(), OwnerOf(tokenId), symbol(), totalSupply()
13uproszczony_abi= [
14 {
15 „wejścia”: [{„Typ wewnętrzny”: 'adres', 'nazwa': 'właściciel', 'typ': 'adres'}],
16 'nazwa': „bilans”,
17 „wyjścia”: [{„Typ wewnętrzny”: 'uint256', 'nazwa': '', 'typ': 'uint256'}],
18 'płatny': FAŁSZ, „zmienność stanu”: 'pogląd', 'typ': 'funkcjonować', 'stały': PRAWDA
19 },
20 {
21 „wejścia”: [],
22 'nazwa': 'nazwa',
23 „wyjścia”: [{„Typ wewnętrzny”: 'strunowy', 'nazwa': '', 'typ': 'strunowy'}],
24 „zmienność stanu”: 'pogląd', 'typ': 'funkcjonować', 'stały': PRAWDA
25 },
26 {
27 „wejścia”: [{„Typ wewnętrzny”: 'uint256', 'nazwa': „identyfikator tokena”, 'typ': 'uint256'}],
28 'nazwa': 'właściciel',
29 „wyjścia”: [{„Typ wewnętrzny”: 'adres', 'nazwa': '', 'typ': 'adres'}],
30 'płatny': FAŁSZ, „zmienność stanu”: 'pogląd', 'typ': 'funkcjonować', 'stały': PRAWDA
31 },
32 {
33 „wejścia”: [],
34 'nazwa': 'symbol',
35 „wyjścia”: [{„Typ wewnętrzny”: 'strunowy', 'nazwa': '', 'typ': 'strunowy'}],
36 „zmienność stanu”: 'pogląd', 'typ': 'funkcjonować', 'stały': PRAWDA
37 },
38 {
39 „wejścia”: [],
40 'nazwa': „całkowita podaż”,
41 „wyjścia”: [{„Typ wewnętrzny”: 'uint256', 'nazwa': '', 'typ': 'uint256'}],
42 „zmienność stanu”: 'pogląd', 'typ': 'funkcjonować', 'stały': PRAWDA
43 },
44]
45
46ck_extra_abi= [
47 {
48 „wejścia”: [],
49 'nazwa': „ciężarne kotki”,
50 „wyjścia”: [{'nazwa': '', 'typ': 'uint256'}],
51 'płatny': FAŁSZ, „zmienność stanu”: 'pogląd', 'typ': 'funkcjonować', 'stały': PRAWDA
52 },
53 {
54 „wejścia”: [{'nazwa': „_identyfikator kotka”, 'typ': 'uint256'}],
55 'nazwa': 'jest w ciąży',
56 „wyjścia”: [{'nazwa': '', 'typ': „bool”}],
57 'płatny': FAŁSZ, „zmienność stanu”: 'pogląd', 'typ': 'funkcjonować', 'stały': PRAWDA
58 }
59]
60
61ck_kontrakt=w3.et.kontrakt(adres=w3.adres_sumy_kontrolnej(ck_token_addr),abi=uproszczony_abi+ck_extra_abi)
62nazwa=ck_kontrakt.Funkcje.nazwa().dzwonić()
63symbol=ck_kontrakt.Funkcje.symbol().dzwonić()
64aukcje_koci=ck_kontrakt.Funkcje.bilansZ(adres_akta).dzwonić()
65wydrukować(F"{nazwa}[{symbol}] NFT na aukcjach:{aukcje_koci}")
66
67kotki w ciąży=ck_kontrakt.Funkcje.kotki w ciąży().dzwonić()
68wydrukować(F"{nazwa}[{symbol}] NFT Ciąża:{kotki w ciąży}")
69
70# Korzystanie z ABI zdarzenia transferu w celu uzyskania informacji o przeniesionych kotkach.
71tx_event_abi= {
72 'anonimowy': FAŁSZ,
73 „wejścia”: [
74 {„indeksowane”: FAŁSZ, 'nazwa': 'z', 'typ': 'adres'},
75 {„indeksowane”: FAŁSZ, 'nazwa': 'Do', 'typ': 'adres'},
76 {„indeksowane”: FAŁSZ, 'nazwa': „identyfikator tokena”, 'typ': 'uint256'}],
77 'nazwa': 'Przenosić',
78 'typ': 'wydarzenie'
79}
80
81# Potrzebujemy podpisu zdarzenia, aby przefiltrować dzienniki
82sygnatura_zdarzenia=w3.keccak(tekst="Transfer(adres,adres,uint256)").klątwa()
83
84logi=w3.et.get_logs({
85 „z bloku”:w3.et.zablokuj numer- 120,
86 "adres":w3.adres_sumy_kontrolnej(ck_token_addr),
87 „tematy”: [sygnatura_zdarzenia]
88})
89
90# Uwagi:
91# - Zwiększ liczbę bloków ze 120, jeśli nie zostanie zwrócone żadne zdarzenie Transfer.
92# - Jeśli nie znalazłeś żadnego zdarzenia Transfer, możesz również spróbować uzyskać identyfikator tokena pod adresem:
93# https://etherscan.io/address/0x06012c8cf97BEaD5deAe237070F9587f8E7A266d#events
94# Kliknij, aby rozwinąć dzienniki zdarzenia i skopiować jego argument „tokenId”.
95ostatnie_tx= [get_event_data(w3.kodek,tx_event_abi,dziennik)[„argumenty”] DodziennikWlogi]
96
97Jeśliostatnie_tx:
98kotek_identyfikator=ostatnie_tx[0][„identyfikator tokena”] # Wklej tutaj „tokenId” z powyższego łącza
99jest w ciąży=ck_kontrakt.Funkcje.jest w ciąży(kotek_identyfikator).dzwonić()
100 wydrukować(F"{nazwa}[{symbol}] NFT{kotek_identyfikator}jest w ciąży:{jest w ciąży}")
101
Pokaż wszystko
Kopiuj
Kontrakt CryptoKitties ma kilka interesujących wydarzeń innych niż standardowe.
Sprawdźmy dwa z nich,W ciąży
INarodziny
.
1# Korzystanie z ABI wydarzeń związanych z ciążą i porodem, aby uzyskać informacje o nowych kotkach.
2ck_extra_events_abi= [
3 {
4 'anonimowy': FAŁSZ,
5 „wejścia”: [
6 {„indeksowane”: FAŁSZ, 'nazwa': 'właściciel', 'typ': 'adres'},
7 {„indeksowane”: FAŁSZ, 'nazwa': „identyfikator przełożonej”, 'typ': 'uint256'},
8 {„indeksowane”: FAŁSZ, 'nazwa': „identyfikator ojca”, 'typ': 'uint256'},
9 {„indeksowane”: FAŁSZ, 'nazwa': „Ochłodzenie EndBlock”, 'typ': 'uint256'}],
10 'nazwa': 'W ciąży',
11 'typ': 'wydarzenie'
12 },
13 {
14 'anonimowy': FAŁSZ,
15 „wejścia”: [
16 {„indeksowane”: FAŁSZ, 'nazwa': 'właściciel', 'typ': 'adres'},
17 {„indeksowane”: FAŁSZ, 'nazwa': „identyfikator kotka”, 'typ': 'uint256'},
18 {„indeksowane”: FAŁSZ, 'nazwa': „identyfikator przełożonej”, 'typ': 'uint256'},
19 {„indeksowane”: FAŁSZ, 'nazwa': „identyfikator ojca”, 'typ': 'uint256'},
20 {„indeksowane”: FAŁSZ, 'nazwa': „geny”, 'typ': 'uint256'}],
21 'nazwa': 'Narodziny',
22 'typ': 'wydarzenie'
23 }]
24
25# Potrzebujemy podpisu zdarzenia, aby przefiltrować dzienniki
26ck_event_signatures= [
27w3.keccak(tekst="W ciąży (adres, uint256, uint256, uint256)").klątwa(),
28w3.keccak(tekst="Narodziny (adres, uint256, uint256, uint256, uint256)").klątwa(),
29]
30
31# Oto wydarzenie w ciąży:
32# - https://etherscan.io/tx/0xc97eb514a41004acc447ac9d0d6a27ea6da305ac8b877dff37e49db42e1f8cef#eventlog
33dzienniki ciąży=w3.et.get_logs({
34 „z bloku”:w3.et.zablokuj numer- 120,
35 "adres":w3.adres_sumy_kontrolnej(ck_token_addr),
36 „tematy”: [ck_event_signatures[0]]
37})
38
39ostatnie_ciąży= [get_event_data(w3.kodek,ck_extra_events_abi[0],dziennik)[„argumenty”] DodziennikWdzienniki ciąży]
40
41# Oto wydarzenie narodzin:
42# - https://etherscan.io/tx/0x3978028e08a25bb4c44f7877eb3573b9644309c044bf087e335397f16356340a
43dzienniki_narodzin=w3.et.get_logs({
44 „z bloku”:w3.et.zablokuj numer- 120,
45 "adres":w3.adres_sumy_kontrolnej(ck_token_addr),
46 „tematy”: [ck_event_signatures[1]]
47})
48
49ostatnie_narodziny= [get_event_data(w3.kodek,ck_extra_events_abi[1],dziennik)[„argumenty”] DodziennikWdzienniki_narodzin]
50
Pokaż wszystko
Kopiuj
Popularne NFT
- Etherscan NFT Tracker(otwiera się w nowej karcie)↗wymień najlepsze NFT na Ethereum według wolumenu transferów.
- CryptoKitties(otwiera się w nowej karcie)↗to gra skupiona wokół nadających się do rozmnażania, kolekcjonowania i jakże uroczych stworzeń, które nazywamy CryptoKitties.
- Siostra(otwiera się w nowej karcie)↗to globalna gra fantasy football, w której możesz zbierać przedmioty kolekcjonerskie z limitowanych edycji, zarządzać drużynami i rywalizować o nagrody.
- Usługa nazw Ethereum (ENS)(otwiera się w nowej karcie)↗oferuje bezpieczny i zdecentralizowany sposób adresowania zasobów zarówno w łańcuchu blokowym, jak i poza nim, przy użyciu prostych, czytelnych dla człowieka nazw.
- POAP(otwiera się w nowej karcie)↗dostarcza darmowe NFT osobom, które biorą udział w wydarzeniach lub wykonują określone działania. POAP można tworzyć i rozpowszechniać za darmo.
- Niepowstrzymane domeny(otwiera się w nowej karcie)↗to firma z siedzibą w San Francisco budująca domeny na blockchain. Domeny Blockchain zastępują adresy kryptowalut nazwami czytelnymi dla człowieka i mogą być używane do włączania stron internetowych odp*rnych na cenzurę.
- Bogowie Unchained Cards(otwiera się w nowej karcie)↗to TCG na łańcuchu blokowym Ethereum, który wykorzystuje NFT do zapewnienia rzeczywistej własności zasobów w grze.
- Klub jachtowy znudzonej małpy(otwiera się w nowej karcie)↗to zbiór 10 000 unikalnych NFT, który oprócz tego, że jest rzadkim dziełem sztuki, działa jako żeton członkowski klubu, zapewniając członkom korzyści i korzyści, które zwiększają się z czasem w wyniku wysiłków społeczności.
Dalsza lektura
- EIP-721: ERC-721 Non-Fungible Token Standard(otwiera się w nowej karcie)↗
- OpenZeppelin — dokumenty ERC-721(otwiera się w nowej karcie)↗
- OpenZeppelin — implementacja ERC-721(otwiera się w nowej karcie)↗
- Alchemy NFT API(otwiera się w nowej karcie)↗