Skip to content

Biconomy SDK Release 7

Compare
Choose a tag to compare
@livingrockrises livingrockrises released this 10 Jan 07:24
· 328 commits to main since this release
7a165b0

What's Changed

Smart Account Abstraction

Abstracted the smart account creation process to improve UX and reduce boilerplate code.

Example of creating a smart a smart account and sending user gasless user op.

Before

  import { ethers } from "ethers";	
  import { BiconomySmartAccountV2, DEFAULT_ENTRYPOINT_ADDRESS} from "@biconomy/account";
	import { Bundler } from "@biconomy/bundler";
	import { BiconomyPaymaster } from "@biconomy/paymaster";
	import { PaymasterMode } from "@biconomy/paymaster";
	import {
	  DEFAULT_ECDSA_OWNERSHIP_MODULE,
	  ECDSAOwnershipValidationModule,
	} from "@biconomy/modules";

  let provider = new ethers.providers.JsonRpcProvider("rpcUrl");
  let signer = new ethers.Wallet("private key", provider);

  const bundler = new Bundler({
    bundlerUrl: "bundler url",
    chainId: 80001,
    entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
  });

  const paymaster = new BiconomyPaymaster({
    paymasterUrl: "paymaster url",
    strictMode: false,
  });

  const ecdsaModule = await ECDSAOwnershipValidationModule.create({
    signer: signer,
    moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE,
  });

  const biconomySmartAccountConfig = {
    signer: signer,
    chainId: 80001,
    paymaster: paymaster,
    bundler: bundler,
    entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
    defaultValidationModule: ecdsaModule,
    activeValidationModule: ecdsaModule,
  };

  const biconomySmartAccount = await BiconomySmartAccountV2.create(
    biconomySmartAccountConfig
  );

	const transaction = {
      to: "0xd3C85Fdd3695Aee3f0A12B3376aCD8DC54020221",
      data: "0x"
  }

  let partialUserOp = await biconomySmartAccount.buildUserOp([transaction], 
    paymasterServiceData: {
      mode: PaymasterMode.SPONSORED,
    },
  });

  const userOpResponse = await biconomySmartAccount.sendUserOp(partialUserOp);
  await userOpResponse.wait();

After

  import { ethers } from "ethers";	
  import { BiconomySmartAccountV2} from "@biconomy/account";
	import { PaymasterMode } from "@biconomy/paymaster";

  let provider = new ethers.providers.JsonRpcProvider("rpcUrl");
  let signer = new ethers.Wallet("private key", provider);

  const biconomySmartAccountConfig = {
    signer: signer,
    chainId: 80001
    biconomyPaymasterApiKey: "paymaster api key",
    bundlerUrl: "bundler url"
  };

  const biconomySmartAccount = await BiconomySmartAccountV2.create(
    biconomySmartAccountConfig
  );

	const transaction = {
      to: "0xd3C85Fdd3695Aee3f0A12B3376aCD8DC54020221",
      data: "0x"
  }

  let partialUserOp = await biconomySmartAccount.buildUserOp([transaction], 
    paymasterServiceData: {
      mode: PaymasterMode.SPONSORED,
    },
  );

  const userOpResponse = await biconomySmartAccount.sendUserOp(partialUserOp);
  await userOpResponse.wait();

The smart account uses ECDSA by default, entry point address is also set by default by the SDK.

  1. Abstracted Bundler

    Bundler is now required, this will help us remove the need of providing a chainId as a param in the create method in the future because we can get it from bundler instance or bundler url. Making sure a smart account has a bundler is essential as the smart account is not functional without the bundler.

    The user can now skip creating the instance of the bundler and provide just the bundler url instead to the “create” method of BiconomySmartAccountV2.

    Example of creating a smart account and sending a user op.

     	const provider = new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/polygon_mumbai");
      const signer = new ethers.Wallet("private key", provider);
    
      const bundlerUrl = "bundler url";
      const biconomyPaymasterApiKey = "paymaster api key";
      const chainId = 80001;
    
      let smartAccount = await BiconomySmartAccountV2.create({
          signer,
          chainId,
          bundlerUrl
      })
  2. Abstracted Paymaster

    Paymaster is now abstracted, added a new optional param, “biconomyPaymasterApiKey” which can be provided instead of having to manually create the instance of paymaster by the user.

      const provider = new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/polygon_mumbai");
      const signer = new ethers.Wallet("private key", provider);
    
      const bundlerUrl = "bundler url";
      const biconomyPaymasterApiKey = "paymaster api key";
      const chainId = 80001;
    
      let smartAccount = await BiconomySmartAccountV2.create({
          signer,
          chainId,
          biconomyPaymasterApiKey
      })
  3. Default validation module to ECDSA

    User does not need to provide a “defaultValidationModule” and “activeValidationModule” if the module that he wants to use is ECDSA, this will be set by default on the smart accounts.

      const provider = new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/polygon_mumbai");
      const signer = new ethers.Wallet("private key", provider);
    
      const bundlerUrl = "bundler url";
      const chainId = 80001;
    
    	// ECDSA validation module is assigned by the SDK by default
      let smartAccount = await BiconomySmartAccountV2.create({
          signer,
          chainId,
          bundlerUrl
      })
  4. Abstracted entry point address

    The “entryPointAddress” is now optional. User can skip providing an entry point address and the SDK will set it to “DEFAULT_ENTRYPOINT_ADDRESS” by default.

      const provider = new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/polygon_mumbai");
      const signer = new ethers.Wallet("private key", provider);
    
      const bundlerUrl = "bundler url";
      const chainId = 80001;
    
    	// Entry point address is automatically set to **DEFAULT_ENTRYPOINT_ADDRESS**
      let smartAccount = await BiconomySmartAccountV2.create({
          signer,
          chainId,
          bundlerUrl
      })

    Support for WalletClientSigner

    Our smart accounts now supports WalletClientSigner from “@alchemy/aa-core”.

    User can now pass WalletClientSigner instead of ethers.Signer or keep using ethers.Signer if preferred.

    	 import { WalletClientSigner } from "@alchemy/aa-core";
    	 import { privateKeyToAccount } from "viem/accounts";  	
       import { createWalletClient, http } from "viem";
       import { polygonMumbai } from "viem/chains";
       import { BiconomySmartAccountV2 } from "../src/BiconomySmartAccountV2";
       import { ChainId } from "@biconomy/core-types";
    
        const wallet = privateKeyToAccount(`0x${privKey}`);
    
        const walletClient = createWalletClient({
          account: wallet,
          chain: polygonMumbai,
          transport: http("https://rpc-mumbai.maticvigil.com"),
        });
    
        const ecdsaSigner: WalletClientSigner = new WalletClientSigner(walletClient, "json-rpc");
    
        const account = await BiconomySmartAccountV2.create({
          chainId: ChainId.POLYGON_MUMBAI,
          signer: ecdsaSigner,
          bundlerUrl: "https://bundler.biconomy.io/api/v2/80001/..."
        });

What's Changed

New Contributors

Full Changelog: r6...r7