web3.eth.getPastLogs(options, [, callback]);
Description
Gets past logs, matching the given options.
Parameters
Object
— The filter options as follows:
fromBlock
— Number|String
: The number of the earliest block ("latest"
may be given to mean the most recent and "pending"
currently mining). By default "latest"
.toBlock
— Number|String
: The number of the latest block ("latest"
may be given to mean the most recent and "pending"
currently mining). By default "latest"
.address
— String|Array
: An address or a list of addresses to only get logs from particular account(s).topics
— Array
: An array of values which must each appear in the log entries. The order is important, if you want to leave topics out use null
, e.g. [null, '0x12...']
. You can also pass an array for each topic with options for that topic e.g. [null, ['option1', 'option2']]
.Returns
Promise
returns Array
— Array of log objects.
The structure of the returned event Object
in the Array
looks as follows:
address
— String
: From which this event originated from.data
— String
: The data containing non-indexed log parameter.topics
— Array
: An array with max 4 (32 Byte) topics, topic 1-3 contains indexed parameters of the log. The first topic usually consists of the signature (a keccak256 hash) of the name of the event that occurred, including the types (uint256, string, etc.) of its parameters.logIndex
— Number
: Integer of the event index position in the block.transactionIndex
— Number
: Integer of the transaction's index position, the event was created in.transactionHash
32 Bytes — String
: Hash of the transaction this event was created in.blockHash
32 Bytes — String
: Hash of the block where this event was created in. null
if still pending.blockNumber
— Number
: The block number where this log was created in. null
if still pending.Example
web3.eth.getPastLogs({
address: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe",
topics: ["0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234"]
})
.then(console.log);
> [{
data: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385',
topics: ['0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7', '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385']
logIndex: 0,
transactionIndex: 0,
transactionHash: '0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385',
blockHash: '0xfd43ade1c09fade1c0d57a7af66ab4ead7c2c2eb7b11a91ffdd57a7af66ab4ead7',
blockNumber: 1234,
address: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe'
},{...}]