### Project Setup and Dependencies Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/external-wallets-quickstart.mdx Commands to create a new Vite React TypeScript project, install dependencies including Biconomy abstractjs, viem, wagmi, and peer dependencies for wagmi. ```bash bun create vite fusion-single-chain --template react-ts cd fusion-single-chain bun install bun add viem wagmi @biconomy/abstractjs bun add @tanstack/react-query ethers ``` -------------------------------- ### Install Dependencies Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/embedded-wallets-quickstart.mdx Command to install all the project dependencies listed in the package.json file using Bun. ```bash bun install ``` -------------------------------- ### Install AbstractJS SDK Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/migrations/v2ToNexus.md Installs the latest version of the AbstractJS SDK using npm. This is a prerequisite for the migration process. ```bash npm install @biconomy/abstractjs ``` -------------------------------- ### Complete Nexus Account Migration Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/migrations/nexusToNexus.md A comprehensive TypeScript example demonstrating the full process of migrating a Nexus account. It covers setting up the account, connecting to the bundler client, upgrading the smart account, and testing the upgraded account with a transaction. ```typescript import { privateKeyToAccount } from "viem/accounts"; import { createBicoBundlerClient, toNexusAccount } from "@biconomy/abstractjs"; import { baseSepolia } from "viem/chains"; import { http } from "viem"; async function migrateNexusAccount() { // Setup const privateKey = "YOUR_PRIVATE_KEY"; const account = privateKeyToAccount(`0x${privateKey}`); const bundlerUrl = "YOUR_BUNDLER_URL"; // Your existing account address - CRITICAL for migration const existingAccountAddress = "YOUR_EXISTING_ACCOUNT_ADDRESS"; // Connect to your existing account const nexusAccount = await toNexusAccount({ signer: account, chain: baseSepolia, transport: http(), accountAddress: existingAccountAddress }); const bundlerClient = createBicoBundlerClient({ account: nexusAccount, transport: http(bundlerUrl) }); // Check the account ID before upgrade const oldAccountId = await bundlerClient.accountId(); console.log("Account ID before upgrade:", oldAccountId); // Verify account is deployed const isDeployed = await bundlerClient.account.isDeployed(); if (!isDeployed) { console.log("Account not deployed. Please deploy the account first."); return; } console.log("Starting account upgrade..."); // Upgrade the account to the latest implementation const hash = await bundlerClient.upgradeSmartAccount(); console.log("Upgrade transaction submitted:", hash); // Wait for the upgrade transaction to be processed const receipt = await bundlerClient.waitForUserOperationReceipt({ hash }); console.log("Upgrade transaction completed. Success:", receipt.success); if (!receipt.success) { console.error("Upgrade failed. Please check gas, balance, and permissions."); return; } // Verify the account has been upgraded const newAccountId = await bundlerClient.accountId(); console.log("Account ID after upgrade:", newAccountId); // CRITICAL: Verify and store the account address for future use const accountAddress = await bundlerClient.account.getAddress(); console.log("STORE THIS ACCOUNT ADDRESS:", accountAddress); // Test the upgraded account with a transaction console.log("Testing upgraded account with a transaction..."); // Example: Simple transaction to verify everything works try { const testHash = await bundlerClient.sendUserOperation({ calls: [{ to: "0x0000000000000000000000000000000000000000", value: 0n, data: "0x" }] }); const testReceipt = await bundlerClient.waitForUserOperationReceipt({ hash: testHash }); console.log("Test transaction successful:", testReceipt.success); console.log("Migration completed successfully!"); } catch (error) { console.error("Test transaction failed:", error); } } migrateNexusAccount().catch(console.error); ``` -------------------------------- ### Basic signQuote Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/signQuote.md A comprehensive example demonstrating the full three-step transaction process: getQuote, signQuote, and executeSignedQuote, including client setup and fee token configuration. ```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 }); ``` -------------------------------- ### App Provider Setup Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/external-wallets-quickstart.mdx Wraps the main App component with WagmiProvider and QueryClientProvider in src/main.tsx for state management and blockchain interaction. ```typescript import { WagmiProvider } from 'wagmi' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { config } from './wagmi' import App from './App' const queryClient = new QueryClient() ReactDOM.createRoot(document.getElementById('root')!).render( ) ``` -------------------------------- ### Quick Start: Initialize MEE Client Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/index.md Demonstrates how to initialize the MEE Client by creating a signer account, initializing a multichain smart account, and then creating the MEE client instance. It also shows how to get a quote and execute it. ```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}`); ``` -------------------------------- ### Project Setup with Vite Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/embedded-wallets-quickstart.mdx Commands to create a new Vite project with React and TypeScript, navigate into the project directory, and add necessary dependencies for Biconomy MEE and Privy integration. ```bash bun create vite biconomy-mee-embedded-example --template react-ts cd biconomy-mee-embedded-example ``` -------------------------------- ### Biconomy Nexus Client and Smart Sessions Setup Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/smart-sessions/policies/sudo-policy.mdx This snippet details the setup of the Biconomy Nexus client and the installation of the smart sessions module. It includes private key management, bundler client creation, and extending the Nexus client with smart session creation capabilities. This is a foundational setup for managing sessions and permissions. ```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), }) // --- 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) ) ``` -------------------------------- ### MEE Client Integration Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/learn-about-biconomy/what-is-mee.mdx Provides a step-by-step guide on integrating MEE into an application, including creating a multichain account and executing orchestrated flows. ```typescript import { createMeeClient, toMultichainNexusAccount } from "@biconomy/abstractjs" // 1. Create account const account = await toMultichainNexusAccount({ signer: userWallet, chains: [optimism, base, arbitrum], transports: [http(), http(), http()] }) // 2. Create client const meeClient = await createMeeClient({ account }) // 3. Execute anything const { hash } = await meeClient.execute({ instructions: [...], // Your orchestrated flow feeToken: { address: USER_PREFERRED_TOKEN } }) ``` -------------------------------- ### Biconomy Nexus Client and Smart Sessions Setup Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/smart-sessions/policies/universal-action-policy.mdx This code sets up the Biconomy Nexus client using viem and the Biconomy SDK. It includes initializing the client with a bundler URL, installing the smart sessions module, and extending the client with smart session creation capabilities. ```ts import { OneOf, 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), }) // --- 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) ) ``` -------------------------------- ### Referral Tracking Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-across.mdx Shows how to implement referral tracking by providing a referrer address in the `getAcrossSuggestedFees` parameters. ```typescript const fees = await getAcrossSuggestedFees({ // ... other params referrer: '0xYourReferrerAddress', }) ``` -------------------------------- ### React Application Setup with Wagmi and React Query Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/external-wallets-quickstart.mdx This main.tsx file sets up the root of the React application. It integrates Wagmi for blockchain interactions and React Query for state management, wrapping the main App component within the necessary providers. ```tsx import ReactDOM from 'react-dom/client'; import { WagmiProvider } from 'wagmi'; import { QueryClient, QueryClientProvider } from '@tan/react-query'; import { config } from './wagmi'; import App from './App'; const queryClient = new QueryClient(); ReactDOM.createRoot(document.getElementById('root')!).render( ); ``` -------------------------------- ### Revenue Sharing Setup Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-lifi.mdx Demonstrates how to configure revenue sharing by providing integrator and fee details in the LiFi quote request. This enables earning fees by setting an integrator name, a fee percentage, and a referrer address. ```typescript const quote = await getLifiQuote({ // ... other params integrator: 'YourAppName', fee: 0.003, // 0.3% fee referrer: '0xYourAddress' }) ``` -------------------------------- ### Cleanup Mechanism Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-lifi.mdx Demonstrates how to define cleanup instructions to return funds if any step in a cross-chain operation fails. This ensures assets are safely returned to the specified recipient. ```typescript cleanUps: [{ chainId: base.id, recipientAddress: eoa.address, tokenAddress: usdcAddresses[base.id] }] ``` -------------------------------- ### Basic Usage Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/helpers/index.md Demonstrates how to use MEE client helpers for getting contract addresses, generating explorer links, and creating runtime values for dynamic transaction data. It highlights the use of `buildComposable` when working with runtime helpers. ```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 } }); ``` -------------------------------- ### Full Execution Flow Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/signOnChainQuote.md Demonstrates a complete transaction flow using the Biconomy Abstract SDK. This includes setting up a multichain account, creating a MEE client, getting an on-chain quote for token transfers, signing the quote, executing it, and waiting for the receipt. It also shows how to verify the recipient's balance. ```typescript import { createMeeClient, toMultichainNexusAccount, mcUSDC } from "@biconomy/abstractjs"; import { http, parseUnits } from "viem"; import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; import { optimism } from "viem/chains"; // Setup multichain account const mcNexus = await toMultichainNexusAccount({ chains: [optimism], signer: eoaAccount, transports: [http()] }); // Create MEE client const meeClient = await createMeeClient({ account: mcNexus }); // Create a recipient account for the transfer const recipientAccount = privateKeyToAccount(generatePrivateKey()); // Token address on Optimism const tokenAddress = mcUSDC.addressOn(optimism.id); // Create trigger for a token transfer const trigger = { chainId: optimism.id, tokenAddress: tokenAddress, amount: 1n // Minimal amount for testing }; // Fee token (same as trigger token in this example) const feeToken = { address: tokenAddress, chainId: optimism.id }; // Get deployment information const sender = mcNexus.signer.address; const { address: recipient } = mcNexus.deploymentOn(optimism.id, true); // Get an on-chain quote for a token transfer const onChainQuote = await meeClient.getOnChainQuote({ trigger, instructions: [ // Transfer from EOA to smart account mcNexus.build({ type: "transferFrom", data: { ...trigger, sender, recipient } }), // Transfer from smart account to recipient mcNexus.build({ type: "transfer", data: { ...trigger, recipient: recipientAccount.address } }) ], feeToken }); // Sign the on-chain quote (this sends an on-chain transaction) const signedQuote = await meeClient.signOnChainQuote({ fusionQuote: onChainQuote }); // Execute the signed quote const executionResponse = await meeClient.executeSignedQuote({ signedQuote }); console.log(`Quote execution submitted with hash: ${executionResponse.hash}`); // Wait for the supertransaction receipt const receipt = await meeClient.waitForSupertransactionReceipt({ hash: executionResponse.hash }); console.log("Transaction confirmed!"); console.log(`Explorer links: ${receipt.explorerLinks.join(', ')}`); // Verify the recipient received the tokens const recipientBalance = await getBalance( mcNexus.deploymentOn(optimism.id, true).publicClient, recipientAccount.address, tokenAddress ); console.log(`Recipient balance: ${recipientBalance}`); ``` -------------------------------- ### Complete Cross-Chain Operation Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/index.md Demonstrates a full workflow using the MeeClient to get a quote for cross-chain operations, execute the quote, and wait for the transaction receipt. It includes transferring USDC on Optimism and deploying a contract on Base. ```typescript import { createMeeClient, mcUSDC } from '@biconomy/abstractjs'; import { parseUnits } from 'viem'; // Create the MEE client const meeClient = await createMeeClient({ account: multiChainAccount, apiKey: "mee_your_api_key_here" // Optional for production use }); // 1. Get a quote for cross-chain operations const quote = await meeClient.getQuote({ instructions: [ // Transfer USDC on Optimism { calls: [{ to: "0xUSDCAddress", data: encodeTransferFunction("0xRecipient", parseUnits("10", 6)) }], chainId: optimism.id }, // Deploy a contract on Base { calls: [{ data: contractDeploymentBytecode }], chainId: base.id } ], feeToken: { address: mcUSDC.addressOn(optimism.id), chainId: optimism.id } }); // 2. Execute the quote const { hash } = await meeClient.executeQuote({ quote }); console.log(`Transaction submitted with hash: ${hash}`); // 3. Wait for transaction receipt const receipt = await meeClient.getSupertransactionReceipt({ hash }); console.log("Transaction completed with status:", receipt.transactionStatus); // Check individual user operations receipt.userOps.forEach((userOp, i) => { console.log(`Operation ${i} on chain ${userOp.chainId}: ${userOp.executionStatus}`); }); // Alternative: Use waitForSupertransactionReceipt to automatically wait for completion // const receipt = await meeClient.waitForSupertransactionReceipt({ hash }); // console.log("All operations completed with status:", receipt.transactionStatus); ``` -------------------------------- ### Install AbstractJS and Viem Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/set-up-abstractjs.mdx Installs the necessary AbstractJS and Viem packages using npm. ```bash npm install @biconomy/abstractjs viem ``` -------------------------------- ### Authorize with EIP-7702 for Smart Account Installation Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/embedded-wallets-quickstart.mdx TypeScript example demonstrating how to sign an authorization message using Privy's `signAuthorization` hook to install a Biconomy Nexus smart account on a Privy embedded wallet EOA. ```ts const authorization = await signAuthorization({ contractAddress: NEXUS_V120, chainId: baseSepolia.id, // or 0 for universal nonce: 0, }); ``` -------------------------------- ### Basic Setup with AbstractJS Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/set-up-abstractjs.mdx Imports dependencies and sets up a signer using Viem and 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}`) ``` -------------------------------- ### Basic getPermitQuote Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/getPermitQuote.md A comprehensive example demonstrating the setup of a multichain account, MEE client, and the usage of getPermitQuote for a simple transaction, including error handling. ```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 const tokenAddress = mcUSDC.addressOn(mainnet.id); // Create trigger information const trigger = { chainId: mainnet.id, tokenAddress: tokenAddress, amount: 1000000n // 1 USDC (6 decimals) }; // Fee token information const feeToken = { address: tokenAddress, chainId: mainnet.id }; try { // Get permit quote for a simple transaction const permitQuote = await meeClient.getPermitQuote({ instructions: [ mcNexus.build({ type: "default", data: { calls: [ { to: "0x0000000000000000000000000000000000000000", gasLimit: 50000n, value: 0n } ], chainId: optimism.id } }) ], feeToken, trigger }); console.log("Permit quote received:"); console.log(`Quote ID: ${permitQuote.quote.id}`); console.log(`Payment Token: ${permitQuote.quote.paymentInfo.token}`); console.log(`Payment Chain: ${permitQuote.quote.paymentInfo.chainId}`); console.log(`Total Amount (including fees): ${permitQuote.trigger.amount}`); // The permit quote can now be signed and executed } catch (error) { console.error("Error getting permit quote:", error); } ``` -------------------------------- ### Error Handling Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-across.mdx Provides an example of how to handle errors when fetching Across quotes, including checks for amount below minimum deposit and exceeding deposit limits. ```typescript try { const fees = await getAcrossSuggestedFees(parameters) // Check if amount is too low if (fees.isAmountTooLow) { throw new Error('❌ Amount below minimum deposit') } // Check deposit limits if (inputAmount > fees.limits.maxDepositInstant) { console.warn('⚠️ Amount exceeds instant deposit limit') } // ... orchestration logic } catch (error) { if (error.message.includes('HTTP error')) { console.error('❌ Failed to get Across quote') } console.error('🚨 Orchestration failed:', error) } ``` -------------------------------- ### Install MEE Client Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/index.md Installs the necessary packages for the MEE Client using either npm or yarn. ```bash npm install @biconomy/abstractjs viem @rhinestone/module-sdk # or yarn add @biconomy/abstractjs viem @rhinestone/module-sdk ``` -------------------------------- ### Main Application Entry Point Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/embedded-wallets-quickstart.mdx Configuration for the React application's main entry point (main.tsx), setting up PrivyProvider, QueryClientProvider, and WagmiProvider with necessary configurations. ```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( ); ``` -------------------------------- ### Example Usage of executeQuote Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/executeQuote.md Demonstrates how to use the executeQuote method, including getting a quote, executing it, and waiting for the transaction receipt. ```typescript // Get a quote for executing all instructions // This will calculate the total cost in the specified payment token const quote = await meeClient.getQuote({ instructions: [ mcNexus.build({ type: "default", data: { calls: [{ to: zeroAddress, value: 0n }], chainId: targetChain.id } }) ], feeToken: { address: mcUSDC.addressOn(paymentChain.id), chainId: paymentChain.id } }); // Execute the quote and get back a transaction hash // This sends the transaction to the network const { hash } = await meeClient.executeQuote({ quote }); // Wait for the transaction receipt const receipt = await meeClient.waitForSupertransactionReceipt({ hash }); // Check transaction status if (receipt.transactionStatus === "MINED_SUCCESS") { console.log("Transaction successful"); } ``` -------------------------------- ### Install Dependencies Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/wallets-and-signers/turnkey.mdx Installs the necessary SDKs from Turnkey, Biconomy, and viem for building gasless transaction solutions. ```bash npm install @turnkey/sdk-server @turnkey/viem @biconomy/abstractjs viem dotenv ``` -------------------------------- ### Basic getSupertransactionReceipt Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/getSupertransactionReceipt.md Demonstrates how to execute a quote, get its supertransaction receipt, and log the transaction status and explorer links. ```typescript const quote = await meeClient.getQuote({ instructions: [ { calls: [ { to: zeroAddress, value: 0n, gasLimit: 50000n } ], chainId: targetChain.id } ], feeToken: { address: mcUSDC.addressOn(paymentChain.id), chainId: paymentChain.id } }); const { hash } = await meeClient.executeQuote({ quote }); const receipt = await meeClient.getSupertransactionReceipt({ hash }); console.log(`Transaction status: ${receipt.transactionStatus}`); console.log(`Explorer links:`, receipt.explorerLinks); ``` -------------------------------- ### Initialize Biconomy MEE Client and Account Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/external-wallets-quickstart.mdx Connects to MetaMask, initializes a viem WalletClient, creates a multichain account using toMultichainNexusAccount, and sets up the Biconomy MEE client. ```tsx import { createWalletClient, custom, http, type WalletClient } from 'viem'; import { baseSepolia } from 'viem/chains'; import { createMeeClient, toMultichainNexusAccount, type MeeClient, type MultichainSmartAccount } from '@biconomy/abstractjs'; // ... inside the App component const connectAndInit = async () => { if (typeof (window as any).ethereum === 'undefined') { alert('MetaMask not detected'); return; } const wallet = createWalletClient({ chain: baseSepolia, transport: custom((window as any).ethereum) }); setWalletClient(wallet); const [address] = await wallet.requestAddresses(); setAccount(address); const multiAccount = await toMultichainNexusAccount({ chains: [baseSepolia], transports: [http()], signer: createWalletClient({ account: address, transport: custom((window as any).ethereum) }) }); setOrchestrator(multiAccount); const mee = await createMeeClient({ account: multiAccount }); setMeeClient(mee); }; ``` -------------------------------- ### Get MEE Scan Link Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/embedded-wallets-quickstart.mdx Generates a link to MEE Scan for tracking the status of a submitted transaction. ```ts const link = getMeeScanLink(hash); ``` -------------------------------- ### Basic Execute Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/execute.md A comprehensive example demonstrating how to set up a multichain account, create an MEE client, define a fee token, and execute a simple transaction. ```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 (optimism in this case) const feeToken = { address: mcUSDC.addressOn(optimism.id), chainId: optimism.id }; // Execute a simple transaction on the target chain const { hash } = await meeClient.execute({ instructions: [ { calls: [ { to: zeroAddress, value: 0n, gasLimit: 50000n } ], chainId: base.id } ], feeToken }); // Wait for transaction receipt const receipt = await meeClient.waitForSupertransactionReceipt({ hash }); console.log("Transaction completed:", receipt); ``` -------------------------------- ### Cleanup Mechanism Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-across.mdx Illustrates the cleanup instructions used to ensure funds are returned if any step in the orchestration fails. ```typescript cleanUps: [{ chainId: base.id, recipientAddress: eoa.address, tokenAddress: usdcAddresses[base.id] }] ``` -------------------------------- ### Wallet and Companion Initialization Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/external-wallets-quickstart.mdx Initializes a wallet client using window.ethereum and creates a Biconomy MEE Nexus account (Orchestrator) for multi-chain interactions. ```javascript import { createWalletClient, custom } from 'viem' import { baseSepolia } from 'viem/chains' import { toMultichainNexusAccount, createMeeClient } from '@biconomy/abstractjs' 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 }) ``` -------------------------------- ### Update AbstractJS Package Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/migrations/nexusToNexus.md Installs the latest version of the AbstractJS SDK using package managers like npm, yarn, pnpm, and bun. ```bash # npm npm update @biconomy/abstractjs # yarn yarn upgrade @biconomy/abstractjs # pnpm pnpm update @biconomy/abstractjs # bun bun update @biconomy/abstractjs ``` -------------------------------- ### MEE getInfo Basic Usage Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/methods/more/getInfo.md Demonstrates how to use the `getInfo` method with the MEE client to fetch and log service configuration details, including supported chains and wallet providers. ```typescript import { createMeeClient, toMultichainNexusAccount } from "@biconomy/abstractjs"; import { http } from "viem"; import { optimism, polygon } from "viem/chains"; // Setup multichain account const mcNexus = await toMultichainNexusAccount({ chains: [optimism, polygon], signer: eoaAccount, transports: [http(), http()] }); // Create MEE client const meeClient = await createMeeClient({ account: mcNexus }); try { const info = await meeClient.getInfo(); console.log(`MEE API Version: ${info.version}`); console.log(`Node: ${info.node}`); // Log supported chains console.log("Supported chains:"); info.supported_chains.forEach(chain => { console.log(`- ${chain.name} (Chain ID: ${chain.chainId})`); }); // Check if specific chains are supported const supportedChainIds = info.supported_chains.map(chain => Number(chain.chainId)); console.log(`Optimism (${optimism.id}) supported: ${supportedChainIds.includes(optimism.id)}`); console.log(`Polygon (${polygon.id}) supported: ${supportedChainIds.includes(polygon.id)}`); // Log wallet providers console.log("Supported wallet providers:"); info.supported_wallet_providers.forEach(provider => { console.log(`- ${provider.walletProvider}`); console.log(` Supported chains: ${provider.supportedChains.join(", ")}`); console.log(` EOA enabled: ${provider.eoaEnabled || false}`); console.log(` EOA fusion: ${provider.eoaFusion || false}`); }); // Check if USDC is available as a payment token const usdcAvailable = info.supported_gas_tokens.some(gasToken => gasToken.paymentTokens.some(token => token.symbol === "USDC") ); console.log(`USDC available as payment token: ${usdcAvailable}`); } catch (error) { console.error("Error fetching MEE service information:", error); } ``` -------------------------------- ### Exclusive Relayers Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-across.mdx Illustrates how to specify exclusive relayers for priority fills by providing the relayer address and exclusivity deadline in the transaction arguments. ```typescript args: [ // ... other args '0xRelayerAddress', // exclusiveRelayer // ... 300, // exclusivityDeadline (5 min) ] ``` -------------------------------- ### Cross-Chain Messaging Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-across.mdx Demonstrates how to include a message with a cross-chain bridge transaction using the `getAcrossSuggestedFees` function and passing the message to the deposit function. ```typescript const fees = await getAcrossSuggestedFees({ // ... other params message: '0x1234...', // Encoded message }) // Include message in deposit args: [ // ... other args message // Pass to depositV3 ] ``` -------------------------------- ### Tracking Transactions with MEE Scan Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-lifi.mdx Provides an example of how to generate a link to track a transaction on MEE Scan. This is useful for monitoring the status and details of cross-chain orchestrations. ```typescript const meeScanUrl = getMeeScanLink(hash) console.log(`🔍 Track transaction: ${meeScanUrl}`) ``` -------------------------------- ### Create MEE Client Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/getting-started/set-up-abstractjs.mdx Initializes an MEE client to connect to MEE Nodes for orchestration and gasless execution. ```typescript const meeClient = await createMeeClient({ account: orchestrator, apiKey: 'your-api-key', url: 'https://mee-node-url' }) ``` -------------------------------- ### Building Batch Transfer Instructions Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/external-wallets-quickstart.mdx Constructs multiple ERC-20 token transfer instructions using the orchestrator's buildComposable method for batch execution. ```javascript import { erc20Abi } from 'viem' const transfers = await Promise.all( recipients.map((recipient) => orchestrator.buildComposable({ type: 'default', data: { abi: erc20Abi, chainId: baseSepolia.id, to: usdcAddress, functionName: 'transfer', args: [recipient, 1_000_000n] // 1 USDC in 6 decimals } }) ) ) ``` -------------------------------- ### Multi-Chain Cleanup Configuration Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-relay.mdx Provides an example of configuring cleanup instructions for multiple chains, specifying the chain ID, recipient address, and token address for each. ```typescript cleanUps: [ { chainId: optimism.id, recipientAddress: eoa.address, tokenAddress: usdcOptimism }, { chainId: base.id, recipientAddress: eoa.address, tokenAddress: usdcBase } ] ``` -------------------------------- ### Project Dependencies Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/embedded-wallets-quickstart.mdx List of essential npm dependencies required for the project, including Biconomy abstractjs, Privy React and Wagmi integrations, Wagmi, Viem, and React query. ```json "dependencies": { "@biconomy/abstractjs": "^1.0.17", "@privy-io/react-auth": "^2.14.2", "@privy-io/wagmi": "^1.0.4", "@tanstack/react-query": "^5.80.7", "react": "^19.1.0", "react-dom": "^19.1.0", "viem": "^2.31.3", "wagmi": "^2.15.6" } ``` -------------------------------- ### Cleanup Mechanism Example Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/integration-guides/bridges-and-solvers/integrate-relay.mdx Demonstrates how to define cleanup instructions to ensure funds are returned if any step in an orchestration fails. This is crucial for robust cross-chain operations. ```typescript cleanUps: [{ chainId: base.id, recipientAddress: eoa.address, tokenAddress: usdcAddresses[base.id] }] ``` -------------------------------- ### deploymentOn Method API Reference Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/account/methods/more/deploymentOn.md Details the deploymentOn method for retrieving smart account deployment information. Includes parameter descriptions, return types, and usage examples. ```APIDOC deploymentOn(chainId: number, strictMode?: boolean): ModularSmartAccount | ModularSmartAccount | undefined Retrieves deployment information for a smart account on a specific chain. Parameters: chainId (number): The ID of the chain to query. strictMode (boolean, optional): If true, throws an error if no deployment exists for the specified chain. Defaults to false. Returns: ModularSmartAccount: If strictMode is true or a deployment exists. ModularSmartAccount | undefined: If strictMode is false and no deployment exists. Error Handling: - Throws an error if strictMode is true and no deployment exists for the specified chain. - Throws an error if an invalid chain ID is provided. Example: // Get deployment with strict mode (throws if not found). Type safely returns the ModularSmartAccount const optimismDeployment = account.deploymentOn(10, true); // Get deployment without strict mode (returns undefined if not found) const baseDeployment = account.deploymentOn(8453); // Use the deployment if (baseDeployment) { const address = baseDeployment.address; const chainId = baseDeployment.client.chain?.id; } Type Definitions: ModularSmartAccount: address: Hex client: SmartAccountClient entryPoint: Address factoryAddress: Address initCode: Hex DeploymentOnFunction: (chainId: number, strictMode: true): ModularSmartAccount (chainId: number, strictMode?: false): ModularSmartAccount | undefined ``` -------------------------------- ### Build Method Example: Token Bridging Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/sdk-reference/mee-client/account/methods/build.md Demonstrates how to use the `build` method to create an intent for bridging tokens from Optimism to Base. It then shows how to get a quote for this intent and execute it as a supertransaction. ```typescript import { parseUnits } from "ethers"; // Bridge tokens from Optimism to Base using an intent const bridgeIntent = await mcAccount.build({ type: "intent", data: { amount: parseUnits("5", 6), // Fixed, known amount mcToken: mcUSDC, toChain: base } }); // Execute the intent as a supertransaction const quote = await meeClient.getQuote({ instructions: [bridgeIntent], feeToken: { address: mcUSDC.addressOn(optimism.id), chainId: optimism.id } }); const { hash } = await meeClient.executeQuote({ quote }); ``` -------------------------------- ### Get Privy Embedded Wallet Instance Source: https://github.com/bcnmy/abstract-docs/blob/main/docs/pages/new/quickstart/embedded-wallets-quickstart.mdx TypeScript code snippet to retrieve the Privy embedded wallet instance from the list of available wallets after a user has logged in. ```ts const wallet = wallets.find(wallet => wallet.walletClientType === 'privy'); ``` -------------------------------- ### 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 Initializes an orchestrator account using a private key and sets up the MEE client with the orchestrator account and an API key. It supports multiple chains like Optimism and Base. ```typescript const eoa = privateKeyToAccount(PRIVATE_KEY) const orchestrator = await toMultichainNexusAccount({ chains: [optimism, base], transports: [http(), http('https://base.llamarpc.com')], signer: eoa }) const meeClient = await createMeeClient({ account: orchestrator, apiKey: 'your_mee_api_key' }) ```