diff --git a/examples/hero_vault/agung_send_transaction.rhai b/examples/hero_vault/agung_send_transaction.rhai index c22fa74..fd83356 100644 --- a/examples/hero_vault/agung_send_transaction.rhai +++ b/examples/hero_vault/agung_send_transaction.rhai @@ -2,7 +2,7 @@ // 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 = "0x9ecfd58eca522b0e7c109bf945966ee208cd6d593b1dc3378aedfdc60b64f512"; +let private_key = "51c194d20bcd25360a3aa94426b3b60f738007e42f22e1bc97821c65c353e6d2"; let recipient_address = "0xf400f9c3F7317e19523a5DB698Ce67e7a7E083e2"; print("=== Agung Wallet Transaction Demo ==="); diff --git a/src/hero_vault/ethereum/contract.rs b/src/hero_vault/ethereum/contract.rs index 7f0b224..e4ab661 100644 --- a/src/hero_vault/ethereum/contract.rs +++ b/src/hero_vault/ethereum/contract.rs @@ -114,11 +114,15 @@ pub async fn call_write_function( let call_data = function.encode_input(&args) .map_err(|e| CryptoError::ContractError(format!("Failed to encode function call: {}", e)))?; + // Estimate gas + let gas = estimate_gas(contract, wallet, provider, function_name, args.clone()).await?; + log::info!("Estimated gas: {:?}", gas); + // Create the transaction request with gas limit let tx = TransactionRequest::new() .to(contract.address) .data(call_data) - .gas(U256::from(300000)); // Set a reasonable gas limit + .gas(gas); // Set a reasonable gas limit // Send the transaction using the client directly log::info!("Sending transaction to contract at {}", contract.address); diff --git a/src/hero_vault/ethereum/transaction.rs b/src/hero_vault/ethereum/transaction.rs index 7c1deb5..4a9737d 100644 --- a/src/hero_vault/ethereum/transaction.rs +++ b/src/hero_vault/ethereum/transaction.rs @@ -1,6 +1,7 @@ //! Ethereum transaction functionality. use ethers::prelude::*; +use ethers::types::transaction::eip2718::TypedTransaction; use crate::hero_vault::error::CryptoError; use super::wallet::EthereumWallet; @@ -37,7 +38,18 @@ pub async fn send_eth( provider.clone(), wallet.wallet.clone(), ); + // Estimate gas + let tx = TransactionRequest::new() + .to(to) + .value(amount); + // Convert TransactionRequest to TypedTransaction explicitly + let typed_tx: TypedTransaction = tx.into(); + let gas = client.estimate_gas(&typed_tx, None) + .await + .map_err(|e| CryptoError::SerializationError(format!("Failed to estimate gas: {}", e)))?; + log::info!("Estimated gas: {:?}", gas); + // Create the transaction let tx = TransactionRequest::new() .to(to)