UNPKG

@abstract-foundation/agw-client

Version:
55 lines 2.42 kB
import { BaseError, } from 'viem'; import { getChainId, sendRawTransaction } from 'viem/actions'; import { assertCurrentChain, getAction, getTransactionError, parseAccount, } from 'viem/utils'; import {} from 'viem/zksync'; 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) { 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); 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