Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.

Commit 46e365b

Browse files
authored
Add a 10s timeout when fetching transaction receipts (#380)
1 parent 81cddec commit 46e365b

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/util/ethereum/get-transaction-receipt.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@ const web3 = require('./web3');
22

33
const getTransactionReceipt = async transactionHash => {
44
const web3Wrapper = web3.getWrapper();
5-
const receipt = await web3Wrapper.getTransactionReceiptIfExistsAsync(
6-
transactionHash,
7-
);
5+
6+
const timeout = new Promise((resolve, reject) => {
7+
const id = setTimeout(() => {
8+
clearTimeout(id);
9+
reject(
10+
new Error(
11+
`Fetching transaction receipt ${transactionHash} timed out after 10s`,
12+
),
13+
);
14+
}, 10000);
15+
});
16+
17+
const receipt = await Promise.race([
18+
web3Wrapper.getTransactionReceiptIfExistsAsync(transactionHash),
19+
timeout,
20+
]);
821

922
return receipt;
1023
};

0 commit comments

Comments
 (0)