@abstract-foundation/agw-client
Version:
Abstract Global Wallet Client SDK
38 lines • 1.45 kB
JavaScript
import { encodeFunctionData, } from "viem";
import { getContractError, parseAccount } from "viem/utils";
import { AccountNotFoundError } from "../errors/account.js";
import { sendTransactionSync } from "./sendTransactionSync.js";
export async function writeContractSync(client, signerClient, publicClient, parameters, isPrivyCrossApp = false, customPaymasterHandler = undefined) {
const { abi, account: account_ = client.account, address, args, dataSuffix, functionName, throwOnReceiptRevert, timeout, ...request } = parameters;
if (!account_)
throw new AccountNotFoundError({
docsPath: "/docs/contract/writeContract",
});
const account = parseAccount(account_);
const data = encodeFunctionData({
abi,
args,
functionName,
});
try {
return await sendTransactionSync(client, signerClient, publicClient, {
data: `${data}${dataSuffix ? dataSuffix.replace("0x", "") : ""}`,
to: address,
account,
throwOnReceiptRevert,
timeout,
...request,
}, isPrivyCrossApp, customPaymasterHandler);
}
catch (error) {
throw getContractError(error, {
abi,
address,
args,
docsPath: "/docs/contract/writeContract",
functionName,
sender: account.address,
});
}
}
//# sourceMappingURL=writeContractSync.js.map