Search…
cargo.pollTx
After enabling Cargo you can use the PollTx instance on the enabled Cargo instance. You can use the methods of the PollTx class to watch pending transactions and notify you when they are complete. Here is the source on GitHub.

Using PollTx

Here is an example of how you might use PollTx in an application
1
async function purchaseAnItem(resaleItemId, price) {
2
// After making a call that submit a transaction,
3
// PollTx will immediately start watching the transaction
4
// for completion. You can listen for completed transactions
5
// by using the events below.
6
const tx = await cargo.api.purchaseResaleToken(resaleItemId, price);
7
}
8
9
// Somewhere else in your application you can add event listeners
10
// to the PollTx instance that will tell you when the list of pending
11
// transactions has been updated and when a transaction is complete
12
cargo.pollTx.on('pending', (newTx, pendingTxArray) => {
13
// newTx is the new pending transaction
14
// pendingTxArray a list of all transactions that are still pending
15
console.log(pendingTxArray);
16
});
17
18
cargo.pollTx.on('completed', (tx, pendingTxArray) => {
19
// tx is the completed transaction hash
20
console.log(tx);
21
// pendingTxArray is the updated list of pending
22
// transactions.
23
})
24
25
// You can use the .once method to remove the listener after the
26
// first 'completed' event it hears.
27
cargo.pollTx.once('completed', (tx, pendingTxArray) => {})
28
​
29
​
Copied!
Last modified 28d ago
Copy link
Contents
Using PollTx