Get CSV Export Logs
Overview
The Get CSV Export Logs endpoint obtains data on interactions with smart contracts by analyzing their
log events. The distinctive feature of this endpoint is the output format in comma-separated values (CSV),
which can be saved to a file physically located on your machine or in a cloud. At least one of the following
parameters must be specified: topic_0
, topic_1
, topic_2
, topic_3
, contract
, or origin
. The range
should be defined by either block_number
, timestamp
, or block_hash
.
Stream Interruptions and CU Limit
To avoid spending more than a certain number of computational units, it is recommended to use the cu_limit
parameter. In the event of a data stream interruption or when the CU limit is reached, it is advisable to utilize
the offset
parameter. This ensures that the stream resumes with identical parameters, starting from the last received
item. To implement this, set the value for the offset
parameter to the ID of the last received item.
Multiple values can be set for these parameters: topic_0
, topic_1
, topic_2
, topic_3
,
and contract
, with a maximum of five items each.
Usage
In this example, we receive all log events with the given topics on the USDT contract
0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9
on Arbitrum Nitro. The query is filtered by the origin
address
0x06fa8562b9a149cf02427aeed8d0d26bb70244fb
and the LOG3
opcode.
import * as Parsiq from '@parsiq/parsiq.js';
import {OpCode} from '@parsiq/parsiq.js';
const client = Parsiq.createClient(process.env.API_KEY, Parsiq.ChainId.ARBITRUM_NITRO_MAINNET);
const stream = await client.logs.csvExport.getByBlockRange(
1, 'latest',
{
contract: ['0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9'],
topic_0: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'],
topic_1: ['0x00000000000000000000000006fa8562b9a149cf02427aeed8d0d26bb70244fb'],
topic_2: ['0x000000000000000000000000ce7ec11a5f306c6b896526149db1a86c7d1531e2'],
origin: '0x06fa8562b9a149cf02427aeed8d0d26bb70244fb',
op_code: OpCode.LOG3
},
{
cu_limit: 1000
}
);
let buffer = '';
stream.on('data', (chunk) => {
buffer += chunk.toString();
let newlineIndex;
while ((newlineIndex = buffer.indexOf('\n')) >= 0) {
const line = buffer.slice(0, newlineIndex);
console.log(line);
buffer = buffer.slice(newlineIndex + 1)
}
}).on('end', () => {
if (buffer.length > 0) {
console.log(buffer);
}
console.log('CSV stream processing completed.');
});
Output:
id,block_number,op_code,contract,topic_0,topic_1,topic_2,topic_3,log_data,timestamp,block_hash,tx_hash,origin
000000000a7ec0ba-0001-00000001,176079034,LOG3,0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x00000000000000000000000006fa8562b9a149cf02427aeed8d0d26bb70244fb,0x000000000000000000000000ce7ec11a5f306c6b896526149db1a86c7d1531e2,,0x000000000000000000000000000000000000000000000000000000000a5004ec,1706710925,0x9ea11aa291d2d10ab854e99ab7ca53c66eb5cd340142278568336ad89fc5358e,0x6614315d14505803db7ede4aefb664dca4bd65ce70231122ac37f4eb10a2202a,0x06fa8562b9a149cf02427aeed8d0d26bb70244fb
000000000a8b3a84-0001-00000001,176896644,LOG3,0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9,0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0
0000000000000000000000006fa8562b9a149cf02427aeed8d0d26bb70244fb,0x000000000000000000000000ce7ec11a5f306c6b896526149db1a86c7d1531e2,,0x0000000000000000000000000
000000000000000000000000000000007af1da4,1706927644,0x2a339b435dd325532e5597ebc8fa52313a0563f2890965054512c55f085dc7b8,0xe148c5481104559e8d21bd5fd007c01fdf20ec9a6143086572adf0a8eb622629,0x06fa8562b9a149cf02427aeed8d0d26bb70244fb
CSV stream processing completed.
Parameters
chainId
version
block_number_start
block_number_end
origin
contract
topic_0
topic_1
topic_2
topic_3
op_code
cu_limit
offset