transactionMined.js 959 B

123456789101112131415161718192021222324252627282930313233
  1. // from https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6
  2. module.export = web3.eth.transactionMined = function (txnHash, interval) {
  3. var transactionReceiptAsync;
  4. interval = interval || 500;
  5. transactionReceiptAsync = function (txnHash, resolve, reject) {
  6. try {
  7. var receipt = web3.eth.getTransactionReceipt(txnHash);
  8. if (receipt === null) {
  9. setTimeout(function () {
  10. transactionReceiptAsync(txnHash, resolve, reject);
  11. }, interval);
  12. } else {
  13. resolve(receipt);
  14. }
  15. } catch (e) {
  16. reject(e);
  17. }
  18. };
  19. if (Array.isArray(txnHash)) {
  20. var promises = [];
  21. txnHash.forEach(function (oneTxHash) {
  22. promises.push(
  23. web3.eth.getTransactionReceiptMined(oneTxHash, interval));
  24. });
  25. return Promise.all(promises);
  26. } else {
  27. return new Promise(function (resolve, reject) {
  28. transactionReceiptAsync(txnHash, resolve, reject);
  29. });
  30. }
  31. };