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:
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);
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"