@solidusnetwork/solidus-polling
v1.0.6
Published
Shim for @solidusnetwork/solidus-js that allows clients to poll for responses
Downloads
249
Maintainers
Readme
Solidus Polling
Solidus Polling is an extension to the Solidus JS library, designed to provide an easy and efficient way to poll for responses on the client side. Built on top of Solidus JS, it maintains the simplicity and reliability you're accustomed to, with added polling capabilities.
Features
- Seamless integration with Solidus JS.
- Poll for transaction receipts, contract method results, or any asynchronous process.
- Configurable polling intervals and timeout settings.
- Efficient error handling during the polling process.
Installation
Before you install Solidus Polling, make sure you have Solidus JS installed in your project.
npm install @solidusnetwork/solidus-jsThen, you can install Solidus Polling using npm:
npm install @solidusnetwork/solidus-pollingOr yarn:
yarn add @solidusnetwork/solidus-pollingUsage
Here's a quick example to get you started:
const { pollFor } = require('@solidusnetwork/solidus-polling');
const solidus = require('@solidusnetwork/solidus-js');
async function main() {
const provider = new solidus.providers.JsonRpcProvider("http://localhost:8610");
const transactionHash = 'your-transaction-hash';
try {
const receipt = await pollFor(provider, 'getTransactionReceipt', [transactionHash], 1000, 30000);
console.log(receipt);
} catch (error) {
console.error('Error polling for transaction receipt:', error);
}
}
main();API Reference
pollFor(provider, methodName, params, initial_polling_interval = 60, request_timeout = 30, max_duration = 180, max_polling_interval = 90)Polls for a method's response.
Parameters
- provider: The Solidus provider instance.
- methodName: Name of the method you're awaiting a response from.
- params: Parameters to be passed to the method being called.
- initial_polling_interval (optional): Time (in seconds) for the initial interval between polls.
- request_timeout (optional): Time (in seconds) before the request times out.
- max_duration (optional): Maximum duration (in seconds) before the entire polling process times out. Defaults to 180 seconds.
- max_polling_interval (optional): Maximum time (in seconds) allowed between polls. Defaults to 10000 milliseconds.
Contributing
We welcome contributions! Please see our contributing guidelines for details.
