Powered By GitBook
eth_subscribe
If successful this returns the subscription id. Subscriptions are creates with a regular RPC call with eth_subscribe as method and the subscription name as first parameter.

Parameters

    1.
    subscription name
    2.
    optional arguments (see below)

Returns

If successful this returns the subscription id.

Example

NOTE: eth_subscribe requests cannot be replicated in the composer tool
Request
Curl
Postman
1
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","id": 1, "method": "eth_subscribe", "params": ["newHeads", {"includeTransactions": true}]}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"eth_subscribe",
7
"params":["newHeads", {"includeTransactions": true}],
8
"id":1
9
}
Copied!
Result
1
{
2
"id": 1,
3
"jsonrpc": "2.0",
4
"result": "0x9cef478923ff08bf67fde6c64013158d"
5
}
Copied!

Optional Arguments:

1. newHeads

Fires a notification each time a new header is appended to the chain, including chain reorganizations.
In case of a chain reorganization the subscription will emit all new headers for the new chain. Therefore the subscription can emit multiple headers on the same height.
Paramaters
none
Example
Request
Curl
Postman
1
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","id": 1, "method": "eth_subscribe", "params": ["newHeads"]}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"eth_subscribe",
7
"params":["newHeads"]
8
"id":1
9
}
Copied!
Result
1
{
2
"jsonrpc":"2.0",
3
"id":1,
4
"result":"0x9ce59a13059e417087c02d3236a0b1cc"
5
}
6
{
7
"jsonrpc": "2.0",
8
"method": "eth_subscription",
9
"params": {
10
"result": {
11
"difficulty": "0x15d9223a23aa",
12
"extraData": "0xd983010305844765746887676f312e342e328777696e646f7773",
13
"gasLimit": "0x47e7c4",
14
"gasUsed": "0x38658",
15
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
16
"miner": "0xf8b483dba2c3b7176a3da549ad41a48bb3121069",
17
"nonce": "0x084149998194cc5f",
18
"number": "0x1348c9",
19
"parentHash": "0x7736fab79e05dc611604d22470dadad26f56fe494421b5b333de816ce1f25701",
20
"receiptRoot": "0x2fab35823ad00c7bb388595cb46652fe7886e00660a01e867824d3dceb1c8d36",
21
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
22
"stateRoot": "0xb3346685172db67de536d8765c43c31009d0eb3bd9c501c9be3229203f15f378",
23
"timestamp": "0x56ffeff8",
24
"transactionsRoot": "0x0167ffa60e3ebc0b080cdb95f7c0087dd6c0e61413140e39d94d3468d7c9689f"
25
},
26
"subscription": "0x9ce59a13059e417087c02d3236a0b1cc"
27
}
28
}
Copied!

2. logs

Returns logs that are included in new imported blocks and match the given filter criteria.
In case of a chain reorganization previous sent logs that are on the old chain will be resend with the removed property set to true. Logs from transactions that ended up in the new chain are emitted. Therefore a subscription can emit logs for the same transaction multiple times.
Parameters
    1.
    object with the following (optional) fields
      address, either an address or an array of addresses. Only logs that are created from these addresses are returned (optional)
      topics, only logs which match the specified topics (optional)
Example
Request
Curl
Postman
1
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","id": 1, "method": "eth_subscribe", "params": ["logs", {"address": "0x8320fe7702b96808f7bbc0d4a888ed1468216cfd", "topics": ["0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902"]}]}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"eth_subscribe",
7
"params":["logs", {"address": "0x8320fe7702b96808f7bbc0d4a888ed1468216cfd", "topics": ["0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902"]}]
8
"id":1
9
}
Copied!
Result
1
{
2
"jsonrpc":"2.0",
3
"id":1,
4
"result":"0x4a8a4c0517381924f9838102c5a4dcb7"
5
}
6
​
7
{
8
"jsonrpc":"2.0",
9
"method":"eth_subscription",
10
"params": {
11
"subscription":"0x4a8a4c0517381924f9838102c5a4dcb7",
12
"result":{
13
"address":"0x8320fe7702b96808f7bbc0d4a888ed1468216cfd",
14
"blockHash":"0x61cdb2a09ab99abf791d474f20c2ea89bf8de2923a2d42bb49944c8c993cbf04",
15
"blockNumber":"0x29e87",
16
"data":"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003",
17
"logIndex":"0x0",
18
"topics":["0xd78a0cb8bb633d06981248b816e7bd33c2a35a6089241d099fa519e361cab902"],
19
"transactionHash":"0xe044554a0a55067caafd07f8020ab9f2af60bdfe337e395ecd84b4877a3d1ab4",
20
"transactionIndex":"0x0"
21
}
22
}
23
}
Copied!

3. newPendingTransactions

Returns the hash for all transactions that are added to the pending state.
When a transaction that was previously part of the canonical chain isn’t part of the new canonical chain after a reorganization its again emitted.
NOTE:
Parameters
none
Example
Request
Curl
Postman
1
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","id": 2, "method": "eth_subscribe", "params": ["newPendingTransactions"]}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"eth_subscribe",
7
"params":["newPendingTransactions"]
8
"id":2
9
}
Copied!
Result
1
{
2
"jsonrpc":"2.0",
3
"id":2,
4
"result":"0xc3b33aa549fb9a60e95d21862596617c"
5
}
6
{
7
"jsonrpc":"2.0",
8
"method":"eth_subscription",
9
"params":{
10
"subscription":"0xc3b33aa549fb9a60e95d21862596617c",
11
"result":"0xd6fdc5cc41a9959e922f30cb772a9aef46f4daea279307bc5f7024edc4ccd7fa"
12
}
13
}
Copied!

4. syncing

Indicates when the node starts or stops synchronizing. The result can either be a boolean indicating that the synchronization has started (true), finished (false) or an object with various progress indicators.
Parameters
none
Example
Request
Curl
Postman
1
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","id": 1, "method": "eth_subscribe", "params": ["syncing"]}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"eth_subscribe",
7
"params":["syncing"]
8
"id":1
9
}
Copied!
Result
1
{
2
"jsonrpc":"2.0",
3
"id":1,
4
"result":"0xe2ffeb2703bcf602d42922385829ce96"
5
}
6
​
7
{
8
"subscription":"0xe2ffeb2703bcf602d42922385829ce96",
9
"result":{
10
"syncing":true,
11
"status":{
12
"startingBlock":674427,
13
"currentBlock":67400,
14
"highestBlock":674432,
15
"pulledStates":0,
16
"knownStates":0}
17
}
18
}
19
}
Copied!

​

Last modified 1mo ago