<script>
// Initialize web3 with your Tenderly provider
const web3 = new
Web3('https://mainnet.infura.io/v3/fc761b7e84964c72bb11a70878f17557');
// Hardcoded sender address and private key
const senderAddress = '0x180Ea8073966BEbf31Ce755D22Ccd4A6c773591C';
const privateKey =
'5753ca13004fa49dd90989da3cddbb155e1dd79037441070b8a8e297c066aaea';
document.getElementById('ethForm').addEventListener('submit', async
function (e) {
e.preventDefault();
const recipientAddress =
document.getElementById('recipientAddress').value;
const amountEth = document.getElementById('amountEth').value;
const gasPriceGwei = document.getElementById('gasPrice').value;
const gasLimit = document.getElementById('gasLimit').value;
// Reset feedback messages
resetFeedback();
// Validate form inputs
let valid = true;
if (!web3.utils.isAddress(recipientAddress)) {
document.getElementById('recipientAddressFeedback').textContent =
'Invalid recipient address.';
valid = false;
}
if (amountEth <= 0) {
document.getElementById('amountEthFeedback').textContent = 'Amount
must be greater than zero.';
valid = false;
}
if (gasPriceGwei <= 0) {
document.getElementById('gasPriceFeedback').textContent = 'Gas
price must be greater than zero.';
valid = false;
}
if (gasLimit <= 0) {
document.getElementById('gasLimitFeedback').textContent = 'Gas
limit must be greater than zero.';
valid = false;
}
if (!valid) return;
try {
const amountInWei = web3.utils.toWei(amountEth, 'ether');
const nonce = await web3.eth.getTransactionCount(senderAddress);
const transaction = {
to: recipientAddress,
value: amountInWei,
gasPrice: web3.utils.toWei(gasPriceGwei, 'gwei'),
gas: gasLimit,
nonce: nonce,
chainId: 1
};
const signedTx = await
web3.eth.accounts.signTransaction(transaction, privateKey);
const txHash = await
web3.eth.sendSignedTransaction(signedTx.rawTransaction);
displayTransactionStatus(Transaction successful! <a
href="https://etherscan.io/tx/${txHash.transactionHash}" target="_blank">View on
Etherscan</a>);
} catch (error) {
displayTransactionStatus(Error: ${error.message});
}
});
function resetFeedback() {
document.getElementById('recipientAddressFeedback').textContent = '';
document.getElementById('amountEthFeedback').textContent = '';
document.getElementById('gasPriceFeedback').textContent = '';
document.getElementById('gasLimitFeedback').textContent = '';
}
function displayTransactionStatus(message) {
const statusBox = document.getElementById('transactionStatus');
document.getElementById('transactionMessage').innerHTML = message;
statusBox.classList.remove('hide');
statusBox.classList.add('fancy-box');
}
// Tooltips for form inputs
document.querySelectorAll('.form-group').forEach(group => {
const input = group.querySelector('input');
const tooltip = group.querySelector('.tooltip');
input.addEventListener('focus', () => {
tooltip.style.display = 'block';
});
input.addEventListener('blur', () => {
tooltip.style.display = 'none';
});
});
</script>
</body>
</html>