@abstract-foundation/agw-client
Version:
Abstract Global Wallet Client SDK
56 lines • 2.51 kB
JavaScript
import { getChainId, sendRawTransaction } from "viem/actions";
import { assertCurrentChain, getAction, getTransactionError, parseAccount, } from "viem/utils";
import { INSUFFICIENT_BALANCE_SELECTOR } from "../constants.js";
import { AccountNotFoundError } from "../errors/account.js";
import { InsufficientBalanceError } from "../errors/insufficientBalance.js";
import { prepareTransactionRequest } from "./prepareTransaction.js";
import { signTransaction } from "./signTransaction.js";
export async function sendTransactionInternal(client, signerClient, publicClient, parameters, validator, validationHookData = {}, customPaymasterHandler = undefined, sendSerializedTransaction) {
const { chain = client.chain } = parameters;
if (!signerClient.account)
throw new AccountNotFoundError({
docsPath: "/docs/actions/wallet/sendTransaction",
});
const account = parseAccount(signerClient.account);
try {
// assertEip712Request(parameters)
// Prepare the request for signing (assign appropriate fees, etc.)
const request = await prepareTransactionRequest(client, signerClient, publicClient, {
...parameters,
parameters: ["gas", "nonce", "fees"],
isSponsored: customPaymasterHandler !== undefined ||
parameters.paymaster !== undefined,
nonceManager: account.nonceManager,
});
let chainId;
if (chain !== null) {
chainId = await getAction(signerClient, getChainId, "getChainId")({});
assertCurrentChain({
currentChainId: chainId,
chain,
});
}
const serializedTransaction = await signTransaction(client, signerClient, publicClient, {
...request,
chainId,
}, validator, validationHookData, customPaymasterHandler);
if (sendSerializedTransaction) {
return await sendSerializedTransaction(serializedTransaction);
}
return (await getAction(client, sendRawTransaction, "sendRawTransaction")({
serializedTransaction,
}));
}
catch (err) {
if (err instanceof Error &&
err.message.includes(INSUFFICIENT_BALANCE_SELECTOR)) {
throw new InsufficientBalanceError();
}
throw getTransactionError(err, {
...parameters,
account,
chain: chain,
});
}
}
//# sourceMappingURL=sendTransactionInternal.js.map