sal/examples/hero_vault/agung_simple_transfer.rhai
Sameh Abouelsaad f669bdb84f
Some checks failed
Rhai Tests / Run Rhai Tests (push) Has been cancelled
Support conatrcts call args in rhai bindings
2025-05-10 00:42:21 +03:00

69 lines
2.8 KiB
Plaintext

// Example Rhai script for testing a simple ETH transfer on Agung network
// This script demonstrates how to use send_eth with the private key
// Step 1: Set up wallet and network
let space_name = "agung_simple_transfer_demo";
let password = "secure_password123";
let private_key = "0xf3976cfd4e0705cf90014f18140c14850bee210d4d609d49eb84eecc36fc5f38";
let network_name = "agung";
print("=== Testing Simple ETH Transfer on Agung Network ===\n");
// Create a key space
print("Creating key space: " + space_name);
if create_key_space(space_name, password) {
print("✓ Key space created successfully");
// Create a keypair
print("\nCreating keypair...");
if create_keypair("transfer_key", password) {
print("✓ Created contract keypair");
// Create a wallet from the private key for the Agung network
print("\nCreating wallet from private key for Agung network...");
if create_wallet_from_private_key_for_network(private_key, network_name) {
print("✓ Wallet created successfully");
// Get the wallet address
let wallet_address = get_wallet_address_for_network(network_name);
print("Wallet address: " + wallet_address);
// Check wallet balance
print("\nChecking wallet balance...");
let balance = get_balance(network_name, wallet_address);
if balance != "" {
print("Wallet balance: " + balance + " wei");
// Define a recipient address for the transfer
// Using a random valid address on the network
let recipient = "0x7267B587E4416537060C6bF0B06f6Fd421106650";
let amount = "1000000000000000"; // 0.001 ETH
print("\nAttempting to transfer " + amount + " wei to " + recipient);
// Send ETH
let tx_hash = send_eth(network_name, recipient, amount);
if tx_hash != "" {
print("✓ Transaction sent successfully");
print("Transaction hash: " + tx_hash);
print("You can view the transaction at: " + get_network_explorer_url(network_name) + "/tx/" + tx_hash);
} else {
print("✗ Failed to send transaction");
print("This could be due to insufficient funds or other errors.");
}
} else {
print("✗ Failed to get wallet balance");
}
} else {
print("✗ Failed to create wallet from private key");
}
} else {
print("✗ Failed to create keypair");
}
} else {
print("✗ Failed to create key space");
}
print("\nSimple transfer test completed");