@abstract-foundation/agw-client
Version:
Abstract Global Wallet Client SDK
28 lines • 1.46 kB
JavaScript
import { BaseError, } from "viem";
import { sendRawTransactionSync, } from "viem/actions";
import { getAction } from "viem/utils";
import { SESSION_KEY_VALIDATOR_ADDRESS } from "../constants.js";
import { encodeSessionWithPeriodIds, getPeriodIdsForTransaction, } from "../sessions.js";
import { sendTransactionInternal } from "./sendTransactionInternal.js";
export async function sendTransactionForSessionSync(client, signerClient, publicClient, parameters, session, customPaymasterHandler = undefined) {
const { throwOnReceiptRevert, timeout, ...txParameters } = parameters;
const selector = txParameters.data
? `0x${txParameters.data.slice(2, 10)}`
: undefined;
if (!txParameters.to) {
throw new BaseError("Transaction to field is not specified");
}
return sendTransactionInternal(client, signerClient, publicClient, txParameters, SESSION_KEY_VALIDATOR_ADDRESS, {
[SESSION_KEY_VALIDATOR_ADDRESS]: encodeSessionWithPeriodIds(session, getPeriodIdsForTransaction({
sessionConfig: session,
target: txParameters.to,
selector,
timestamp: BigInt(Math.floor(Date.now() / 1000)),
})),
}, customPaymasterHandler, (serializedTransaction) => getAction(client, sendRawTransactionSync, "sendRawTransactionSync")({
serializedTransaction,
throwOnReceiptRevert,
timeout,
}));
}
//# sourceMappingURL=sendTransactionForSessionSync.js.map