### Setup and Run Example Minting Bot Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/guides/creating-a-minting-bot.md Navigate to the example directory, install its dependencies, copy the environment configuration, and start the bot. Ensure you fill in the necessary environment variables. ```bash pnpm install cp .env.example .env pnpm start ``` -------------------------------- ### Install Dependencies for Step-by-Step Minting Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/guides/creating-a-react-minting-app/advanced-use-cases.md Install the necessary dependencies for the step-by-step minting example. Navigate to the example directory first. ```bash cd examples/step-by-step-mint npm install ``` -------------------------------- ### Install Dependencies and Build SDK Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/guides/creating-a-minting-bot.md Install project dependencies and build the SDK before running example scripts. This is a prerequisite for executing the minting bot examples. ```bash pnpm install pnpm build ``` -------------------------------- ### Viem Client Setup Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/account-adapters/viem.md Example setup for Viem public and wallet clients. Ensure to replace 'YOUR_RPC_URL' with your actual RPC endpoint. ```typescript import { createWalletClient, createPublicClient, custom, http } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { mainnet } from 'viem/chains' // Create public client for read operations export const publicClient = createPublicClient({ chain: mainnet, transport: http('YOUR_RPC_URL') // or custom(window.ethereum) for browser }) // Create wallet client for transactions const account = privateKeyToAccount('0x...') export const walletClient = createWalletClient({ account, chain: mainnet, transport: custom(window.ethereum) }) ``` -------------------------------- ### Install Dependencies Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/edition/step-by-step-mint/README.md Install the necessary Node.js dependencies for the example project. Ensure you have Node.js 18+ installed. ```bash cd examples/edition/step-by-step-mint npm install ``` -------------------------------- ### Quick Start: Minting an Edition Product Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/getting-started.md This example demonstrates how to initialize the Manifold client, fetch an Edition product, and execute a purchase using Wagmi for wallet connection and transaction handling. Replace 'YOUR_RPC_URL' with your actual RPC endpoint. ```typescript import { createClient, EditionProduct, createPublicProviderWagmi, createAccountViem } from '@manifoldxyz/client-sdk'; import { createConfig, http, getAccount, getWalletClient } from '@wagmi/core'; import { mainnet } from '@wagmi/core/chains'; // Create Wagmi config const config = createConfig({ chains: [mainnet], transports: { [mainnet.id]: http('YOUR_RPC_URL'), // or http() for public RPC }, }); // Initialize the Manifold client const client = createClient({ publicProvider:createPublicProviderWagmi({ config }) }); // Fetch product const product = await client.getProduct('4150231280') as EditionProduct; // Get connected account from Wagmi const account = getAccount(config); if (!account.address) throw new Error('No wallet connected'); // Prepare purchase const prepared = await product.preparePurchase({ address: account.address, payload: { quantity: 1 }, }); // Get wallet client and create account adapter const walletClient = await getWalletClient(config); // Execute purchase const order = await product.purchase({ account: createAccountViem({ walletClient }), preparedPurchase: prepared, }); const txHash = order.receipts[0]?.txHash; console.log(`Edition purchase transaction: ${txHash}`); ``` -------------------------------- ### Setup Minting Bot Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/README.md Follow these instructions to set up an automated minting script for backend operations. Ensure you copy the environment example file. ```bash cd examples/[edition|blindmint]/minting-bot npm install cp .env.example .env npm run start ``` -------------------------------- ### Basic Minting Bot Example Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/guides/creating-a-minting-bot.md This TypeScript example demonstrates how to set up the Manifold SDK client, retrieve a product, check its status, and perform a purchase. It includes wallet setup and basic error handling for the transaction. ```typescript import { createClient, createAccountEthers5, createPublicProviderEthers5, isBlindMintProduct, isEditionProduct, } from '@manifoldxyz/client-sdk'; import { ethers } from 'ethers'; // Setup provider for the network const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL!); const networkId = Number(process.env.NETWORK_ID!); // e.g., 1 for mainnet, 8453 for Base // Create public provider for the client const publicProvider = createPublicProviderEthers5({ [networkId]: provider }); // Initialize the client const client = createClient({ publicProvider }); const product = await client.getProduct('INSTANCE_ID'); // Check product status first const productStatus = await product.getStatus(); if (productStatus !== 'active') { throw new Error(`Product is ${productStatus}`); } // Handle different product types if (!isEditionProduct(product)) { throw new Error('Unsupported product type'); } // Setup wallet for signing transactions const wallet = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY!, provider); const account = createAccountEthers5({ wallet }); try { const prepared = await product.preparePurchase({ recipientAddress: wallet.address, payload: { quantity: 1 }, }); const order = await product.purchase({ account, preparedPurchase: prepared, }); console.log( order.status, order.receipts.map((r) => r.txHash), ); } catch (error) { console.log(`Unable to execute transaction: ${(error as Error).message}`); } ``` -------------------------------- ### Install Dependencies and Configure Environment Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/blindmint/step-by-step-mint/README.md Installs project dependencies and copies the environment file. Configure your API keys and instance ID in the .env file. ```bash cd examples/step-by-step-mint npm install cp .env.example .env ``` -------------------------------- ### Install Workspace Dependencies Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/edition/minting-bot/README.md Installs and builds the SDK for local development. Ensure you are in the repository root. ```bash pnpm install pnpm --filter @manifoldxyz/client-sdk build ``` -------------------------------- ### Setup Step-by-Step Transaction Flow Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/README.md Execute these commands to set up a project demonstrating transparent minting with explicit transaction control. ```bash cd examples/[blindmint|edition]/step-by-step-mint npm install npm run dev ``` -------------------------------- ### Install Dependencies Source: https://github.com/manifoldxyz/client-sdk/blob/main/CONTRIBUTING.md Install all necessary project dependencies using pnpm. ```bash pnpm install ``` -------------------------------- ### Run Basic Minting Bot Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/edition/minting-bot/README.md Executes the basic minting bot example. This example loads environment variables, creates a Manifold client, fetches product details, prepares the purchase, and executes the purchase using the SDK's automatic transaction handling. ```bash pnpm --filter @manifoldxyz/example-edition-minting-bot run start ``` -------------------------------- ### Install Playground Dependencies Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/playground/README.md Navigate to the playground directory and install necessary npm packages. ```bash cd playground npm install ``` -------------------------------- ### Install Dependencies Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/blindmint/minting-bot/README.md Install project dependencies before running the bot. This command should be executed in the project directory. ```bash npm install ``` -------------------------------- ### Setup RainbowKit Integration Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/README.md Run these commands to set up a Next.js application with RainbowKit for wallet connection and one-click minting. ```bash cd examples/[blindmint|edition]/rainbowkit-mint npm install npm run dev ``` -------------------------------- ### Start the Server Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/x402/express/README.md Starts the Express server. The server will be accessible at http://localhost:4022. ```bash pnpm run start ``` -------------------------------- ### Build SDK Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/blindmint/minting-bot/README.md Build the SDK from the repository root to ensure local `dist/` output is up to date. This is a prerequisite for running the example. ```bash npm install npm run build ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/edition/rainbowkit-mint/README.md Copy the example environment file and update it with your specific project details, including WalletConnect Project ID, RPC URLs, and your Edition product instance ID. ```bash cp .env.example .env.local ``` ```env NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_project_id NEXT_PUBLIC_RPC_URL_MAINNET=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY NEXT_PUBLIC_RPC_URL_BASE=https://base-mainnet.infura.io/v3/YOUR_KEY NEXT_PUBLIC_INSTANCE_ID=your_edition_instance_id ``` -------------------------------- ### Copy Environment Variables Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/blindmint/rainbowkit-mint/README.md Copy the example environment file to a local file to configure your project settings. ```bash cp .env.example .env.local ``` -------------------------------- ### Create Environment Variables Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/guides/creating-a-react-minting-app/README.md Copy the example environment file and fill in your specific project details, such as WalletConnect Project ID, Edition Instance ID, and RPC URL. ```bash cp .env.example \ env.local ``` -------------------------------- ### Launch the Development Server Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/guides/creating-a-react-minting-app/README.md Start the local development server to view your React minting app at http://localhost:3000. ```bash pnpm dev ``` -------------------------------- ### Clone and Install Manifold SDK Source: https://github.com/manifoldxyz/client-sdk/blob/main/README.md Clone the repository, navigate to the directory, and install dependencies using pnpm. ```bash git clone https://github.com/manifoldxyz/client-sdk.git cd client-sdk pnpm install pnpm build ``` -------------------------------- ### Run Local Development Server Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/guides/creating-a-react-minting-app/advanced-use-cases.md Start the local development server to test your minting application. ```bash npm run dev ``` -------------------------------- ### Run Custom Transaction Execution Example Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/edition/minting-bot/README.md Executes the custom transaction execution example. This example demonstrates how to extract raw transaction data from the SDK and use viem's sendTransaction for direct execution, offering full control over the transaction lifecycle, gas management, and receipt handling. ```bash pnpm --filter @manifoldxyz/example-edition-minting-bot run start:custom ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/blindmint/minting-bot/README.md Copy the example environment file and populate it with your specific settings for the minting bot. Ensure all required variables are provided. ```bash cp .env.example .env ``` -------------------------------- ### Install Manifold Client SDK Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/getting-started.md Install the SDK using npm. Ensure you have Node.js 18.0.0 or higher. ```bash npm install @manifoldxyz/client-sdk ``` -------------------------------- ### Run SDK Playground Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/README.md Start the interactive playground to test SDK functionalities. ```bash pnpm run playground ``` -------------------------------- ### Execute Command on Filtered Examples Source: https://github.com/manifoldxyz/client-sdk/blob/main/README.md Run a specific command on all packages within the examples directory using pnpm --filter and exec. ```bash pnpm --filter @manifoldxyz/examples exec ``` -------------------------------- ### Step-by-Step Purchase Flow Example Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/blindmint/step-by-step-mint/README.md Execute minting steps manually for more control or to update the UI between steps. This is useful for providing granular feedback to the user. ```typescript for (const step of preparedPurchase.steps) { await step.execute(account); // Update UI between steps } ``` -------------------------------- ### Simulate Purchase and Get Transaction Steps Source: https://context7.com/manifoldxyz/client-sdk/llms.txt Use `product.preparePurchase` to validate eligibility, estimate gas, and get transaction steps for a purchase. Handles common errors like sold-out or not-eligible via `ClientSDKError`. ```typescript import { createClient, createPublicProviderViem, isEditionProduct, ClientSDKError, } from '@manifoldxyz/client-sdk'; import { createPublicClient, http } from 'viem'; import { mainnet } from 'viem/chains'; const publicProvider = createPublicProviderViem({ 1: createPublicClient({ chain: mainnet, transport: http() }), }); const client = createClient({ publicProvider }); const product = await client.getProduct('4150231280'); if (!isEditionProduct(product)) throw new Error('Expected Edition product'); try { const preparedPurchase = await product.preparePurchase({ userAddress: '0xBuyerWalletAddress', recipientAddress: '0xRecipientAddress', // optional: different recipient payload: { quantity: 2 }, gasBuffer: { multiplier: 120 }, // 20% extra gas buffer }); console.log('Total cost:', preparedPurchase.cost.total.formatted); // e.g., "0.10 ETH" console.log('Steps required:', preparedPurchase.steps.length); // 1 step = just mint; 2 steps = ERC-20 approval + mint } catch (error) { const sdkError = error as ClientSDKError; // Possible codes: NOT_ELIGIBLE, SOLD_OUT, LIMIT_REACHED, ENDED, NOT_STARTED, ESTIMATION_FAILED console.error(`Purchase blocked [${sdkError.code}]: ${sdkError.message}`); } ``` -------------------------------- ### Install SDK Package Dependencies Source: https://github.com/manifoldxyz/client-sdk/blob/main/CLAUDE.md Installs dependencies specifically for the `@manifoldxyz/client-sdk` package. ```bash pnpm --filter @manifoldxyz/client-sdk install ``` -------------------------------- ### Viem Public Provider for Browser Usage Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/public-provider-adapters/viem.md Integrate with browser-based wallets like MetaMask. This example uses `window.ethereum` to create a public client. ```typescript import { createPublicProviderViem } from '@manifoldxyz/client-sdk'; import { createPublicClient, custom } from 'viem'; import { mainnet } from 'viem/chains'; // Use the browser's injected provider const publicClient = createPublicClient({ chain: mainnet, transport: custom(window.ethereum) }); const publicProvider = createPublicProviderViem({ 1: publicClient }); const client = createClient({ publicProvider }); ``` -------------------------------- ### Complete Example: Custom Transaction Execution with Viem Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/transaction-steps/transactionData.md Demonstrates preparing a purchase with the Manifold SDK, extracting transaction data, and executing each step using custom logic and parameters with Viem. ```typescript import { createClient, createPublicProviderViem, isEditionProduct } from '@manifoldxyz/client-sdk'; import { createWalletClient, createPublicClient, http, type Hex, type Address } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; import { sepolia } from 'viem/chains'; async function customMint() { // Step 1: Prepare the purchase using Manifold SDK const manifoldPublicClient = createPublicClient({ chain: sepolia, transport: http(), }); const publicProvider = createPublicProviderViem({ [sepolia.id]: manifoldPublicClient }); const client = createClient({ publicProvider }); const product = await client.getProduct('4133757168'); if (!isEditionProduct(product)) { throw new Error('Not an Edition product'); } // Prepare purchase for wallet address const preparedPurchase = await product.preparePurchase({ userAddress: '0xYourWalletAddress', payload: { quantity: 1 }, }); // Step 2: Extract transaction data from steps console.log(`Total steps: ${preparedPurchase.steps.length}`); for (const step of preparedPurchase.steps) { console.log(`Step: ${step.name} (${step.type})`); console.log(` Contract: ${step.transactionData.contractAddress}`); console.log(` Value: ${step.transactionData.value} wei`); console.log(` Gas estimate: ${step.transactionData.gasEstimate}`); console.log(` Network: Chain ID ${step.transactionData.networkId}`); } // Step 3: Execute using custom logic with viem const account = privateKeyToAccount('0xYourPrivateKey'); const walletClient = createWalletClient({ account, chain: sepolia, transport: http(), }); const publicClient = createPublicClient({ chain: sepolia, transport: http(), }); // Execute each step with custom parameters for (const step of preparedPurchase.steps) { const { contractAddress, transactionData, value, gasEstimate } = step.transactionData; // Custom gas management - 10% buffer instead of default 20% const customGasLimit = (BigInt(gasEstimate) * 110n) / 100n; console.log(`Executing ${step.name}...`); // Send transaction with custom parameters const txHash = await walletClient.sendTransaction({ to: contractAddress as Address, data: transactionData as Hex, value: value ? BigInt(value) : 0n, gas: customGasLimit, // Add custom parameters: // maxFeePerGas: ..., // maxPriorityFeePerGas: ..., // nonce: ..., }); console.log(`Transaction hash: ${txHash}`); // Wait for confirmation const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash, // Optional: custom confirmation blocks // confirmations: 2, }); console.log(`Status: ${receipt.status}`); console.log( `Gas used: ${receipt.gasUsed} (${(receipt.gasUsed * 100n) / customGasLimit}% of limit)`, ); } } ``` -------------------------------- ### Configure Environment Variables for Minting App Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/guides/creating-a-react-minting-app/advanced-use-cases.md Set up your environment variables by copying the example file and providing your Manifold Studio instance ID and WalletConnect project ID. ```bash NEXT_PUBLIC_INSTANCE_ID= # You blind mint instance ID from Manifold Studio NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID= # Get one at https://dashboard.reown.com/sign-in ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/edition/step-by-step-mint/README.md Copy the example environment file and configure your Manifold Studio instance ID, Alchemy API key, and WalletConnect Project ID. ```bash cp .env.example .env ``` ```env NEXT_PUBLIC_ALCHEMY_API_KEY=your_alchemy_api_key NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_walletconnect_project_id NEXT_PUBLIC_INSTANCE_ID=your_edition_instance_id ``` -------------------------------- ### Prepare Purchase and Get Steps Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/edition/step-by-step-mint/README.md Initiates the purchase process by calling `preparePurchase` on the product object. This returns a `PreparedPurchase` object containing transaction steps, cost breakdown, and eligibility information. ```typescript // Prepare purchase and get steps const prepared = await product.preparePurchase({ address, payload: { quantity }, }); // Store steps for modal display setPreparedPurchase(prepared); setIsModalOpen(true); ``` -------------------------------- ### Initialize Manifold Client with Viem Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/account-adapters/README.md This snippet demonstrates how to initialize the Manifold client using Viem for both public provider and account creation. Ensure you have Viem installed and configured with your RPC URL. ```typescript import { createClient, createPublicProviderViem, createAccountViem } from '@manifoldxyz/client-sdk'; import { createPublicClient, createWalletClient, http } from 'viem'; import { mainnet } from 'viem/chains'; // 1. Create public provider for blockchain reads const publicClient = createPublicClient({ chain: mainnet, transport: http('YOUR_RPC_URL') }); const publicProvider = createPublicProviderViem({ 1: publicClient }); // 2. Initialize Manifold client const client = createClient({ publicProvider }); // 3. Create account for transactions (when needed) const walletClient = createWalletClient({ /* ... */ }); const account = createAccountViem({ walletClient }); ``` -------------------------------- ### Run the Minting Bot Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/blindmint/minting-bot/README.md Execute the minting bot to start the blind minting process. This command initiates the script that performs the mint. ```bash npm run start ``` -------------------------------- ### Prepare Purchase and Get Transaction Steps Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/blindmint/step-by-step-mint/README.md Initiates the purchase process by calling `preparePurchase` to obtain transaction steps and cost details. This should be called before displaying the minting modal. ```typescript const prepared = await product.preparePurchase({ address, payload: { quantity }, }); setPreparedPurchase(prepared); setIsModalOpen(true); ``` -------------------------------- ### Minting an Edition Product Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/edition/rainbowkit-mint/README.md Follow this flow to mint an edition product: get the product, verify its type, check its status, prepare the purchase with quantity and optional promo code, and finally execute the purchase. ```typescript import { isEditionProduct } from '@manifoldxyz/client-sdk'; // 1. Get product const product = await client.getProduct(INSTANCE_ID); // 2. Verify it's an Edition product if (!isEditionProduct(product)) { throw new Error('Product is not an Edition type'); } // 3. Check product status const productStatus = await product.getStatus(); if (productStatus !== 'active') { throw new Error(`Edition product is ${productStatus}`); } // 4. Prepare purchase with Edition-specific payload const preparedPurchase = await product.preparePurchase({ address: address, payload: { quantity: 1, // Optional: promo code for discounts // code: 'PROMO_CODE' } }); // 5. Execute purchase const order = await product.purchase({ account, preparedPurchase, }); ``` -------------------------------- ### Create Viem Public Provider with Fallback Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/public-provider-adapters/viem.md Configure fallback providers for enhanced reliability. This setup is used when the primary provider fails or is on the wrong network. ```typescript import { createPublicProviderViem } from '@manifoldxyz/client-sdk'; import { createPublicClient, http } from 'viem'; import { mainnet, base } from 'viem/chains'; // Providers with fallback (used when primary fails or is on wrong network) const publicClients = { 1: [ createPublicClient({ chain: mainnet, transport: http('PRIMARY_MAINNET_RPC_URL') }), createPublicClient({ chain: mainnet, transport: http('FALLBACK_MAINNET_RPC_URL') }) ] }; // Create the public provider with fallback support const publicProvider = createPublicProviderViem(publicClients); // Use with Manifold client const client = createClient({ publicProvider }); ``` -------------------------------- ### Create Manifold Client with Viem Provider Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/manifold-client/README.md Initializes the Manifold client using a public provider configured with Viem. This example shows how to set up Viem clients for different networks. ```typescript import { createClient, createPublicProviderViem } from '@manifoldxyz/client-sdk'; import { createPublicClient, http } from 'viem'; import { mainnet } from 'viem/chains'; // Create public clients for each network you want to support const publicClient = createPublicClient({ chain: mainnet, transport: http('YOUR_RPC_URL') }); // Create the public provider const publicProvider = createPublicProviderViem({ 1: publicClient // mainnet }); // Initialize the Manifold client const client = createClient({ publicProvider }); ``` -------------------------------- ### Prepare Blind Mint Purchase - JavaScript Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/product/blind-mint/preparepurchase.md Simulates a blind mint purchase to check eligibility and get the total cost. Ensure the product is a blind mint product and handle potential errors during the simulation. ```javascript import { createClient, createPublicProviderViem, isBlindMintProduct } from '@manifoldxyz/client-sdk' import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const publicClient = createPublicClient({ chain: mainnet, transport: http(), }) const publicProvider = createPublicProviderViem({ 1: publicClient }) const client = createClient({ publicProvider }); const product = await client.getProduct('12311232') if (!isBlindMintProduct(product)) { throw new Error(`Unsupported app type`) } try { const preparedPurchase = await product.preparePurchase({ userAddress: '0x....', // the connected wallet payload: { quantity: 1 }, gasBuffer: { multiplier: 0.25 // 25% gas buffer } }); } catch (error: ClientSDKError) { console.log(`Error: ${error.message}`) return } console.log('Total cost:', preparedPurchase.cost.total.formatted); ``` -------------------------------- ### Conventional Commit Examples Source: https://github.com/manifoldxyz/client-sdk/blob/main/CONTRIBUTING.md Examples of commit messages following the conventional commits format. Use 'feat' for new features and 'fix' for bug fixes. ```bash feat(sdk): add support for new product type fix(edition): resolve purchase validation issue ``` -------------------------------- ### Build the Client SDK Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/README.md Compile the client SDK project. ```bash pnpm run build ``` -------------------------------- ### Install Latest LTS Node.js with NVM Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/getting-started.md If your Node.js version is below 18.0.0, use a version manager like nvm to install the latest Long Term Support (LTS) version. ```bash nvm install --lts nvm use --lts ``` -------------------------------- ### Build the Project Source: https://github.com/manifoldxyz/client-sdk/blob/main/CONTRIBUTING.md Compile the project's code. ```bash pnpm build ``` -------------------------------- ### Get Payment Requirements (402 Response) Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/x402/express/README.md This GET request to the purchase endpoint initiates the payment process by returning a 402 Payment Required response. It details the payment scheme, required amount, and accepted assets for the NFT purchase. ```http GET /manifold/base-sepolia/id/4150231280/purchase?quantity=1&userAddress=0x... { "x402Version": 1, "accepts": [ { "scheme": "exact", "network": "base-sepolia", "maxAmountRequired": "1000000", "resource": "http://localhost:4022/manifold/base-sepolia/id/4150231280/purchase", "description": "NFT Purchase: Cool NFT", "mimeType": "application/json", "payTo": "0xAdminWallet", "maxTimeoutSeconds": 300, "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e", "extra": { "name": "USDC", "version": "2", "productId": "4150231280", "quantity": 1 } } ] } ``` -------------------------------- ### Get Product Status Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/product/common/getstatus.md Retrieves the current status of the product. The status can be 'active', 'upcoming', 'sold-out', or 'ended'. ```typescript const status = await product.getStatus(); console.log(`Current product status ${status}`) ``` -------------------------------- ### getRules() Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/product/common/getrules.md Retrieves the product rules, such as start and end dates, maximum tokens per wallet, audience restrictions, and more. ```APIDOC ## getRules() ### Description Retrieves the product rules, such as start and end dates, maximum tokens per wallet, audience restrictions, and more. ### Method SDK Method ### Returns #### ProductRule - **startDate** (Date) - Optional - Start date (if not provided, start immediately) - **endDate** (Date) - Optional - End date (if not provided, the product never ends) - **audienceRestriction** (enum) - Required - allowlist | none - **maxPerWallet** (number) - Optional - Number of allowed purchased per wallet #### AudienceRestriction Enum - `allowlist`: The product is restricted to specific wallet addresses. - `none`: The product has no audience restrictions. ``` -------------------------------- ### Get Step Description Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/edition/step-by-step-mint/README.md Provides a user-friendly description for each transaction step type. Customize these descriptions for better clarity in the UI. ```typescript const getStepDescription = (step: TransactionStep) => { switch (step.type) { case 'approval': return 'Approve the contract to spend tokens'; case 'mint': return 'Execute the Edition mint transaction'; default: return step.description; } }; ``` -------------------------------- ### Get User-Friendly Step Description Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/blindmint/step-by-step-mint/README.md Provides a human-readable description for each transaction step type, enhancing user understanding during the minting process. ```typescript const getStepDescription = (step: TransactionStep) => { switch (step.type) { case 'approval': return 'Approve the contract to spend tokens'; case 'mint': return 'Execute the blind mint transaction'; default: return step.description; } }; ``` -------------------------------- ### Prepare Purchase with Manifold SDK Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/transaction-steps/transactionData.md Shows how to initiate a purchase using the Manifold SDK to obtain prepared transaction steps. ```typescript const preparedPurchase = await product.preparePurchase({ userAddress: walletAddress, payload: { quantity: 1 }, }); ``` -------------------------------- ### Client Creation Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/README.md Creates a new SDK client instance with configuration options. ```APIDOC ## createClient(config) ### Description Creates a new SDK client instance. ### Parameters - `config` (object, required): Configuration options - `publicProvider` (IPublicProvider, required): Provider for blockchain interactions - `debug` (boolean, optional): Enable debug logging ### Example ```typescript import { createClient, createPublicProviderWagmi } from '@manifoldxyz/client-sdk'; import { createConfig, http } from '@wagmi/core'; import { mainnet, base } from '@wagmi/core/chains'; // Setup Wagmi config const config = createConfig({ chains: [mainnet, base], transports: { [mainnet.id]: http(), [base.id]: http(), }, }); // Create public provider const publicProvider = createPublicProviderWagmi({ config }); // Create client const client = createClient({ publicProvider }); // With debug logging const client = createClient({ publicProvider, debug: true }); ``` ``` -------------------------------- ### preparePurchase Method Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/product/blind-mint/preparepurchase.md Simulates a purchase to check eligibility and get the total cost. This method is part of the Blind Mint Product interface. ```APIDOC ## preparePurchase(params) ### Description Simulates purchase to check eligibility and get total cost. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **userAddress** (string) - Required - The address making the purchase - **recipientAddress** (string) - Optional - If different than `address` - **networkId** (number) - Optional - If specified, forces transaction on the network (handles funds bridging automatically), assumes product network otherwise. - **payload** (object) - Required - Specific to Blind Mint Products. Specify quantity of purchase. - **quantity** (number) - Required - The number of items to purchase. - **gasBuffer** (object) - Optional - How much additional gas to spend on the purchase. - **fixed** (BigInt) - Optional - Fixed gas buffer amount. - **multiplier** (number) - Optional - Gas buffer by multiplier. The multiplier represents a percentage (as a number out of 100). For example: multiplier: 120 means 120% of the original estimate (20% increase). - **account** (Account) - Optional - If provided, it will perform balance checks on the specified account; otherwise, it will skip balance checks. ### Returns - [PreparedPurchase](../../../reference/preparedpurchase.md) ### Example ```jsx import { createClient, createPublicProviderViem, isBlindMintProduct } from '@manifoldxyz/client-sdk' import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const publicClient = createPublicClient({ chain: mainnet, transport: http(), }) const publicProvider = createPublicProviderViem({ 1: publicClient }) const client = createClient({ publicProvider }); const product = await client.getProduct('12311232') if (!isBlindMintProduct(product)) { throw new Error(`Unsupported app type`) } try { const preparedPurchase = await product.preparePurchase({ userAddress: '0x....', // the connected wallet payload: { quantity: 1 }, gasBuffer: { multiplier: 0.25 // 25% gas buffer } }); } catch (error: ClientSDKError) { console.log(`Error: ${error.message}`) return } console.log('Total cost:', preparedPurchase.cost.total.formatted); ``` ### Errors - **INVALID_INPUT**: `invalid input` - **UNSUPPORTED_NETWORK**: `unsupported networkId ${networkId}` - **SOLD_OUT**: `product sold out` - **LIMIT_REACHED**: `you've reached your purchase limit` - **ENDED**: `ended` - **NOT_STARTED**: `not started, come back later` - **ESTIMATION_FAILED**: `transaction estimation failed` ``` -------------------------------- ### Get Product Status Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/product/common/getstatus.md Retrieves the current status of the product. The status indicates whether the product is active, upcoming, sold out, or has ended. ```APIDOC ## getStatus() ### Description Retrieves the current status of the product. ### Method ```typescript getStatus(): Promise<'active' | 'upcoming' | 'sold-out' | 'ended'> ``` ### Returns: - **active**: The product is currently active and available for purchase. - **upcoming**: The product sale has not started yet. - **sold-out**: The product is sold out. - **ended**: The product sale has ended. ### Example ```jsx const status = await product.getStatus(); console.log(`Current product status ${status}`); ``` ``` -------------------------------- ### Lint the Client SDK Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/README.md Run the linter to check for code style and potential issues. ```bash pnpm run lint ``` -------------------------------- ### Axios Instance with Payment Interceptor Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/x402/express/playground-react/README.md Demonstrates how to create an axios instance configured with the x402-axios payment interceptor for automatic handling of x402 payment requirements. Ensure you have a wagmi wallet client available. ```javascript // Get wallet client from wagmi const { data: walletClient } = useWalletClient(); // Create axios instance with payment interceptor const api = withPaymentInterceptor( axios.create({ baseURL: serverUrl }), walletClient // wagmi wallet client ); // Make request - payment is handled automatically const response = await api.get('/manifold/base-sepolia/id/123/purchase'); ``` -------------------------------- ### Create Viem Wallet Client with Private Key Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/README.md Instantiate a Viem wallet client using a private key for programmatic access. ```typescript import { createWalletClient, http } from 'viem'; import { mainnet } from 'viem/chains'; import { privateKeyToAccount } from 'viem/accounts'; import { createAccountViem } from '@manifoldxyz/client-sdk'; // Using private key const viemAccount = privateKeyToAccount('0x...'); const walletClient = createWalletClient({ account: viemAccount, chain: mainnet, transport: http(), }); const account = createAccountViem({ walletClient }); ``` -------------------------------- ### Environment Variables Configuration Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/examples/README.md Common environment variables required for Manifold SDK examples, including instance IDs, RPC endpoints, and wallet private keys. ```env # Product Configuration INSTANCE_ID=your_product_instance_id NEXT_PUBLIC_INSTANCE_ID=your_product_instance_id # RPC Endpoints MAINNET_RPC=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY BASE_RPC=https://base-mainnet.g.alchemy.com/v2/YOUR_KEY # Wallet (server-side only) WALLET_PRIVATE_KEY=your_private_key # Optional MINT_QUANTITY=1 ``` -------------------------------- ### Fetch Product Sale Rules Source: https://context7.com/manifoldxyz/client-sdk/llms.txt Retrieves the sale configuration rules for a product, including start and end dates, purchase limits per wallet, and audience restrictions. ```typescript const product = await client.getProduct('4150231280'); const rules = await product.getRules(); console.log('Start:', rules.startDate?.toLocaleString() ?? 'Immediately'); console.log('End:', rules.endDate?.toLocaleString() ?? 'Never'); console.log('Max per wallet:', rules.maxPerWallet ?? 'Unlimited'); console.log('Audience:', rules.audienceRestriction); // 'allowlist' | 'none' if (rules.audienceRestriction === 'allowlist') { console.log('This is an allowlist-gated drop'); } ``` -------------------------------- ### Initialize SDK Client with Wagmi Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/README.md Import and initialize the SDK client using Wagmi for blockchain interactions. Requires setting up a Wagmi config and creating a public provider. ```typescript import { createClient, createPublicProviderWagmi } from '@manifoldxyz/client-sdk'; import { createConfig, http } from '@wagmi/core'; import { mainnet, base } from '@wagmi/core/chains'; // Create Wagmi config const config = createConfig({ chains: [mainnet, base], transports: { [mainnet.id]: http(), [base.id]: http(), }, }); // Create public provider const publicProvider = createPublicProviderWagmi({ config }); // Initialize the SDK client const client = createClient({ publicProvider }); ``` -------------------------------- ### Create Multi-Network Public Provider with Viem Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/public-provider-adapters/README.md Initialize a public provider that supports multiple networks simultaneously by providing a Viem client for each desired network. The SDK automatically selects the appropriate provider based on the product's network. ```typescript const publicProvider = createPublicProviderViem({ 1: mainnetClient, // Ethereum Mainnet 8453: baseClient, // Base 10: optimismClient, // Optimism 360: shapeClient, // Shape 11155111: sepoliaClient // Sepolia Testnet }); ``` -------------------------------- ### Initiate a Product Purchase Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/sdk/product/common/purchase.md Use this snippet to initiate a purchase for a product. Ensure you have a preparedPurchase object from a prior preparePurchase call. This method may trigger multiple write transactions. ```typescript const receipt = await product.purchase({ account, preparedPurchase, }); console.log('Mint transaction:', receipt.transactionReceipt.txHash); if (receipt.order) { console.log('Recipient:', receipt.order.recipientAddress); for (const item of receipt.order.items) { console.log(`Minted token ${item.token.tokenId} x${item.quantity}`); } } ``` -------------------------------- ### Run Interactive SDK Playground Source: https://github.com/manifoldxyz/client-sdk/blob/main/CLAUDE.md Launches the interactive playground for the `@manifoldxyz/client-sdk` package, allowing for real-time testing of SDK functionalities. ```bash pnpm --filter @manifoldxyz/client-sdk run playground ``` -------------------------------- ### Prepare Purchase for Edition Product Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/docs/guides/creating-a-react-minting-app/README.md Prepare the purchase by specifying the desired quantity and the user's address. This step performs eligibility checks and calculates the total cost. ```typescript const preparedPurchase = await product.preparePurchase({ address: address, payload: { quantity: 1, }, }); ``` -------------------------------- ### Create Viem Wallet Client for Browser Source: https://github.com/manifoldxyz/client-sdk/blob/main/packages/client-sdk/README.md Instantiate a Viem wallet client using a browser-provided Ethereum provider like MetaMask. ```typescript import { createWalletClient, custom, http } from 'viem'; import { mainnet } from 'viem/chains'; import { createAccountViem } from '@manifoldxyz/client-sdk'; // Using browser wallet (MetaMask, etc.) const walletClient = createWalletClient({ chain: mainnet, transport: custom(window.ethereum), }); const account = createAccountViem({ walletClient }); ``` -------------------------------- ### Run Tests Source: https://github.com/manifoldxyz/client-sdk/blob/main/CONTRIBUTING.md Execute the project's test suite. ```bash pnpm test ```