UNPKG

@biconomy/sdk

Version:

SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.

58 lines 2.4 kB
import { toNexusAccount } from "../account/toNexusAccount.js"; import { MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS, MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS } from "../constants/index.js"; import { createBicoBundlerClient } from "./createBicoBundlerClient.js"; import { erc7579Actions } from "./decorators/erc7579/index.js"; import { smartAccountActions } from "./decorators/smartAccount/index.js"; /** * Creates a Nexus Client for interacting with the Nexus smart account system. * * @param parameters - {@link SmartAccountClientConfig} * @returns Nexus Client. {@link NexusClient} * * @example * import { createSmartAccountClient } from '@biconomy/sdk' * import { http } from 'viem' * import { mainnet } from 'viem/chains' * * const nexusClient = await createSmartAccountClient({ * chain: mainnet, * transport: http('https://mainnet.infura.io/v3/YOUR-PROJECT-ID'), * bundlerTransport: http('https://api.biconomy.io'), * signer: '0x...', * }) */ export async function createSmartAccountClient(parameters) { const { account: account_, client: client_, chain = parameters.chain ?? client_?.chain, signer, index = 0n, key = "nexus client", name = "Nexus Client", module, factoryAddress = MAINNET_ADDRESS_K1_VALIDATOR_FACTORY_ADDRESS, validatorAddress = MAINNET_ADDRESS_K1_VALIDATOR_ADDRESS, bundlerTransport, transport, accountAddress, paymasterContext, attesters, attesterThreshold, useTestBundler = false, ...bundlerConfig } = parameters; if (!chain) throw new Error("Missing chain"); const nexusAccount = account_ ?? (await toNexusAccount({ accountAddress, transport, chain, signer, index, module, factoryAddress, validatorAddress, attesters, attesterThreshold, useTestBundler })); const bundler_ = createBicoBundlerClient({ ...bundlerConfig, chain, key, name, paymasterContext, account: nexusAccount, transport: bundlerTransport }) .extend(erc7579Actions()) .extend(smartAccountActions()); return bundler_; } // Aliases for backwards compatibility export const createNexusClient = createSmartAccountClient; export const createNexusSessionClient = createSmartAccountClient; //# sourceMappingURL=createSmartAccountClient.js.map