2

I am making some erc721 transactions. I can retrieve those transactions using the etherscan api like this

https://api.etherscan.io/api?module=contract&action=txlist&address=0xb30c5db4ca271653535b846f237c4a8d0d6fb32d&startblock=0&endblock=99999999&page=1&offset=20&sort=desc&apikey=

{"blockNumber":"6878479","timeStamp":"1544697153","hash":"0x68dffa9cd6b2f408a5bc1bb9c3cc9a0344e9e7e71029e551f3a5b35673bad362","nonce":"53","blockHash":"0x2e0968d71243a531b80db3a1feba3b0b16f664ae16cf3a992e4fd3fd8a40667c","transactionIndex":"153","from":"0xb30c5db4ca271653535b846f237c4a8d0d6fb32d","to":"0x06012c8cf97bead5deae237070f9587f8e7a266d","value":"0","gas":"69379","gasPrice":"5100000000","isError":"0","txreceipt_status":"1","input":"0xa9059cbb0000000000000000000000003b7b6f8c1b9fe9be5b59326a3e8c695fce3a4e0800000000000000000000000000000000000000000000000000000000000c90c4","contractAddress":"","cumulativeGasUsed":"7480061","gasUsed":"69379","confirmations":"4750"}

This is a cryptokitties transaction. However, how do I distinguish this from a erc20 transaction. I checked their other apis https://etherscan.io/apis#contracts

but, none of them seem to explicitly state the type of contract/transaction.

0

That link is broken, but I'll give it a whirl.

The problem

We would like to use the Etherscan Developer API to review transactions against a given contract address and find out:

  1. Does this contract implement ERC-721?
  2. What is the list of token transfers on this contract or other useful info.

There is a lot you can do with the Etherscan Developer API. For example, here's one URL that pulls data from Ethereum Mainnet -> Etherscan -> JSON parser -> Shields.io and renders it as an image to calculate the number of Su Squares remaining for sale:

enter image description here

Source: https://img.shields.io/badge/dynamic/json.svg?label=Su+Squares+available&url=https%3A%2F%2Fapi.etherscan.io%2Fapi%3Fmodule%3Daccount%26action%3Dtokenbalance%26contractaddress%3D0xE9e3F9cfc1A64DFca53614a0182CFAD56c10624F%26address%3D0xE9e3F9cfc1A64DFca53614a0182CFAD56c10624F%26tag%3Dlatest%26apikey%3DYourApiKeyToken&query=%24.result

Solution

First, the source documentation is at https://etherscan.io/apis

It is not possible to determine which contracts support ERC-721. Source: The ERC-721 Validator. So we are going to have to use some approximation.

Here is a some ERC-721 contract, I won't tell you which one: 0xE9e3F9cfc1A64DFca53614a0182CFAD56c10624F.

We can use a special query against Etherscan to guess if it is ERC-721 compliant. This will check the original contract creation code (limiting the page and offset parameters).

http://api.etherscan.io/api?module=account&action=txlist&address=0xE9e3F9cfc1A64DFca53614a0182CFAD56c10624F&startblock=0&endblock=99999999&sort=asc&apikey=YourApiKeyToken&page=1&offset=1

Just load that file and grep that code for 42842e0e, the function signature for safeTransferFrom(address,address,uint256) and boom you found it! This makes me pretty confident because I don't expect non-721 contracts to implement that method. This approach is not fail-safe, because there are function signature collisions (expect to try 500k attempts* to collide with that one), because contracts can lie, and because a contract can use a proxy to another backing implementation.

Likewise, you can query more transactions and filter on input begins with 42842e0e to find transfers. This is still a big approximation because those transfers might fail and also because there are many ways (including internal transactions) to transfer rather than using the 42842e0e function.

Discussion

This is a fun tool to test and have fun with, but for actual analysis you will want to use a real tool.

  • 2^32 byte combinations * 0.5 collision luck factor / ~5000 bytes per contract initialization

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.