UNPKG

@alchemy/aa-core

Version:

viem based SDK that enables interactions with ERC-4337 Smart Accounts. ABIs are based off the definitions generated in @account-abstraction/contracts

46 lines 1.66 kB
import { createClient, http, publicActions, } from "viem"; import { ChainNotFoundError } from "../errors/client.js"; import { VERSION } from "../version.js"; import { bundlerActions, } from "./decorators/bundlerClient.js"; export const createBundlerClientFromExisting = (client) => { return client.extend(bundlerActions); }; export function createBundlerClient(args) { if (!args.chain) { throw new ChainNotFoundError(); } const { key = "bundler-public", name = "Public Bundler Client", type = "bundlerClient", } = args; const { transport, ...opts } = args; const resolvedTransport = transport({ chain: args.chain, pollingInterval: opts.pollingInterval, }); const baseParameters = { ...args, key, name, type, }; const client = (() => { if (resolvedTransport.config.type === "http") { const { url, fetchOptions: fetchOptions_ } = resolvedTransport.value; const fetchOptions = fetchOptions_ ?? {}; if (url.toLowerCase().indexOf("alchemy") > -1) { fetchOptions.headers = { ...fetchOptions.headers, "Alchemy-AA-Sdk-Version": VERSION, }; } return createClient({ ...baseParameters, transport: http(url, { ...resolvedTransport.config, fetchOptions, }), }); } return createClient(baseParameters); })(); return client.extend(publicActions).extend(bundlerActions); } //# sourceMappingURL=bundlerClient.js.map