transaction-retry-tool
Version:
Tool to retry transactions on a blockchain
26 lines • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
const retryTransaction = async (env, txHash, signerKey, gasPrice) => {
try {
const signer = await (0, utils_1.getSigner)(env, signerKey);
const tx = await (0, utils_1.getTransaction)(signer, txHash);
if (tx === null)
return null;
// Check if transaction is mined
if (tx.blockNumber)
console.log('\x1b[32m%s\x1b[0m', `Transaction ${txHash} was mined, in block ${tx.blockNumber}`);
else if (tx.from === signer.address && tx.gasPrice !== undefined && tx.gasLimit !== undefined) {
return (0, utils_1.replaceTransactionIfNecessary)(env, signer, tx, txHash, gasPrice);
}
else
console.log('\x1b[33m%s\x1b[0m', `${tx.from === signer.address
? `Error: tx.gasPrice or tx.gasLimit is undefined`
: `Transaction ${txHash} is not from the same sender, original sender: ${tx.from}, current sender: ${signer.address}`}`);
}
catch (err) {
console.log('\x1b[33m%s\x1b[0m', `Error: ${err}`);
}
};
exports.default = retryTransaction;
//# sourceMappingURL=retryTransaction.js.map