eth_getFilterChanges
Polling method for a filter, which returns an array of events that have occurred since the last poll on the Centrifuge network.
Parameters#
id(string, required): The filter ID returned from eth_newFilter, eth_newBlockFilter, or eth_newPendingTransactionFilter
Returns#
An array containing different data types depending on the filter type:
For log filters (eth_newFilter):#
Array of log objects with:
address(string): Address from which this log originatedtopics(array of strings): Array of 0 to 4 32-byte DATA topicsdata(string): Contains non-indexed arguments of the logblockNumber(string): Block number where this log was includedblockHash(string): Hash of the block where this log was includedtransactionHash(string): Hash of the transaction that created this logtransactionIndex(string): Transaction index position in the blocklogIndex(string): Integer of the log index position in the blockremoved(boolean): true when the log was removed due to a chain reorganization
For block filters (eth_newBlockFilter):#
Array of 32-byte block hashes for blocks that were newly created
For pending transaction filters (eth_newPendingTransactionFilter):#
Array of 32-byte transaction hashes for transactions that entered the pending state
Implementation Example#
- cURL
- JavaScript
- Python
# Create a log filter scoped to the latest block (requires jq)
FILTER_ID=$(curl -s -X POST https://api-centrifuge.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_newFilter",
"params": [{
"fromBlock": "latest",
"toBlock": "latest",
"address": null,
"topics": []
}],
"id": 1
}' | jq -r '.result')
# Poll for changes on that filter
curl -s -X POST https://api-centrifuge.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d "$(jq -n --arg id \"$FILTER_ID\" '{jsonrpc:\"2.0\", method:\"eth_getFilterChanges\", params:[$id], id:1}')"
const endpoint = 'https://api-centrifuge.n.dwellir.com/YOUR_API_KEY';
const createFilter = async () => {
const filterResponse = await fetch(endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_newFilter',
params: [{ fromBlock: 'latest', toBlock: 'latest', address: null, topics: [] }],
id: 1
})
});
const { result } = await filterResponse.json();
return result;
};
const filterId = await createFilter();
const response = await fetch(endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_getFilterChanges',
params: [filterId],
id: 2
})
});
const data = await response.json();
console.log(data.result);
import requests
url = 'https://api-centrifuge.n.dwellir.com/YOUR_API_KEY'
headers = {'Content-Type': 'application/json'}
filter_payload = {
"jsonrpc": "2.0",
"method": "eth_newFilter",
"params": [{
"fromBlock": "latest",
"toBlock": "latest",
"address": None,
"topics": []
}],
"id": 1
}
filter_id = requests.post(url, headers=headers, json=filter_payload, timeout=10).json()['result']
changes_payload = {
"jsonrpc": "2.0",
"method": "eth_getFilterChanges",
"params": [filter_id],
"id": 2
}
response = requests.post(url, headers=headers, json=changes_payload, timeout=10)
print(response.json()['result'])
Response Example#
For log filters:#
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"address": "0x1234567890abcdef1234567890abcdef12345678",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
],
"data": "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000",
"blockNumber": "0x1b4",
"blockHash": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
"transactionHash": "0xfedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321",
"transactionIndex": "0x1",
"logIndex": "0x0",
"removed": false
}
]
}
For block filters:#
{
"jsonrpc": "2.0",
"id": 1,
"result": [
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
"0xfedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321"
]
}
Notes#
- This method only returns changes that occurred since the last poll
- Filters timeout if not accessed within a certain time period (typically 5 minutes)
- The first call to eth_getFilterChanges returns all events since filter creation
- Subsequent calls return only new events since the previous call
- Use eth_getFilterLogs to retrieve all accumulated logs regardless of polling
Need help? Contact our support team or check the Centrifuge documentation.