Subscribes/Unsubscribes to new pending transactions or a specific pending transaction.
Make sure you're connected.
Request
Every new transaction:
{"jsonrpc":"2.0","id":2,"method":"subscribe","params":["pending_transaction"]}
Specific pending transaction:
{"jsonrpc":"2.0","id":2,"method":"subscribe","params":["pending_transaction",{"hash":"0xf16c9f57349e6d094ceba3fadf612da3f68802d8fbf0dd06b52ed7da56b43a81"}]}
Param | Type | Description |
---|---|---|
hash | string | The pending transaction hash. |
Response
"result": {
"blockchainId": "1c9c969065fcd1cf",
"hash": "0x7acf9d893184af7bffd22145a4b7a8ecda4d37bbf5c305175c7ae2fd7cfd8dea",
"nonce": 167253,
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"blockNumber": -1,
"transactionIndex": 0,
"from": "0xc5341278a92e2bd8203ab931c6780c15d367713f",
"to": "0x8e766f57f7d16ca50b4a0b90b88f6468a09b0439",
"value": 0,
"input": "0xa9059cbb000000000000000000000000f8452b266f4a37295a3c067865da4d68f269490c000000000000000000000000000000000000000000000097f3e82b0a7cda4000",
"gasPrice": 13333333333,
"gas": 90000,
"createdAt": 1557876078585,
"createdAtNanoseconds": 0,
"optionalProperties": {
"r": "0x10965cf3120fb98952f9b8a8696f8ebaef142a96a437b22a74589ac324423903",
"s": "0x60a50374670e4f97e2c15f959acd2d0e45cf82d7aad9cf6f8b8903235560dbe3",
"v": 37
}
}
Example
const WebSocket = require('ws');
const ws = new WebSocket('wss://ws.web3api.io', {headers: {x-api-key:'<api_key>'}});
ws.on('open', () => {
ws.send(JSON.stringify({
jsonrpc: '2.0',
method: 'subscribe',
params: ['pending_transaction', {hash: '0x6c80ebbe94deb54d84e7d22b0eac014275d3a2df97e5afa0e7bf408ae9bc8b22'}],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});
Supported Blockchains
Blockchain | Network | Slug (x-amberdata-blockchain-id) |
---|---|---|
Bitcoin | Mainnet | bitcoin-mainnet |
Litecoin | Mainnet | litecoin-mainnet |
Ethereum | Mainnet | ethereum-mainnet |