Function createSessionSmartAccountClient

  • createSessionSmartAccountClient

    Creates a new instance of BiconomySmartAccountV2 class. This is used to impersonate a users smart account by a dapp, for use with a valid session that has previously been granted by the user. A dummy signer is passed into the smart account instance, which cannot be used. The sessionSigner is used instead for signing transactions, which is fetched from the session storage using the sessionID. ISessionStorage

    Parameters

    Returns Promise<BiconomySmartAccountV2>

    A promise that resolves to a new instance of BiconomySmartAccountV2.

    Throws

    An error if something is wrong with the smart account instance creation.

    Example

    import { createClient } from "viem"
    import { createSmartAccountClient, BiconomySmartAccountV2 } from "@biconomy/account"
    import { createWalletClient, http } from "viem";
    import { polygonAmoy } from "viem/chains";
    import { SessionFileStorage } from "@biconomy/session-file-storage";

    const signer = createWalletClient({
    account,
    chain: polygonAmoy,
    transport: http(),
    });


    // The following fields are required to create a session smart account client
    const smartAccountAddress = '0x...';
    const sessionStorage = new SessionFileStorage(smartAccountAddress);
    const sessionKeyAddress = '0x...';
    const sessionID = '0x...';

    const smartAccountWithSession = await createSessionSmartAccountClient(
    {
    accountAddress: smartAccountAddress, // Set the account address on behalf of the user
    bundlerUrl,
    paymasterUrl,
    chainId
    },
    "DEFAULT_STORE" // Can be ommitted if using default session storage (localStorage in browser, fileStorage in node backend)
    )

    // The smartAccountWithSession instance can now be used to interact with the blockchain on behalf of the user in the same manner as a regular smart account instance.
    // smartAccountWithSession.sendTransaction(...) etc.