Ipfs

如何顯示從公共地址開始的 ERC721 項目列表

  • May 16, 2018

我想更多地了解這個 ERC721 不可替代代幣。

我在 KnownOrigin 上買了一些加密貓(非 721)和一些藝術品,現在我想在網頁上展示它們。

對於 Cryptokitties,我正在使用公共地址聯繫 Cryptokitties API 並獲取所有資訊

https://api.cryptokitties.co/kitties?owner_wallet_address=PUBLIC_ADDRESS&limit=100&offset=0

{
"offset": 0,
"limit": 20,
"kitties": [
   {
       "id": 732654,
       "name": null,
       "image_url": "https://storage.googleapis.com/ck-kitty-image/0x06012c8cf97bead5deae237070f9587f8e7a266d/732654.svg",
       "image_url_cdn": "https://img.cn.cryptokitties.co/0x06012c8cf97bead5deae237070f9587f8e7a266d/732654.svg",
       "generation": 10,
       "created_at": "2018-05-02T17:21:13.000Z",
       "color": "mintgreen",
       "is_fancy": false,
       "is_exclusive": false,
       "fancy_type": null,
       "language": "en",
       "status": {
           "cooldown": 1442113251014,
           "cooldown_index": 5,
           "is_ready": true,
           "is_gestating": false
       },
       "purrs": {
           "count": 0,
           "is_purred": false
       },
       "watchlist": {
           "count": 0,
           "is_watchlisted": false
       },
       "hatched": true,
       "auction": {},
       "owner": {
           "address": "0x15d82290c2d78764fca6e158b5af5e2e9ddb46a8",
           "nickname": "Ziba Leah",
           "image": "13"
       },
       "sire": {
           "id": 193991,
           "name": null,
           "image_url": "https://storage.googleapis.com/ck-kitty-image/0x06012c8cf97bead5deae237070f9587f8e7a266d/193991.svg",
           "image_url_cdn": "https://img.cn.cryptokitties.co/0x06012c8cf97bead5deae237070f9587f8e7a266d/193991.svg",
           "generation": 5,
           "created_at": "2017-12-09T22:25:59.000Z",
           "color": "strawberry",
           "is_fancy": false,
           "is_exclusive": false,
           "fancy_type": null
       },
       "matron": {
           "id": 730675,
           "name": null,
           "image_url": "https://storage.googleapis.com/ck-kitty-image/0x06012c8cf97bead5deae237070f9587f8e7a266d/730675.svg",
           "image_url_cdn": "https://img.cn.cryptokitties.co/0x06012c8cf97bead5deae237070f9587f8e7a266d/730675.svg",
           "generation": 9,
           "created_at": "2018-04-30T14:41:12.000Z",
           "color": "mintgreen",
           "is_fancy": false,
           "is_exclusive": false,
           "fancy_type": null
       }
   }
]
"total": 1

}

據我了解,一些元數據被保存到區塊鏈中。所以我從幾個 API 服務(blockcypher、etherscan 等)呼叫 API 並接收我的令牌列表,例如:

