// Script to create an Ethereum wallet from a private key and send tokens on the Agung network // This script demonstrates how to create a wallet from a private key and send tokens // Define the private key and recipient address let private_key = "51c194d20bcd25360a3aa94426b3b60f738007e42f22e1bc97821c65c353e6d2"; let recipient_address = "0xf400f9c3F7317e19523a5DB698Ce67e7a7E083e2"; print("=== Agung Wallet Transaction Demo ==="); print(`From private key: ${private_key}`); print(`To address: ${recipient_address}`); // First, create a key space and keypair (required for the wallet infrastructure) let space_name = "agung_transaction_demo"; let password = "demo_password"; // Create a new key space if !create_key_space(space_name, password) { print("Failed to create key space"); return; } // Create a keypair if !create_keypair("demo_keypair", password) { print("Failed to create keypair"); return; } // Select the keypair if !select_keypair("demo_keypair") { print("Failed to select keypair"); return; } print("\nCreated and selected keypair successfully"); // Clear any existing Ethereum wallets to avoid conflicts if clear_ethereum_wallets() { print("Cleared existing Ethereum wallets"); } else { print("Failed to clear existing Ethereum wallets"); return; } // Create a wallet from the private key directly print("\n=== Creating Wallet from Private Key ==="); // Create a wallet from the private key (works for any network) if create_ethereum_wallet_from_private_key(private_key) { print("Successfully created wallet from private key"); // Get the wallet address let wallet_address = get_ethereum_address(); print(`Wallet address: ${wallet_address}`); // Create a provider for the Agung network let provider_id = create_provider("agung"); if provider_id != "" { print("Successfully created Agung provider"); // Check the wallet balance first let wallet_address = get_ethereum_address(); let balance_wei = get_balance("agung", wallet_address); if balance_wei == "" { print("Failed to get wallet balance"); print("This could be due to network issues or other errors."); return; } print(`Current wallet balance: ${balance_wei}`); // Convert 1 AGNG to wei (1 AGNG = 10^18 wei) // Use string representation for large numbers let amount_wei_str = "1000000000000000000"; // 1 AGNG in wei as a string // For this example, we'll assume we have enough balance // NOTE: In a real application, you would need to check the balance properly // by parsing it and comparing with the amount. if false { // Disabled check since balance format has changed print(`Insufficient balance to send ${amount_wei_str} wei (1 AGNG)`); print(`Current balance: ${balance_wei}`); print("Please fund the wallet before attempting to send a transaction"); return; } print(`Attempting to send ${amount_wei_str} wei (1 AGNG) to ${recipient_address}`); // Send the transaction using the blocking implementation let tx_hash = send_eth("agung", recipient_address, amount_wei_str); if tx_hash != "" { print(`Transaction sent with hash: ${tx_hash}`); print(`You can view the transaction at: ${get_network_explorer_url("agung")}/tx/${tx_hash}`); } else { print("Transaction failed"); print("This could be due to insufficient funds, network issues, or other errors."); print("Check the logs for more details."); } } else { print("Failed to create Agung provider"); } } else { print("Failed to create wallet from private key"); } print("\nAgung transaction demo completed");