Filter
getFilterChanges
Polling method for a filter, which returns an array of logs since the last poll.
Parameters
Name | Type | Description |
---|---|---|
filterId | String | The filter id. |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns Array
- Array of log objects, or an empty array if nothing has changed since last poll.
The structure of the returned log Object
in the Array
looks as follows:
Name | Type | Description |
---|---|---|
address | 20-byte DATA | Address from which this log originated. |
topics | Array of DATA | Array of 0 to 4 32-byte DATA of indexed log arguments. (In Solidity: The first topic is the hash of the signature of the event (e.g., |
data | DATA | Contains the non-indexed arguments of the log. |
blockNumber | QUANTITY | The block number where this log was in. |
transactionHash | 32-byte DATA | Hash of the transaction that this log was created from. |
transactionIndex | QUANTITY | Integer. The index of the transaction that this log was created from. |
blockHash | 32-byte DATA | Hash of the block where this log was in. |
logIndex | QUANTITY | Integer of the log index position in the block. |
id | String | A log identifier. It is made by concatenating "log_" string with |
Example
getFilterLogs
Returns an array of all logs matching the filter with the given id. The filter object should be obtained using newFilter. Note that filter ids returned by other filter creation functions, such as newBlockFilter or newPendingTransactionFilter, cannot be used with this function.
Parameters
Name | Type | Description |
---|---|---|
filterId | String | The filter id. |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
See getFilterChanges
Example
getPastLogs
Gets past logs, matching the given options.
Parameters
Name | Type | Description |
---|---|---|
options | Object | The filter options. |
options.fromBlock | Number | String | (optional) The number of the earliest block to get the logs. ( |
options.toBlock | Number | String | (optional) The number of the last block to get the logs. ( |
options.address | String | Array | (optional) An address or a list of addresses. Only the logs related to the particular account(s) will be returned. |
options.topics | Array | (optional) An array of values that must appear in the log entries. The order is important. If you want to leave topics out, use |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns Array
- Array of log objects.
The structure of the returned event Object
in the Array
looks as follows:
Name | Type | Description |
---|---|---|
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. |
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-byte String | Hash of the transaction this event was created in. |
blockHash | 32-byte String | Hash of the block where this event was created in. |
blockNumber | Number | The block number where this log was created in. |
id | String | A log identifier. It is made through concatenating "log_" string with |
Example
newBlockFilter
Creates a filter in the node to receive the information about new block arrival. To check if the state has changed, call getFilterChanges.
Parameters
Name | Type | Description |
---|---|---|
callback | Function | (optional) Optional callback. The callback is fired with an error object as its first parameter and the result as the second. |
Return Value
Promise
returns String
- A filter id.
Example
newFilter
Creates a filter object using the given filter options, to receive the specific state changes (logs).
To check if the state has changed, call getFilterChanges.
To obtain all logs matching the filter created by
newFilter
, call getFilterLogs.
For detailed information about topic filters, please see Klaytn Platform API - klay_newFilter.
Parameters
Name | Type | Description |
---|---|---|
options | Object | The filter options. |
options.fromBlock | Number | String | (optional) The number of the earliest block height to query the events. (There are special tags, |
options.toBlock | Number | String | (optional) The number of the last block height to query the events (There are special tags, |
options.address | String | Array | (optional) An address or a list of addresses to get logs generated inside the given contract(s). |
options.topics | Array | (optional) An array of values to search for in the log entries. The order is important. If you want to match everything in the given position, use |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns String
- A filter id.
Example
newPendingTransactionFilter
Creates a filter in the node, to receive the information about new pending transactions arrival. To check if the state has changed, call getFilterChanges.
Parameters
Name | Type | Description |
---|---|---|
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns String
- A filter id.
Example
uninstallFilter
Removes the filter with the given id. It is strongly recommended to immediately remove the filter if monitoring is no longer needed. A filter will be removed if the filter has not been invoked through getFilterChanges for more than the timeout value set in the node. The default configuration is 5 minutes.
Parameters
Name | Type | Description |
---|---|---|
filterId | String | The filter id. |
callback | Function | (optional) Optional callback, returns an error object as the first parameter and the result as the second. |
Return Value
Promise
returns Boolean
- true
if the filter was successfully uninstalled, otherwise false
.
Example
Last updated