Closed passionofvc closed 4 years ago
const account = /* ... */
api.connect().then( () => {
api.connection.on('transaction', (ev) => {
console.log(JSON.stringify(ev, null, 2))
})
return api.connection.request({
command: 'subscribe',
accounts: [ account ]
})
})
This code allows you to listen for transactions on a given account. You can read more about the fields here
You guys survived ? :)
@sharafian thanks, if I have 1 million account, whether I can subscribe account by 1 million or should I call api.connection.request 1 million time for one account? I am sorry to be late.
const account = /* ... */
api.connect().then( () => {
api.connection.on('transaction', (ev) => {
console.log(JSON.stringify(ev, null, 2))
})
return api.connection.request({
command: 'subscribe',
accounts: [ 1 million account ]
})
})
Yep, the accounts
field can contain many accounts if you want to subscribe to more than one
@sharafian very thanks, I am newbie to javascript, also learn many this time.
This thing was not on their official documentation at all. Thanks for saving
I figured it out as per the latest build :
client.connect().then((ok) => {
client.connection._onMessage(JSON.stringify({
type: 'transaction'
}));
client.connection.on('transaction', (EventBody) => {
console.info(This is where you get your event body');
});
return client.connection.request({
command: 'subscribe',
accounts: []
})
})
Hope should work for you.
In 1.0.0-beta.0 and later, use the request() method directly (docs).
Hi @intelliot, do we have any way to listen new ledger or new transaction?
@tangnv Yes, use api.request()
to subscribe to ledger
for new ledgers, and transactions
for new transactions. For transactions affecting a specific account, subscribe to accounts
and use an array to specify the account(s) you're interested in. See Listening to streams.
@tangnv Hi, what if I need to listen for new transactions for 1000000 accounts? If I will use subscribe
with array of billion accounts than how it may affect performance or something else? Maybe it can break something at all? Are there any restrictions with it? Thanks you!
@tangnv Hi, what if I need to listen for new transactions for 1000000 accounts? If I will use
subscribe
with array of billion accounts than how it may affect performance or something else? Maybe it can break something at all? Are there any restrictions with it? Thanks you!
In that case it's better to just listen to all transactions.
This is complete. Docs: https://xrpl.org/rippleapi-reference.html#listening-to-streams
@tangnv Hi, what if I need to listen for new transactions for 1000000 accounts? If I will use
subscribe
with array of billion accounts than how it may affect performance or something else? Maybe it can break something at all? Are there any restrictions with it? Thanks you!
I think it's really not good cuz ripple may save list subscription of address on memory and will be dropped if ws connection is broken by undefined reason. Example on Bitcoin, we have importaddress
for watching address option and the physical node will storage those addresses in disk, so we can access them anytime, no need to worry about connection reset. Just imagine that we have 1 milliion ripple addresses and the connection is broken, we must re-subscribe those 1 milliion addresses or following traditional way is reading all transactions from every block, the hardest thing is speed of creating Ripple block too fast, so can be missed a lot of transactions or delay reading block. Please give me some advice, thanks so much.
I know subscribe ledger event with below code, but how to listen to events on the XRP Ledger (transaction, ledger, account) by a special account?