Etherscan – How to Obtain TokenID of ERC721 Token via Etherscan API (e.g. CryptoKitty TokenID)

cryptokittiesetherscan

I want to be able to find the TokenID of a Crypto Kitty being sold.

The transaction returned from by the etherscan API is such:

{
  blockNumber: '11711690',
  timeStamp: '1611403229',
  hash: '0x8f8d4e163e90c8db91672f443b0896f157d45fc32c3ccf74d131137eedbdd896',
  nonce: '4',
  blockHash: '0xbdd67604d6cc7844f151a38360753ad96fa234bd9cf199c6cf14317ebb4fd0ad',
  transactionIndex: '147',
  from: '0x65274ae6d0d4f88818b600c4b3435c868f5dad4c',
  to: '0xb1690c08e213a35ed9bab7b318de14420fb57d8c',
  value: '2527858781343926',
  gas: '164016',
  gasPrice: '43000000000',
  isError: '1',
  txreceipt_status: '0',
  input: '0x454a2ab3000000000000000000000000000000000000000000000000000000000005a5a3',
  contractAddress: '',
  cumulativeGasUsed: '9793966',
  gasUsed: '27036',
  confirmations: '5702'
}

By looking at the transaction on etherscan I can see that the TokenID is 587058 – https://etherscan.io/tx/0xc7e09024a41841d6acb5933ab983a68bb4433a94e3167a2a893be3ea4387fad6

However that is not recorded anywhere on the transaction… Is there any way that I can derive the token ID? Or, is there an alternative way that I can find the token programmatically/via API? I intend to use the TokenID to then obtain further information about the particular Kitty.

Best Answer

Very easy.

Get the Transfer events from the transaction hash. using tronscan api.

And find the token ID from the event.

You can use this API: https://api.etherscan.io/api?module=logs&action=getLogs&address=0x06012c8cf97bead5deae237070f9587f8e7a266d&topic0=0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef&apikey=YourApiKeyToken

It will give all the latest transactions. You may sort it through it according to your particular transaction.

Enjoy :)

Related Topic