Subscribes/Unsubscribes to all token transfers or token transfers for a specific token.
Make sure you're connected.
Request
All token transfer:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["token_transfer"]}
Specific token transfer:
{"jsonrpc":"2.0","id":1,"method":"subscribe","params":["token_transfer",{"address":"0x06012c8cf97bead5deae237070f9587f8e7a266d"}]}
Field | Type | Description |
---|---|---|
address | string | The address of the token. Specifying tokenAddress means you will only receive events when that token is transferred to or from the specified address . |
Response
"result": {
"blockchainId": "1c9c969065fcd1cf",
"blockNumber": 7808673,
"blockHash": "0x1e6ccac5667d03c843fda3993d5fedaba85e2fd973a63fd8445a60fbb9c12fd3",
"transactionHash": "0x2d505af3f69c4532cf327ecb3a3e6ae9e87538e228c199960c4792d9e16b26d3",
"senderAddress": "0xb1690c08e213a35ed9bab7b318de14420fb57d8c",
"recipientAddress": "0x3fb3f6ecefac4f7781cb65199194b6c6cb7d0967",
"tokenAddress": "0x06012c8cf97bead5deae237070f9587f8e7a266d",
"amount": 1270798,
"type": "EOA_EOA",
"timestamp": 1558515385000,
"timestampNanoseconds": 0,
"logIndex": 102
}
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: ['token_transfer', {address: '0x3f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be'}],
id: 1,
}));
});
ws.on('message', data => {
console.log(JSON.stringify(JSON.parse(data), null, 2));
});
Supported Blockchains
Blockchain | Network | Slug (x-amberdata-blockchain-id) |
---|---|---|
Ethereum | Mainnet | ethereum-mainnet |