Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/server/routes/transaction/blockchain/send-signed-tx.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Type, type Static } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { eth_sendRawTransaction, getRpcClient, isHex } from "thirdweb";
import { eth_sendRawTransaction, getRpcClient, type Hex, isHex } from "thirdweb";
import { getChain } from "../../../../shared/utils/chain";
import { thirdwebClient } from "../../../../shared/utils/sdk";
import { createCustomError } from "../../../middleware/error";
import { TransactionHashSchema } from "../../../schemas/address";
import { standardResponseSchema } from "../../../schemas/shared-api-schemas";
import { walletChainParamSchema } from "../../../schemas/wallet";
import { getChainIdFromChain } from "../../../utils/chain";
import { isInsufficientFundsError, prettifyError } from "../../../../shared/utils/error";

const requestBodySchema = Type.Object({
signedTransaction: Type.String(),
Expand Down Expand Up @@ -57,10 +58,25 @@ export async function sendSignedTransaction(fastify: FastifyInstance) {
client: thirdwebClient,
chain: await getChain(chainId),
});
const transactionHash = await eth_sendRawTransaction(
rpcRequest,
signedTransaction,
);

let transactionHash: Hex;
try {
transactionHash = await eth_sendRawTransaction(
rpcRequest,
signedTransaction,
);
} catch (error) {
// Return 400 for client errors.
const isClientError = isInsufficientFundsError(error);
if (isClientError) {
throw createCustomError(
prettifyError(error),
StatusCodes.BAD_REQUEST,
"CLIENT_RPC_ERROR",
);
}
throw error;
}

res.status(StatusCodes.OK).send({
result: {
Expand Down
Loading