### Full Implementation Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/signOnChainQuote.md A complete workflow showing account setup, quote retrieval, and signing an on-chain quote. ```typescript import { createMeeClient, toMultichainNexusAccount, mcUSDC } from "@biconomy/abstractjs"; import { http } from "viem"; import { mainnet, optimism } from "viem/chains"; // Setup multichain account const mcNexus = await toMultichainNexusAccount({ chains: [mainnet, optimism], signer: eoaAccount, transports: [http(), http()] }); // Create MEE client const meeClient = await createMeeClient({ account: mcNexus }); // Token information on Optimism const tokenAddress = mcUSDC.addressOn(optimism.id); // Create trigger information const trigger = { chainId: optimism.id, tokenAddress: tokenAddress, amount: 1000000n // 1 USDC (6 decimals) }; // Fee token information const feeToken = { address: tokenAddress, chainId: optimism.id }; try { // 1. Get an on-chain quote const onChainQuote = await meeClient.getOnChainQuote({ instructions: [ mcNexus.build({ type: "default", data: { calls: [ { to: "0x0000000000000000000000000000000000000000", gasLimit: 50000n, value: 0n } ], chainId: optimism.id } }) ], feeToken, trigger }); console.log("On-chain quote received:"); console.log(`Quote ID: ${onChainQuote.quote.id}`); // 2. Sign the on-chain quote (this will send an on-chain transaction) const signedQuote = await meeClient.signOnChainQuote({ fusionQuote: onChainQuote, confirmations: 2 }); console.log("Quote signed with signature:", signedQuote.signature); // The signedQuote can now be executed with executeSignedQuote } catch (error) { console.error("Error during on-chain quote signing:", error); } ``` -------------------------------- ### Install Dependencies Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/wallets-and-signers/turnkey.mdx Install the required SDKs for Turnkey, Biconomy, and viem. ```bash npm install @turnkey/sdk-server @turnkey/viem @biconomy/abstractjs viem dotenv ``` -------------------------------- ### Install Dependencies Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/wallets-and-signers/privy.mdx Install the required Privy, Biconomy, and Viem packages. ```bash npm i @privy-io/react-auth @biconomy/abstractjs viem ``` -------------------------------- ### Basic execution flow example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/executeSignedQuote.md A complete example demonstrating the three-step process: getting a quote, signing it, and executing the signed quote. ```typescript import { createMeeClient, toMultichainNexusAccount, mcUSDC } from "@biconomy/abstractjs"; import { http, zeroAddress } from "viem"; import { optimism, base } from "viem/chains"; // Setup multichain account const mcNexus = await toMultichainNexusAccount({ chains: [optimism, base], signer: eoaAccount, transports: [http(), http()] }); // Create MEE client const meeClient = await createMeeClient({ account: mcNexus }); // Define fee token on payment chain const feeToken = { address: mcUSDC.addressOn(optimism.id), chainId: optimism.id }; // Step 1: Get a quote const quote = await meeClient.getQuote({ instructions: [ { calls: [ { to: zeroAddress, value: 0n, gasLimit: 50000n } ], chainId: base.id } ], feeToken }); // Display gas cost to user for confirmation console.log("Gas fee in tokens:", quote.paymentInfo.amount); console.log("Token symbol:", quote.paymentInfo.tokenSymbol); // Step 2: Sign the quote after user confirms const signedQuote = await meeClient.signQuote({ quote }); // Step 3: Execute the signed quote const { hash } = await meeClient.executeSignedQuote({ signedQuote }); // Wait for transaction receipt const receipt = await meeClient.waitForSupertransactionReceipt({ hash }); console.log("Transaction completed:", receipt); ``` -------------------------------- ### Install Dependencies Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/embedded-wallets-quickstart.mdx Install the project dependencies using bun. ```bash bun install ``` -------------------------------- ### Install MEE Client Dependencies Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/index.md Install the required packages using npm or yarn to begin using the MEE Client. ```bash npm install @biconomy/abstractjs viem @rhinestone/module-sdk # or yarn add @biconomy/abstractjs viem @rhinestone/module-sdk ``` -------------------------------- ### Basic signQuote Implementation Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/signQuote.md Full workflow example showing quote retrieval, user confirmation, and signing. ```typescript import { createMeeClient, toMultichainNexusAccount, mcUSDC } from "@biconomy/abstractjs"; import { http, zeroAddress } from "viem"; import { optimism, base } from "viem/chains"; // Setup multichain account const mcNexus = await toMultichainNexusAccount({ chains: [optimism, base], signer: eoaAccount, transports: [http(), http()] }); // Create MEE client const meeClient = await createMeeClient({ account: mcNexus }); // Define fee token on payment chain const feeToken = { address: mcUSDC.addressOn(optimism.id), chainId: optimism.id }; // Step 1: Get a quote const quote = await meeClient.getQuote({ instructions: [ { calls: [ { to: zeroAddress, value: 0n, gasLimit: 50000n } ], chainId: base.id } ], feeToken }); // Display gas cost to user for confirmation console.log("Gas fee in tokens:", quote.paymentInfo.amount); console.log("Token symbol:", quote.paymentInfo.tokenSymbol); // After user confirmation, sign the quote const signedQuote = await meeClient.signQuote({ quote }); // Now the signed quote can be executed const { hash } = await meeClient.executeSignedQuote({ signedQuote }); ``` -------------------------------- ### Setup Imports and Constants Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/wallets-and-signers/privy.mdx Import necessary modules from Viem, AbstractJS, and Privy, and define required constants. ```ts import { createWalletClient, http, custom, erc20Abi, } from "viem"; import { optimism, base } from "viem/chains"; import { createMeeClient, toMultichainNexusAccount, runtimeERC20BalanceOf, greaterThanOrEqualTo, } from "@biconomy/abstractjs"; import { useWallets, useSignAuthorization } from "@privy-io/react-auth"; const NEXUS_IMPLEMENTATION = "0x000000004F43C49e93C970E84001853a70923B03"; const USDC_ADDRESS = "0xUSDC..."; // Replace with actual USDC address ``` -------------------------------- ### Install AbstractJS dependencies Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/set-up-abstractjs.mdx Install the required AbstractJS and Viem packages via npm. ```bash npm install @biconomy/abstractjs viem ``` -------------------------------- ### Prepare Account for Permissions Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/smart-sessions/execute-transactions-on-users-behalf.mdx Deploys the account and installs the Smart Session module, optionally using a funding token. ```ts const payload = await sessionsMeeClient.prepareForPermissions({ smartSessionsValidator: ssValidator, feeToken: { address: usdcAddresses[base.id], chainId: base.id }, trigger: { tokenAddress: usdcAddresses[base.id], chainId: base.id, amount: parseUnits('10', 6) } }) if (payload) { const receipt = await meeClient.waitForSupertransactionReceipt({ hash: payload.hash }) await grantPermissions() } else { await grantPermissions() } ``` ```ts for (const deployment of mcNexus.deployments) { const isDeployed = await deployment.isDeployed() const isSsInstalled = await isModuleInstalled(deployment.client, { account: deployment, module: { address: smartSessionsValidator.address, initData: "0x", type: smartSessionsValidator.type } }) } ``` -------------------------------- ### Supply and Borrow Assets Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/helpers/more/mcAaveV3Pool.md Demonstrates building both supply and borrow instructions for Aave V3 using the mcAaveV3Pool instance. ```typescript import { mcAaveV3Pool } from "@biconomy/abstractjs" import { optimism } from "viem/chains" // Supply USDC to Aave const supplyOp = await mcAaveV3Pool.build({ type: "supply", data: { chainId: optimism.id, args: [ usdcAddress, parseUnits("100", 6), // 100 USDC userAddress, 0 ] } }) // Borrow ETH against the supplied collateral const borrowOp = await mcAaveV3Pool.build({ type: "borrow", data: { chainId: optimism.id, args: [ wethAddress, parseEther("0.1"), // 0.1 ETH 2, // variable rate mode 0, // referral code userAddress ] } }) ``` -------------------------------- ### Setup and Boilerplate for Smart Sessions Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/smart-sessions/execute-transactions-on-users-behalf.mdx Initializes the MEE client, configures the Smart Sessions module, and sets up the multichain Nexus account. ```ts import { createMeeClient, getSudoPolicy, meeSessionActions, toMultichainNexusAccount, toSmartSessionsModule, waitForSupertransactionReceipt, } from "@biconomy/abstractjs"; import { http, parseUnits, type Hex } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { arbitrum, base, optimism, polygon } from "viem/chains"; import { usdcAddresses } from "../utils/addresses/usdc.addresses"; const eoa = privateKeyToAccount(Bun.env.PRIVATE_KEY as Hex) const sessionSigner = privateKeyToAccount(Bun.env.SESSION_SIGNER_PRIVATE_KEY as Hex) // This creates an ERC-7579 module which will be installed on // the users account to enable Smart Sessions capabilities. const ssValidator = toSmartSessionsModule({ signer: sessionSigner }) // This calculates the address for the user owned Smart Account. // In this case - we call this account the `orchestrator` since // it will be used to orchestrate actions on users behalf. const orchestrator = await toMultichainNexusAccount({ chains: [optimism, base, arbitrum, polygon], transports: [http(), http(), http(), http()], signer: eoa }) // The execution is done through the Modular Execution Environment. // This cretes a connection to the Biconomy MEE Relayers. const meeClient = await createMeeClient({ account: orchestrator }) // This extends the `meeClient` object with additional methods which // are used to work with Smart Sessions. const sessionsMeeClient = meeClient.extend(meeSessionActions) ``` -------------------------------- ### Initialize and Execute with MEE Client Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/index.md Setup the multichain smart account and execute a cross-chain transaction using the MEE Client. ```typescript import { privateKeyToAccount } from "viem/accounts"; import { createMeeClient, toMultichainNexusAccount } from "@biconomy/abstractjs"; import { baseSepolia, mainnet } from "viem/chains"; import { http } from "viem"; // 1. Create a signer account (for development) const privateKey = "PRIVATE_KEY"; const account = privateKeyToAccount(`0x${privateKey}`); // 2. Initialize the multichain smart account const mcNexus = await toMultichainNexusAccount({ chains: [baseSepolia, mainnet], transports: [http(), http()], signer: account }); // 3. Create the MEE client const meeClient = await createMeeClient({ account: mcNexus }); // 4. Now you can execute cross-chain operations const quote = await meeClient.getQuote({ instructions: [{ calls: [{ to: "0x123...", value: 0n, data: "0x..." }], chainId: baseSepolia.id }], feeToken: { address: "0x456...", // USDC contract chainId: mainnet.id // Pay with tokens from Ethereum mainnet } }); // 5. Execute the quote const { hash } = await meeClient.executeQuote({ quote }); console.log(`Transaction hash: ${hash}`); ``` -------------------------------- ### Install AbstractJS SDK Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/migrations/v2ToNexus.md Update to the latest version of the AbstractJS SDK to ensure compatibility with Nexus features. ```bash npm install @biconomy/abstractjs ``` -------------------------------- ### Token Approval Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/account/methods/build.md Constructs instructions to approve a spender for a specific token amount. ```typescript const approvalInstructions = await mcAccount.build({ type: "approve", data: { chainId: optimism.id, tokenAddress: mcUSDC.addressOn(optimism.id), amount: parseUnits("1", 6), spender: "0x..." } }); ``` -------------------------------- ### Initialize Nexus Client with Smart Sessions Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/smart-sessions/policies/time-range-policy.mdx Sets up the Nexus client and installs the smart sessions module required for policy enforcement. ```typescript // @errors: 8010 import { Address, Hex, http } from "viem"; import { ActionPolicyInfo, CreateSessionDataParams, toSmartSessionsValidator, smartSessionCreateActions } from "@biconomy/sdk-canary"; import { privateKeyToAccount } from "viem/accounts"; import { createBicoBundlerClient, toNexusAccount } from "@biconomy/abstractjs"; import { baseSepolia } from "viem/chains"; const privateKey = "PRIVATE_KEY"; const account = privateKeyToAccount(`0x${privateKey}`) const bundlerUrl = "https://bundler.biconomy.io/api/v3/84532/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44"; export const nexusClient = createBicoBundlerClient({ account: await toNexusAccount({ signer: account, chain: baseSepolia, transport: http(), }), transport: http(bundlerUrl), }) // ---cut--- const sessionsModule = toSmartSessionsValidator({ account: nexusClient.account, signer: account }) // Install the smart sessions module on the Nexus client's smart contract account const hash = await nexusClient.installModule({ module: sessionsModule.moduleInitData }) const { success } = await nexusClient.waitForUserOperationReceipt({ hash }) // Extend the Nexus client with smart session creation actions export const usersNexusClient = nexusClient.extend( smartSessionCreateActions(sessionsModule) ) ``` -------------------------------- ### Initialize Nexus Client for Smart Sessions Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/smart-sessions/policies/sudo-policy.mdx Sets up the Biconomy Nexus client, installs the smart sessions module, and extends the client with session creation actions. ```ts import { OneOf, Address, Hex, http } from "viem" import { ActionPolicyInfo, CreateSessionDataParams, toSmartSessionsValidator, smartSessionCreateActions } from "@biconomy/sdk-canary" import { privateKeyToAccount } from "viem/accounts"; import { createBicoBundlerClient } from "@biconomy/abstractjs"; import { baseSepolia } from "viem/chains"; const privateKey = "PRIVATE_KEY"; const account = privateKeyToAccount(`0x${privateKey}`) const bundlerUrl = "https://bundler.biconomy.io/api/v3/84532/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44"; export const nexusClient = createBicoBundlerClient({ account: await toNexusAccount({ signer: account, chain: baseSepolia, transport: http(), }), transport: http(bundlerUrl), }) // ---cut--- const sessionsModule = toSmartSessionsValidator({ account: nexusClient.account, signer: account }) // Install the smart sessions module on the Nexus client's smart contract account const hash = await nexusClient.installModule({ module: sessionsModule.moduleInitData }) const { success } = await nexusClient.waitForUserOperationReceipt({ hash }) // Extend the Nexus client with smart session creation actions export const usersNexusClient = nexusClient.extend( smartSessionCreateActions(sessionsModule) ) ``` -------------------------------- ### Token Transfer Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/account/methods/build.md Constructs instructions for transferring tokens to a specified recipient. ```typescript const transferInstructions = await mcAccount.build({ type: "transfer", data: { chainId: optimism.id, tokenAddress: mcUSDC.addressOn(optimism.id), amount: parseUnits("1", 6), recipient: "0x..." } }); ``` -------------------------------- ### Get Permit Quote for Multiple Instructions Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/getPermitQuote.md Demonstrates how to initialize a multichain account, define instructions, and request a permit quote using the MEE client. ```typescript import { createMeeClient, toMultichainNexusAccount, mcUSDC } from "@biconomy/abstractjs"; import { http } from "viem"; import { mainnet, optimism } from "viem/chains"; // Setup multichain account const mcNexus = await toMultichainNexusAccount({ chains: [mainnet, optimism], signer: eoaAccount, transports: [http(), http()] }); // Create MEE client const meeClient = await createMeeClient({ account: mcNexus }); // Token address const tokenAddress = mcUSDC.addressOn(mainnet.id); // Create trigger const trigger = { chainId: mainnet.id, tokenAddress: tokenAddress, amount: 1n // Minimal amount for test }; // Fee token const feeToken = { address: tokenAddress, chainId: mainnet.id }; // Create multiple instructions const instructions = [ // First instruction on Optimism { calls: [ { to: "0x0000000000000000000000000000000000000000", gasLimit: 50000n, value: 0n } ], chainId: optimism.id }, // Second instruction on Optimism { calls: [ { to: "0x0000000000000000000000000000000000000000", gasLimit: 50000n, value: 0n } ], chainId: optimism.id } ]; // Get permit quote for multiple instructions try { const quote = await meeClient.getPermitQuote({ instructions, feeToken, trigger }); console.log("Permit quote received for multiple instructions"); console.log(`Number of user operations: ${quote.quote.userOps.length}`); console.log(`Quote ID: ${quote.quote.id}`); // The quote can now be signed and executed } catch (error) { console.error("Error getting permit quote:", error); } ``` -------------------------------- ### Setup MEE Client for Time-Bounded Transactions Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/set-execution-time-bounds.mdx Initialize the MEE client and Multichain Nexus account required to interact with time-bound execution features. ```ts import { createMeeClient, toMultichainNexusAccount } from "@biconomy/abstractjs"; import { http, type Hex } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { base, optimism } from "viem/chains"; const eoa = privateKeyToAccount(Bun.env.PRIVATE_KEY as Hex); const orchestrator = await toMultichainNexusAccount({ chains: [optimism, base], transports: [http(), http()], signer: eoa }); const date = new Date(); const meeClient = await createMeeClient({ account: orchestrator }); const minutesToSeconds = (input: number) => input * 60; ``` -------------------------------- ### Setup Session Signer for Multichain Account Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/smart-sessions/execute-transactions-on-users-behalf.mdx Initializes a multichain account with a session signer and extends the client with session actions. ```ts const userOwnedOrchestratorWithSessionSigner = await toMultichainNexusAccount({ chains: [optimism, base, arbitrum, polygon], transports: [http(), http(), http(), http()], accountAddress: orchestrator.addressOn(base.id)!, signer: sessionSigner }) const sessionSignerMeeClient = await createMeeClient({ account: userOwnedOrchestratorWithSessionSigner }) const sessionSignerSessionMeeClient = sessionSignerMeeClient.extend(meeSessionActions) ``` -------------------------------- ### Execute Transactions with Time Bounds Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/set-execution-time-bounds.mdx Examples of configuring instant, delayed, and windowed execution using quote parameters. ```ts const instantTxDefaultExpiryTime = await meeClient.getQuote({ instructions: [], feeToken: { address: '0xYourFeeTokenAddress', chainId: base.id }, }); ``` ```ts const instantTxCustomExpiry = await meeClient.getQuote({ instructions: [], feeToken: { address: '0xYourFeeTokenAddress', chainId: base.id }, upperBoundTimestamp: Date.now() + minutesToSeconds(1) }); ``` ```ts const scheduledTxQuote = await meeClient.getQuote({ instructions: [], feeToken: { address: '0xYourFeeTokenAddress', chainId: base.id }, lowerBoundTimestamp: Date.now() + minutesToSeconds(5) }); ``` ```ts const boundedTx = await meeClient.getQuote({ instructions: [], feeToken: { address: '0xYourFeeTokenAddress', chainId: base.id }, lowerBoundTimestamp: Date.now() + minutesToSeconds(2), upperBoundTimestamp: Date.now() + minutesToSeconds(5) }); ``` -------------------------------- ### Set Up Wallet Client Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/enable-mee-eoa-7702.mdx Initialize a viem wallet client using a private key account. ```ts import { createWalletClient, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; const eoa = privateKeyToAccount(Bun.env.PRIVATE_KEY as `0x${string}`); const walletClient = createWalletClient({ transport: http(), }); ``` -------------------------------- ### Initialize Wallet and Orchestrator Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/external-wallets-quickstart.mdx Sets up the wallet client using window.ethereum and initializes the multichain orchestrator and MEE client. ```ts const walletClient = createWalletClient({ chain: baseSepolia, transport: custom(window.ethereum) }); const orchestrator = await toMultichainNexusAccount({ chains: [baseSepolia], transports: [http()], signer: walletClient }); const meeClient = await createMeeClient({ account: orchestrator }); ``` -------------------------------- ### Initialize Turnkey Client Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/wallets-and-signers/turnkey.mdx Set up the Turnkey client for key management and signing operations. ```ts import { Turnkey } from "@turnkey/sdk-server"; import * as dotenv from "dotenv"; dotenv.config(); const client = new Turnkey({ apiBaseUrl: process.env.BASE_URL, apiPrivateKey: process.env.API_PRIVATE_KEY, apiPublicKey: process.env.API_PUBLIC_KEY, defaultOrganizationId: process.env.ORGANIZATION_ID, }); ``` -------------------------------- ### Bridge Intent Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/account/methods/build.md Constructs instructions for a cross-chain bridge intent. ```typescript const bridgeInstructions = await mcAccount.build({ type: "intent", data: { amount: parseUnits("1", 6), // 1 USDC mcToken: mcUSDC, toChain: optimism } }); ``` -------------------------------- ### getFusionQuote Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/index.md Gets a quote for executing a Fusion transaction for EOA wallets. ```APIDOC ## getFusionQuote ### Description Gets a quote for executing a Fusion transaction, which allows regular EOA wallets to perform complex operations. ### Method `meeClient.getFusionQuote(params)` ### Parameters - **trigger** (Object) - Required - The on-chain trigger transaction details. - **instructions** (Array) - Required - Instructions to execute after the trigger. - **feeToken** (Object) - Required - Token details used for payment. ``` -------------------------------- ### GET /v1/sponsorship/info Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/advanced/self-hosted-sponsorship.mdx Retrieves the available gas tanks and their current balances. ```APIDOC ## GET /v1/sponsorship/info ### Description Returns available gas tanks and their balances. ### Method GET ### Endpoint /v1/sponsorship/info ``` -------------------------------- ### Default Transaction Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/account/methods/build.md Constructs instructions for a standard contract call transaction. ```typescript const defaultInstructions = await mcAccount.build({ type: "default", data: { calls: [{ to: "0x...", value: 0n, gasLimit: 50000n }], chainId: optimism.id } }); ``` -------------------------------- ### Initialize Biconomy-Hosted Client Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/sponsor-gas-for-users.mdx Create a client instance using your project API key for Biconomy-managed sponsorship. ```ts const meeClient = await createMeeClient({ account: orchestrator, apiKey: "your_project_api_key" }); ``` -------------------------------- ### Basic Usage of MEE Client Helpers Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/helpers/index.md Demonstrates importing helpers, generating explorer links, and using runtime values with buildComposable for dynamic transaction data. ```typescript import { getMultichainContract, getMeeScanLink, runtimeERC20BalanceOf, mcUSDC } from "@biconomy/abstractjs"; // Get a contract address const usdcAddress = mcUSDC.addressOn(10); // Get USDC address on Optimism // Create a transaction explorer link const txHash = "0x123..."; const explorerUrl = getMeeScanLink(txHash); // Create a runtime value that resolves to the current USDC balance const dynamicAmount = runtimeERC20BalanceOf({ targetAddress: mcNexus.addressOn(chainId), tokenAddress: mcUSDC.addressOn(chainId) }); // IMPORTANT: When using runtime helpers, always use buildComposable instead of build const transferInstruction = await mcNexus.buildComposable({ type: "transfer", data: { recipient: recipientAddress, tokenAddress: mcUSDC.addressOn(chainId), amount: dynamicAmount, // Will use actual balance at execution time chainId: chainId } }); // The instruction can now be used with getQuote const quote = await meeClient.getQuote({ instructions: [transferInstruction], feeToken: { address: mcUSDC.addressOn(paymentChain.id), chainId: paymentChain.id } }); ``` -------------------------------- ### Error Handling for signQuote Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/signQuote.md Example of catching and handling potential errors during the signing process. ```typescript try { const signedQuote = await meeClient.signQuote({ quote }); console.log("Quote successfully signed"); } catch (error) { if (error.message.includes("signature")) { console.error("Failed to sign the quote. Check signer permissions."); } else if (error.message.includes("format")) { console.error("Invalid quote format"); } else { console.error("Error signing quote:", error); } } ``` -------------------------------- ### Get Gas Tank Address Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/advanced/self-hosted-sponsorship.mdx Retrieves the address associated with the gas tank account. ```ts const { address: gasTankAddress } = await gasTankAccount.getAddress() ``` -------------------------------- ### Create Wallet Client Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/wallets-and-signers/turnkey.mdx Create a viem wallet client using the Turnkey account. ```ts import { createWalletClient, http } from "viem"; import { createAccount } from "@turnkey/viem"; import { optimism } from "viem/chains"; const account = await createAccount({ client: client.apiClient(), organizationId: process.env.ORGANIZATION_ID, signWith: process.env.SIGN_WITH, }); const walletClient = createWalletClient({ account, chain: optimism, transport: http(), }); ``` -------------------------------- ### GET /v1/sponsorship/receipt/:chainId/:hash Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/advanced/self-hosted-sponsorship.mdx Retrieves the transaction receipt for a specific sponsorship transaction. ```APIDOC ## GET /v1/sponsorship/receipt/:chainId/:hash ### Description Returns the transaction receipt for a sponsorship transaction. ### Method GET ### Endpoint /v1/sponsorship/receipt/:chainId/:hash ### Parameters #### Path Parameters - **chainId** (string) - Required - The ID of the chain. - **hash** (string) - Required - The transaction hash. ``` -------------------------------- ### Get Gas Tank Balance Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/advanced/self-hosted-sponsorship.mdx Fetches the balance and decimals for a specific token in the gas tank. ```ts const { balance, decimals } = await gasTankAccount.getBalance({ tokenAddress: testnetMcUSDC.addressOn(baseSepolia.id) }) ``` -------------------------------- ### Initialize MEE Client and Orchestrator Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-lifi.mdx Set up the multichain account and initialize the MEE client with your API key. ```typescript // Create orchestrator account const eoa = privateKeyToAccount(PRIVATE_KEY) const orchestrator = await toMultichainNexusAccount({ chains: [optimism, base], transports: [http(), http('https://base.llamarpc.com')], signer: eoa }) // Initialize MEE client const meeClient = await createMeeClient({ account: orchestrator, apiKey: 'your_mee_api_key' }) ``` -------------------------------- ### Initialize AbstractJS dependencies Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/set-up-abstractjs.mdx Import necessary modules and configure the signer using a private key. ```typescript import { createMeeClient, toMultichainNexusAccount } from "@biconomy/abstractjs"; import { http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { base, optimism } from "viem/chains"; const eoa = privateKeyToAccount(Bun.env.PRIVATE_KEY as `0x${string}`) ``` -------------------------------- ### Comprehensive USDC Operations Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/helpers/more/mcUSDC.md A full example covering approval, transfer, balance checks, and allowance retrieval. ```typescript import { mcUSDC } from "@biconomy/abstractjs" import { optimism } from "viem/chains" import { parseUnits } from "viem" // Approve a spender const approveOp = await mcUSDC.build({ type: "approve", data: { chainId: optimism.id, args: [ spenderAddress, parseUnits("1000", 6) // 1000 USDC ] } }) // Transfer USDC const transferOp = await mcUSDC.build({ type: "transfer", data: { chainId: optimism.id, args: [ recipientAddress, parseUnits("50", 6) // 50 USDC ] } }) // Check balances across chains const balances = await mcUSDC.read({ onChains: [optimism, base], functionName: "balanceOf", args: [userAddress] }) // Get allowance const allowance = await mcUSDC.read({ onChains: [optimism], functionName: "allowance", args: [userAddress, spenderAddress] }) ``` -------------------------------- ### Get supertransaction receipt with TypeScript Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/index.md Retrieves the receipt for a supertransaction to check its execution status and explorer links. ```typescript const receipt = await meeClient.getSupertransactionReceipt({ hash }); console.log("Transaction status:", receipt.transactionStatus); console.log("Explorer links:", receipt.explorerLinks); ``` -------------------------------- ### Get Relay Bridge Quote Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-relay.mdx Fetches a bridge quote from Relay and extracts the transaction request data. ```typescript const relayQuote = await getRelayQuote({ amount: inputAmount.toString(), originChainId: optimism.id, originCurrency: usdcAddresses[optimism.id], destinationChainId: base.id, destinationCurrency: usdcAddresses[base.id], recipient: orchestrator.addressOn(base.id)!, tradeType: 'EXACT_INPUT', user: orchestrator.addressOn(optimism.id)! }) // Extract transaction data from Relay quote const txStep = relayQuote.steps.find(step => step.kind === 'transaction') const transactionRequest = txStep?.items.at(0)?.data if (!transactionRequest) { throw Error("No transaction parsed from Relay") } ``` -------------------------------- ### Get LiFi Bridge Quote Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-lifi.mdx Retrieve a bridge quote from LiFi to facilitate cross-chain asset movement. ```typescript const { transactionRequest } = await getLifiQuote({ fromAddress: orchestrator.addressOn(optimism.id, true), toAddress: orchestrator.addressOn(base.id, true), fromAmount: inputAmount.toString(), fromChain: optimism.id.toString(), fromToken: usdcAddresses[optimism.id], toChain: base.id.toString(), toToken: usdcAddresses[base.id], order: 'FASTEST' // or 'CHEAPEST' for cost optimization }) ``` -------------------------------- ### Retrieve an on-chain quote Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/getOnChainQuote.md Example usage of the getOnChainQuote method with required instructions, fee token, and trigger parameters. ```typescript const onChainQuote = await meeClient.getOnChainQuote({ instructions: [ // Instructions to execute ], feeToken: { address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC chainId: 1 // Ethereum }, trigger: { chainId: 1, // Ethereum tokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC amount: 1000000n // 1 USDC (6 decimals) } }); ``` -------------------------------- ### Configure main.tsx Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/embedded-wallets-quickstart.mdx Wrap the application with PrivyProvider, QueryClientProvider, and WagmiProvider. ```tsx import React from 'react'; import ReactDOM from 'react-dom/client'; import App from './App.tsx'; import './index.css'; import { PrivyProvider } from '@privy-io/react-auth'; import { WagmiProvider } from 'wagmi'; import { wagmiConfig } from './wagmi.ts'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; const appId = 'your-privy-app-id'; const queryClient = new QueryClient(); ReactDOM.createRoot(document.getElementById('root')!).render( ); ``` -------------------------------- ### Initialize Vite Project Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/embedded-wallets-quickstart.mdx Create a new React TypeScript project using Vite. ```bash bun create vite biconomy-mee-embedded-example --template react-ts cd biconomy-mee-embedded-example ``` -------------------------------- ### Handle Multichain Contract Errors Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/helpers/getMultichainContract.md Examples of catching errors when accessing missing deployments or calling non-existent functions. ```typescript // Error when accessing a non-existent deployment try { const address = mcUSDC.addressOn(1); // Assuming no deployment on chain ID 1 } catch (error) { console.error(error.message); // "No deployment found for chain 1" } // Error when calling a non-existent function try { // TypeScript would catch this at compile time, but this can happen at runtime mcUSDC.on(optimism.id).nonExistentFunction({ args: [], gasLimit: 100000n }); } catch (error) { console.error(error.message); // "Function nonExistentFunction not found in ABI" } ``` -------------------------------- ### Initialize Nexus SDK for Application Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/migrations/v2ToNexus.md Standard pattern for initializing the Nexus SDK in your application. Always provide the existing V2 account address to maintain continuity. ```typescript // IMPORTANT: Always use the same address as your V2 account const migratedAccountAddress = "YOUR_V2_ACCOUNT_ADDRESS"; // Use this pattern for all future SDK interactions const nexusAccount = await toNexusAccount({ signer: eoaAccount, chain: base, transport: http(), accountAddress: migratedAccountAddress }); const bundlerClient = createBicoBundlerClient({ account: nexusAccount, transport: http(bundlerUrl) }); ``` -------------------------------- ### Initialize Multichain Account and MEE Client Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/orchestrate-transactions-across-chains.mdx Sets up the Multichain Nexus account with specified chains and transports, then initializes the MEE client. ```ts const oNexus = await toMultichainNexusAccount({ signer: walletProvider, // Embedded or EOA signer chains: [arbitrum, base], transports: [http(), http()], }); const meeClient = await createMeeClient({ account: oNexus }); ``` -------------------------------- ### Traditional Transaction Approaches Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/learn-about-biconomy/understanding-composable-orchestration.mdx Examples of common pitfalls when handling multi-step transactions, such as hardcoding amounts or leaving dust in contracts. ```typescript // Traditional approach - pick your poison: // Option 1: Hardcode amounts (fails often) await token.approve(DEX, 1000) await dex.swap(1000_USDC → 0.5_ETH) // What if you get 0.48 ETH? await aave.supply(0.5_ETH) // Transaction fails! // Option 2: Overestimate and leave dust await token.approve(DEX, 1000) await dex.swap(1000_USDC → ETH) // Get 0.48 ETH await aave.supply(0.4_ETH) // 0.08 ETH stuck as dust ``` -------------------------------- ### Connect to V2 Smart Account Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/migrations/v2ToNexus.md Configure the environment and initialize the V2 smart account client using existing EOA credentials and Biconomy infrastructure URLs. ```typescript import { createWalletClient, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { base } from "viem/chains"; import { createSmartAccountClient as createV2Client, BiconomySmartAccountV2, PaymasterMode } from "@biconomy/account"; // Define configuration variables const config = { // Chain and network information chain: base, // EOA credentials eoaPrivateKey: "YOUR_PRIVATE_KEY", // Replace with your private key eoaAddress: "YOUR_EOA_ADDRESS", // Replace with your EOA address // Biconomy infrastructure URLs v2BundlerUrl: "YOUR_V2_BUNDLER_URL", // Replace with your V2 bundler URL nexusBundlerUrl: "YOUR_NEXUS_BUNDLER_URL", // Replace with your Nexus bundler URL // API keys paymasterApiKey: "YOUR_PAYMASTER_API_KEY", // Replace with your Paymaster API key // Nexus contract addresses // Use the latest addresses from here https://docs.biconomy.io/contracts-and-audits/ nexusImplementationAddress: "", nexusBootstrapAddress: "", emptyHookAddress: "0x0000000000000000000000000000000000000001" }; // Connect to your EOA const eoaAccount = privateKeyToAccount("0x" + config.eoaPrivateKey); const client = createWalletClient({ account: eoaAccount, chain: config.chain, transport: http(), }); // Connect to your V2 smart account const V2Account = await createV2Client({ signer: client, biconomyPaymasterApiKey: config.paymasterApiKey, bundlerUrl: config.v2BundlerUrl, }); // Get V2 account address const V2AccountAddress = await V2Account.getAccountAddress(); console.log("V2 Account Address:", V2AccountAddress); ``` -------------------------------- ### Signing a Permit Quote for Intents and Transactions Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/signPermitQuote.md Demonstrates how to initialize a multichain account, create a MEE client, generate a fusion quote with mixed instructions, and sign the resulting permit quote. ```typescript import { createMeeClient, toMultichainNexusAccount, mcUSDC } from "@biconomy/abstractjs"; import { http, zeroAddress } from "viem"; import { mainnet, optimism } from "viem/chains"; // Setup multichain account const mcNexus = await toMultichainNexusAccount({ chains: [mainnet, optimism], signer: eoaAccount, transports: [http(), http()] }); // Create MEE client const meeClient = await createMeeClient({ account: mcNexus }); // Token address const tokenAddress = mcUSDC.addressOn(mainnet.id); // Create trigger const trigger = { chainId: mainnet.id, tokenAddress: tokenAddress, amount: 1n // Minimal amount for test }; // Fee token const feeToken = { address: tokenAddress, chainId: mainnet.id }; // Get permit quote for an intent and a transaction try { const fusionQuote = await meeClient.getPermitQuote({ trigger, instructions: [ // Intent to bridge USDC to the target chain mcNexus.build({ type: "intent", data: { amount: 1n, mcToken: mcUSDC, toChain: optimism } }), // A simple transaction on the target chain mcNexus.build({ type: "default", data: { calls: [ { to: zeroAddress, gasLimit: 50000n, value: 0n } ], chainId: optimism.id } }) ], feeToken }); // Sign the fusion quote with the permit const signedQuote = await meeClient.signPermitQuote({ fusionQuote }); console.log("Permit quote signed for intent and transaction"); console.log(`Number of user operations: ${signedQuote.userOps.length}`); console.log(`Quote ID: ${signedQuote.id}`); console.log(`Signature: ${signedQuote.signature.slice(0, 66)}...`); } catch (error) { console.error("Error signing permit quote:", error); } ``` -------------------------------- ### GET /v1/sponsorship/nonce/:chainId/:gasTankAddress Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/advanced/self-hosted-sponsorship.mdx Retrieves the current nonce and nonce key for a specific gas tank on a given chain. ```APIDOC ## GET /v1/sponsorship/nonce/:chainId/:gasTankAddress ### Description Returns the current nonce and nonce key for a given gas tank. ### Method GET ### Endpoint /v1/sponsorship/nonce/:chainId/:gasTankAddress ### Parameters #### Path Parameters - **chainId** (string) - Required - The ID of the chain. - **gasTankAddress** (string) - Required - The address of the gas tank. ``` -------------------------------- ### Initialize and use a Multichain Contract Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/helpers/getMultichainContract.md Demonstrates creating a multichain contract instance using an ABI and a list of chain-specific addresses, then retrieving a specific address. ```typescript import { getMultichainContract } from "@biconomy/abstractjs"; import { erc20Abi } from "viem"; import { optimism, base } from "viem/chains"; // Create a multichain contract instance const mcUSDC = getMultichainContract({ abi: erc20Abi, deployments: [ ["0x7F5c764cBc14f9669B88837ca1490cCa17c31607", optimism.id], // Optimism USDC ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", base.id] // Base USDC ] }); // Get contract address on a specific chain const optimismUSDCAddress = mcUSDC.addressOn(optimism.id); console.log("USDC on Optimism:", optimismUSDCAddress); ``` -------------------------------- ### Manual execution approach Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/execute.md Shows how to perform quote generation, signing, and execution as separate steps for greater control over the process. ```typescript // Manual approach with separate steps const quote = await meeClient.getQuote({ instructions, feeToken }); // At this point, you can display gas costs to the user console.log("Gas fee in tokens:", quote.paymentInfo.amount); console.log("Token symbol:", quote.paymentInfo.tokenSymbol); // Proceed with signing and execution only after user confirmation const signedQuote = await meeClient.signQuote({ quote }); const { hash } = await meeClient.executeSignedQuote({ signedQuote }); ``` -------------------------------- ### Sponsor EIP-7702 Transactions Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/sponsor-gas-for-users.mdx Use this pattern for embedded wallets to install smart account logic on EOAs. Requires an authorization object. ```ts const quote = await meeClient.getQuote({ sponsorship: true, instructions: [/* your calls here */], delegate: true, authorization // Required for 7702 accounts }); ``` -------------------------------- ### createMeeClient Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/index.md Initializes a new MEE client instance with the required account and optional configuration parameters. ```APIDOC ## createMeeClient ### Description Initializes the MEE client used to interact with the Biconomy network. ### Parameters - **account** (MultichainSmartAccount) - Required - The multichain smart account to use for transactions. - **apiKey** (string) - Optional - API key for production use with higher rate limits. - **url** (Url) - Optional - URL for the MEE node service. Defaults to "https://network.biconomy.io/v1". - **pollingInterval** (number) - Optional - Polling interval in milliseconds. Defaults to 1000. ``` -------------------------------- ### Sign EIP-7702 Authorization Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/wallets-and-signers/privy.mdx Sign the authorization to install the Biconomy Nexus smart account code onto the Privy EOA address. ```ts const authorization = await signAuthorization({ contractAddress: NEXUS_IMPLEMENTATION, chainId: 0, }); ``` -------------------------------- ### Get Fusion transaction quote with TypeScript Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/index.md Retrieves a quote for Fusion transactions, enabling EOA wallets to perform complex operations. ```typescript const fusionQuote = await meeClient.getFusionQuote({ // The on-chain trigger transaction trigger: { chainId: optimism.id, tokenAddress: "0xUSDCAddress", amount: parseUnits("1", 6) }, // Instructions to execute after trigger instructions: [ approveInstruction, supplyInstruction ], // Pay with these tokens feeToken: { address: "0xUSDCAddress", chainId: optimism.id } }); ```