Skip to content

Commit 9d21d26

Browse files
authored
fix: set errorMessage on transaction revert (#662)
1 parent 6121e05 commit 9d21d26

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/worker/tasks/mineTransactionWorker.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import assert from "assert";
2-
import { Job, Processor, Worker } from "bullmq";
1+
import { Worker, type Job, type Processor } from "bullmq";
2+
import assert from "node:assert";
33
import superjson from "superjson";
44
import {
5-
Address,
65
eth_getTransactionByHash,
76
eth_getTransactionReceipt,
87
getAddress,
98
getRpcClient,
9+
type Address,
1010
} from "thirdweb";
1111
import { stringify } from "thirdweb/utils";
1212
import { getUserOpReceipt, getUserOpReceiptRaw } from "thirdweb/wallets/smart";
@@ -21,16 +21,16 @@ import { logger } from "../../utils/logger";
2121
import { recordMetrics } from "../../utils/prometheus";
2222
import { redis } from "../../utils/redis/redis";
2323
import { thirdwebClient } from "../../utils/sdk";
24-
import {
24+
import type {
2525
ErroredTransaction,
2626
MinedTransaction,
2727
SentTransaction,
2828
} from "../../utils/transaction/types";
2929
import { enqueueTransactionWebhook } from "../../utils/transaction/webhook";
3030
import { reportUsage } from "../../utils/usage";
3131
import {
32-
MineTransactionData,
3332
MineTransactionQueue,
33+
type MineTransactionData,
3434
} from "../queues/mineTransactionQueue";
3535
import { SendTransactionQueue } from "../queues/sendTransactionQueue";
3636

@@ -59,7 +59,7 @@ const handler: Processor<any, void, string> = async (job: Job<string>) => {
5959
}
6060

6161
if (!resultTransaction) {
62-
job.log(`Transaction is not mined yet. Check again later...`);
62+
job.log("Transaction is not mined yet. Check again later...");
6363
throw new Error("NOT_CONFIRMED_YET");
6464
}
6565

@@ -153,6 +153,11 @@ const _mineTransaction = async (
153153
service: "worker",
154154
});
155155

156+
const errorMessage =
157+
receipt.status === "reverted"
158+
? "The transaction failed onchain. See: https://portal.thirdweb.com/engine/troubleshooting"
159+
: undefined;
160+
156161
return {
157162
...sentTransaction,
158163
status: "mined",
@@ -164,6 +169,7 @@ const _mineTransaction = async (
164169
gasUsed: receipt.gasUsed,
165170
effectiveGasPrice: receipt.effectiveGasPrice,
166171
cumulativeGasUsed: receipt.cumulativeGasUsed,
172+
errorMessage,
167173
};
168174
}
169175
}
@@ -233,7 +239,7 @@ const _mineUserOp = async (
233239
} catch (e) {
234240
if (e instanceof Error) {
235241
errorMessage = e.message;
236-
await job.log("Failed to get userOpReceipt: " + e.message);
242+
await job.log(`Failed to get userOpReceipt: ${e.message}`);
237243
} else {
238244
throw e;
239245
}

0 commit comments

Comments
 (0)