{
"address": "PUB ADDRESS",
"total_received": 150015053924110913,
"total_sent": 30815090241240544,
"balance": 119199963682870369,
"unconfirmed_balance": 0,
"final_balance": 119199963682870369,
"n_tx": 13,
"unconfirmed_n_tx": 0,
"final_n_tx": 13,
"nonce": 9,
"pool_nonce": 9,
"txrefs": [
   {
       "tx_hash": "a73c7c191012a0a26cfe434d49a6ff7cd8a94002c6e50f733b7cdd19a3a5efc7",
       "block_height": 5544476,
       "tx_input_n": 0,
       "tx_output_n": -1,
       "value": 8582063000000000,
       "ref_balance": 119199963682870369,
       "confirmations": 3677,
       "confirmed": "2018-05-02T16:56:18Z",
       "double_spend": false
   },
   {
       "tx_hash": "00dab2130486c9c5fddf1896347a56ce776dde0131a1d639ad889f8e07436641",
       "block_height": 5544474,
       "tx_input_n": 0,
       "tx_output_n": -1,
       "value": 141419687500000,
       "ref_balance": 127782026682870369,
       "confirmations": 3679,
       "confirmed": "2018-05-02T16:56:11Z",
       "double_spend": false
   },
   {
       "tx_hash": "26cad46648d402ed5d784ac9406d896da68d3f82472568a45fe42023cf7438a2",
       "block_height": 5544471,
       "tx_input_n": 0,
       "tx_output_n": -1,
       "value": 128380000000000,
       "ref_balance": 127923446370370369,
       "confirmations": 3682,
       "confirmed": "2018-05-02T16:55:22Z",
       "double_spend": false
   },
   {
       "tx_hash": "032bde82867e4df40f26c75cbb88b1a6853ff379f65cdb3645e90ece61860e20",
       "block_height": 5544469,
       "tx_input_n": 0,
       "tx_output_n": -1,
       "value": 8399925000000000,
       "ref_balance": 128051826370370369,
       "confirmations": 3684,
       "confirmed": "2018-05-02T16:54:46Z",
       "double_spend": false
   },
   {
       "tx_hash": "8d4f922977ae6a662cbd09cf49719b17ac213a88f4d02b4dd4a53206fc458794",
       "block_height": 5532550,
       "tx_input_n": -1,
       "tx_output_n": 0,
       "value": 2521768148157,
       "ref_balance": 136451751370370369,
       "confirmations": 15603,
       "confirmed": "2018-04-30T14:24:18Z",
       "double_spend": false
   },
   {
       "tx_hash": "64a8fc9012dc23443b8b1d66bf1dd4aad8501552fdd17146e4a0479612689169",
       "block_height": 5532550,
       "tx_input_n": 0,
       "tx_output_n": -1,
       "value": 1838649731111120,
       "ref_balance": 136449229602222212,
       "confirmations": 15603,
       "confirmed": "2018-04-30T14:24:18Z",
       "double_spend": false
   },
   {
       "tx_hash": "e061d7c8e6e5775cdc4029244e0da568412a15608592cd95abd7b4ad965b9cba",
       "block_height": 5532491,
       "tx_input_n": 0,
       "tx_output_n": -1,
       "value": 8319940000000000,
       "ref_balance": 138287879333333332,
       "confirmations": 15662,
       "confirmed": "2018-04-30T14:08:53Z",
       "double_spend": false
   },
   {
       "tx_hash": "601d8d3b02c20cb0a3413aafd738f01340ceb0f006e76294b684f12eee51f487",
       "block_height": 5532066,
       "tx_input_n": -1,
       "tx_output_n": 0,
       "value": 2997693382888,
       "ref_balance": 146607819333333332,
       "confirmations": 16087,
       "confirmed": "2018-04-30T12:17:29Z",
       "double_spend": false
   },
   {
       "tx_hash": "30498f034eedb42762386a36ed12c290c7e13fc9e912afbc21f7646ddcf2a550",
       "block_height": 5532066,
       "tx_input_n": 0,
       "tx_output_n": -1,
       "value": 1901140804494000,
       "ref_balance": 146604821639950444,
       "confirmations": 16087,
       "confirmed": "2018-04-30T12:17:29Z",
       "double_spend": false
   },
   {
       "tx_hash": "debfb135948a8daf10df225f7f462be27a9fe2064379120c5464b129386a3e71",
       "block_height": 5532064,
       "tx_input_n": -1,
       "tx_output_n": 0,
       "value": 9534462579868,
       "ref_balance": 148505962444444444,
       "confirmations": 16089,
       "confirmed": "2018-04-30T12:17:11Z",
       "double_spend": false
   },
   {
       "tx_hash": "b267fe9b152176dfa67ee4a8b773069793d0cfb42b6fce2350990f057dac92a5",
       "block_height": 5532064,
       "tx_input_n": 0,
       "tx_output_n": -1,
       "value": 1408372018135424,
       "ref_balance": 148496427981864576,
       "confirmations": 16089,
       "confirmed": "2018-04-30T12:17:11Z",
       "double_spend": false
   },
   {
       "tx_hash": "ca0b0f8de001df25c39f3cd479f981a37b5ff348b23c8c3b2cbe596aabfc2a27",
       "block_height": 5532062,
       "tx_input_n": 0,
       "tx_output_n": -1,
       "value": 95200000000000,
       "ref_balance": 149904800000000000,
       "confirmations": 16091,
       "confirmed": "2018-04-30T12:16:41Z",
       "double_spend": false
   },
   {
       "tx_hash": "390a3231fd3a7fa80b52bdbc6f97eee1217bc026fdbf8e41a59bafda5160b5d4",
       "block_height": 5531712,
       "tx_input_n": -1,
       "tx_output_n": 0,
       "value": 150000000000000000,
       "ref_balance": 150000000000000000,
       "confirmations": 16441,
       "confirmed": "2018-04-30T10:50:00Z",
       "double_spend": false
   }
],
"tx_url": "https://api.blockcypher.com/v1/eth/main/txs/"

}

我希望此時能以某種方式看到儲存在鏈上的元數據。

我在哪裡可以從我的公共地址獲取這些資訊?

它是否與我正在聯繫的 API 有關(也許他們沒有在響應中顯示所有元數據)?

據我了解,我必須在某個地方獲得一個 ID 才能從 IPFS 獲取元數據。我在哪裡可以從交易列表/公共地址中找到這個 ID?

提前致謝

大多數 ERC721 實現了一種方法來獲取分配給使用者的令牌。

所以“標準”方法是這樣工作的:

  • 拿到契約
  • 獲取目前使用者的餘額
  • 通過“tokenOfOwnerByIndex”(或類似的)獲取單個項目
  • 通過 getItem 方法(getFighter、getKitty 等)獲取項目的元數據

CryptoFighters 的一個例子可能是這樣的(使用 web3js):

var CRYPTOFIGHTERS_ADDRESS = "0x87d598064c736dd0C712D329aFCFAA0Ccc1921A1";
var CRYPTOFIGHTERS_ABI = [.... TOO LONG ... ]
var CRYPTOFIGHTERS_API = web3.eth.contract(CRYPTOFIGHTERS_ABI).at(CRYPTOFIGHTERS_ADDRESS);

CRYPTOFIGHTERS_API.balanceOf(web3.eth.accounts[0], function(e, s)
{
 totalFighters = parseInt(s);
 for (i = 0; i < totalFighters; i++)
 {
   CRYPTOFIGHTERS_API.tokensOfOwnerByIndex(web3.eth.accounts[0],i, function(error, success) 
   {
      if (success.c[0] > 0)
       loadFighter(success.c[0]);
   });
 }
});      


function loadFighter(id)
{
   CRYPTOFIGHTERS_API.getFighter(id, function(error, success) 
   { 
     console.log(JSON.stringify(success)); 
     cryptofighters.push(JSON.stringify(success));
});
}

相同的方法可以用於 CryptoKitties 和其中的大多數。智能合約中的方法可以稍微改變,但方法是一樣的。

請注意

Crypto Kitties 方法“太慢”,所以大多數時候給出“0”作為答案。建議是使用他們的 API。其他平台也一樣,開發者建議使用他們特定的API

引用自:https://ethereum.stackexchange.com/questions/47399