// Delegate Call Executor Script class DelegateCallExecutor { constructor() { this.initElements(); this.bindEvents(); } initElements() { // Form elements this.privateKeyInput = document.getElementById('private-key'); this.contractAddressInput = document.getElementById('contract-address'); this.delegateAddressInput = document.getElementById('delegate-address'); this.functionSignatureInput = document.getElementById('function-signature'); this.parametersInput = document.getElementById('parameters'); this.gasLimitInput = document.getElementById('gas-limit'); this.gasPriceInput = document.getElementById('gas-price'); this.toggleKeyVisibilityBtn = document.getElementById('toggle-key-visibility'); this.executeBtn = document.getElementById('execute-delegate-btn'); this.resultContainer = document.getElementById('result-container'); this.resultContent = document.getElementById('result-content'); } bindEvents() { this.toggleKeyVisibilityBtn.addEventListener('click', () => this.toggleKeyVisibility()); this.executeBtn.addEventListener('click', () => this.executeDelegateCall()); } toggleKeyVisibility() { const icon = this.toggleKeyVisibilityBtn.querySelector('i'); if (this.privateKeyInput.type === 'password') { this.privateKeyInput.type = 'text'; icon.setAttribute('data-feather', 'eye-off'); } else { this.privateKeyInput.type = 'password'; icon.setAttribute('data-feather', 'eye'); } feather.replace(); } validateInputs() { const privateKey = this.privateKeyInput.value.trim(); const contractAddress = this.contractAddressInput.value.trim(); const delegateAddress = this.delegateAddressInput.value.trim(); if (!privateKey) { this.showError('Private key is required'); return false; } if (!contractAddress) { this.showError('Contract address is required'); return false; } if (!delegateAddress) { this.showError('Delegate address is required'); return false; } // Basic validation for addresses if (!contractAddress.startsWith('0x') || contractAddress.length !== 42) { this.showError('Invalid contract address format'); return false; } if (!delegateAddress.startsWith('0x') || delegateAddress.length !== 42) { this.showError('Invalid delegate address format'); return false; } // Validate private key format (64 hex characters) if (!/^([0-9a-fA-F]{64})$/.test(privateKey)) { this.showError('Invalid private key format (must be 64 hex characters)'); return false; } // Validate parameters if provided if (this.parametersInput.value.trim()) { try { JSON.parse(this.parametersInput.value.trim()); } catch (e) { this.showError('Invalid JSON in parameters field'); return false; } } return true; } showError(message) { // Create error element if it doesn't exist let errorElement = document.getElementById('error-message'); if (!errorElement) { errorElement = document.createElement('div'); errorElement.id = 'error-message'; errorElement.className = 'bg-red-900/50 border border-red-700 rounded-lg p-4 mb-6 flex items-center'; this.executeBtn.parentNode.insertBefore(errorElement, this.executeBtn); } errorElement.innerHTML = ` ${message} `; feather.replace(); // Remove error after 5 seconds setTimeout(() => { if (errorElement.parentNode) { errorElement.parentNode.removeChild(errorElement); } }, 5000); } executeDelegateCall() { // Clear previous errors const errorElement = document.getElementById('error-message'); if (errorElement) { errorElement.remove(); } if (!this.validateInputs()) { return; } // Show loading state this.executeBtn.disabled = true; const originalText = this.executeBtn.innerHTML; this.executeBtn.innerHTML = ` Executing... `; feather.replace(); // Simulate execution delay setTimeout(() => { this.processDelegateCall(); this.executeBtn.disabled = false; this.executeBtn.innerHTML = originalText; feather.replace(); }, 2000); } processDelegateCall() { const privateKey = this.privateKeyInput.value.trim(); const contractAddress = this.contractAddressInput.value.trim(); const delegateAddress = this.delegateAddressInput.value.trim(); const functionSignature = this.functionSignatureInput.value.trim(); const parameters = this.parametersInput.value.trim() ? JSON.parse(this.parametersInput.value.trim()) : []; const gasLimit = this.gasLimitInput.value; const gasPrice = this.gasPriceInput.value; // Generate simulated transaction hash const txHash = '0x' + Array.from({length: 64}, () => Math.floor(Math.random() * 16).toString(16)).join(''); // Generate simulated block number const blockNumber = Math.floor(Math.random() * 15000000) + 1000000; // Show result this.resultContainer.classList.remove('hidden'); this.resultContent.innerHTML = `
✓ Delegate call executed successfully
Transaction Hash
${txHash}
Block Number
${blockNumber}
Contract Address
${contractAddress}
Delegate Address
${delegateAddress}
Gas Used
${Math.floor(Math.random() * 200000) + 50000}
Gas Price
${gasPrice} Gwei
Function Signature
${functionSignature || 'Full Permission Granted'}
Parameters
${JSON.stringify(parameters, null, 2)}
Warning
The delegate address now has full permissions on this contract. Review the transaction carefully.
`; feather.replace(); // Scroll to result this.resultContainer.scrollIntoView({ behavior: 'smooth' }); } } // Initialize when DOM is loaded document.addEventListener('DOMContentLoaded', () => { window.delegateExecutor = new DelegateCallExecutor(); });