0

I am unable to find the correct API call format to download the input data field from the event log of each transaction - is there a way to use API key to download this information?

I am referring to downloading the data of this input data field: enter image description here

2 Answers 2

1

You can use Etherscan Event Log API, which fetches up to 1000 events for a given range of blocks (if there are more than 1000 events in the given range, then only the first 1000 events are fetched).

For each event, it returns the following object:

{
    address         : ...,
    topics          : [ ... ],
    data            : ...,
    blockNumber     : ...,
    timeStamp       : ...,
    gasPrice        : ...,
    gasUsed         : ...,
    logIndex        : ...,
    transactionHash : ...,
    transactionIndex: ...
}

The value of the inputData field can be found within the topics and data fields.

More precisely, the topics field is an array which consists of the event signature hash (first item) and each one of the event's indexed parameter values (second item onward), while the data field is a string which consists of the concatenation of the event's unindexed parameter values.

Here is a coding example:

const request = require("request");

const CONTRACT_ADDRESS  = "...";
const ETHERSCAN_API_KEY = "...";
const ETHERSCAN_API_URL = "http://api.etherscan.io/api?module=logs&action=getLogs&address=" + CONTRACT_ADDRESS + "&apikey=" + ETHERSCAN_API_KEY;

const MAX_TIMEOUT = 10000;
const MAX_RESULTS = 1000;

function scan(fromBlock, toBlock) {
    request(`${ETHERSCAN_API_URL}&fromBlock=${fromBlock}&toBlock=${toBlock}`, {timeout: MAX_TIMEOUT}, function(error, response, body) {
        const parsed = parse(body);
        if (parsed.result) {
            if (parsed.result.length < MAX_RESULTS) {
                for (const event of parsed.result)
                    console.log(event.topics.slice(1), event.data);
            }
            else {
                console.log("warning: too many events");
                for (const event of parsed.result)
                    console.log(event.topics.slice(1), event.data);
            }
        }
        else {
            console.log("error:", error);
        }
    });
}

function parse(str) {
    try {
        return JSON.parse(str);
    }
    catch (error) {
        return {};
    }
}

scan(0,9000000);
2
  • Thanks for this - however, the above still cannot download the input data. For example see this specific transaction: etherscan.io/tx/… I want to download the Input data field inside the overview, the Etherscan Event Log does not contain this field it seems
    – cg202220
    Commented Feb 23, 2020 at 23:24
  • @cg202220: What do you mean "see this transaction"? Your question says "from the event log". Was there an event during this transaction? Otherwise, you should change your question. My answer was under the assumption that you are looking for event data. Commented Feb 24, 2020 at 0:24
0

Assuming you are trying to find the inputs for transactions from a specific address, you may be better served using the account API.

https://api.etherscan.com/api
?module=account
&action=txlist
&address=0x16e7352bb889c5fa3adf59d34c1b4e401e63c223
&startblock=0
&endblock=99999999
&sort=asc
&apikey="your API key"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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