/** * Create New User Account Script * * This script creates a complete new user account with AccountNFT and TBA * * Usage: * 1. Create a .env file and set the following environment variables: * - PRIVATE_KEY: Private key of the account holder * - NETWORK: Network name (optional, defaults to 'Base Sepolia') * * 2. Run the script: * npm run create-tba * or * yarn create-tba */ import { GoTakeSDK } from "../src"; import * as dotenv from 'dotenv'; import { ethers } from 'ethers'; dotenv.config(); /** * Simple preflight checks - only check balance */ async function preflightChecks(sdk: GoTakeSDK, userAddress: string): Promise { console.log('\nšŸ” Running preflight checks...'); console.log('==============================='); try { // Check ETH balance console.log('šŸ’° Checking account balance...'); const balance = await sdk.provider.getBalance(userAddress); const balanceETH = parseFloat(ethers.utils.formatEther(balance)); const minETH = 0.001; // Minimum 0.001 ETH needed console.log(` Balance: ${balanceETH.toFixed(4)} ETH`); if (balanceETH < minETH) { console.log(` āŒ Insufficient balance, at least ${minETH} ETH needed for transactions`); console.log(' šŸ’° Get test ETH: https://www.coinbase.com/faucets/base-ethereum-sepolia-faucet'); return false; } else { console.log(' āœ… ETH balance sufficient'); } console.log('\nāœ… All preflight checks passed!'); return true; } catch (error) { console.error('āŒ Preflight check failed:', error.message); return false; } } async function main() { console.log('šŸ—ļø GoTake Account Creator'); console.log('================================\n'); // Environment configuration const NETWORK = process.env.NETWORK || 'Base Sepolia'; const PRIVATE_KEY = process.env.PRIVATE_KEY; if (!PRIVATE_KEY) { console.error('āŒ Please set PRIVATE_KEY environment variable'); process.exit(1); } try { // Initialize SDK with automatic network resolution console.log(`🌐 Network: ${NETWORK}`); const sdk = new GoTakeSDK({ network: NETWORK, signer: PRIVATE_KEY }); const userAddress = await sdk.getAddress(); console.log(`šŸ‘¤ Wallet Address: ${userAddress}`); // Check wallet balance const balance = await sdk.provider.getBalance(userAddress); console.log(`šŸ’° Wallet Balance: ${ethers.utils.formatEther(balance)} ETH\n`); // Run preflight checks const preflightPassed = await preflightChecks(sdk, userAddress); if (!preflightPassed) { console.log('\nāŒ Preflight checks failed. Please resolve the issues above before continuing.'); process.exit(1); } // Get current gas price recommendations console.log('\n⛽ Getting optimal gas configuration...'); const gasPrices = await sdk.getGasPrice({ multiplier: 1.2, priorityMultiplier: 1.1 }); console.log(` Base Fee: ${gasPrices.baseFeePerGas ? ethers.utils.formatUnits(gasPrices.baseFeePerGas, "gwei") + ' gwei' : 'N/A'}`); console.log(` Max Fee: ${ethers.utils.formatUnits(gasPrices.maxFeePerGas, "gwei")} gwei`); console.log(` Priority Fee: ${gasPrices.maxPriorityFeePerGas ? ethers.utils.formatUnits(gasPrices.maxPriorityFeePerGas, "gwei") + ' gwei' : 'N/A'}`); // Transaction options with gas configuration const transactionOptions = { gasConfig: { gasLimit: 500000, maxFeePerGas: gasPrices.maxFeePerGas, maxPriorityFeePerGas: gasPrices.maxPriorityFeePerGas } }; // Create complete new user account console.log('\nšŸš€ Creating new user account...'); console.log('='.repeat(50)); const result = await sdk.account.createNewUserAccount({ recipientAddress: userAddress, accountNFTMetadata: { uri: `account://${userAddress}/metadata` }, tbaConfig: { salt: '0x0000000000000000000000000000000000000000000000000000000000000000' } }, transactionOptions); console.log('\nāœ… Account creation completed successfully!'); console.log('='.repeat(50)); // Display results console.log('\nšŸ“Š Account Creation Summary:'); console.log(` AccountNFT Token ID: ${result.accountNFT.tokenId.toString()}`); console.log(` AccountNFT Contract: ${result.accountNFT.contractAddress}`); console.log(` AccountNFT Transaction: ${result.accountNFT.tx.hash}`); console.log(` AccountNFT Owner: ${userAddress}`); console.log(`\n TBA Address: ${result.tba.tbaAddress}`); console.log(` TBA Transaction: ${result.tba.tx.hash}`); // Wait for transaction confirmations console.log('\nā³ Waiting for transaction confirmations...'); await result.accountNFT.tx.wait(); await result.tba.tx.wait(); console.log(' āœ… All transactions confirmed'); console.log(`\nšŸŽ‰ New user account setup complete!`); console.log(` Creation completed at: ${new Date().toLocaleString()}`); } catch (error) { console.error('āŒ Account creation failed:', error); console.error('Details:', error.message); process.exit(1); } } // Run the script if (require.main === module) { main().catch(console.error); }