Untitled
unknown
plain_text
a year ago
1.2 kB
4
Indexable
Never
const ethers = require('ethers'); // Replace with your own MetaMask private key and RPC URL const privateKey = '<PrivateKey>'; const rpcUrl = '<RPCUrl>'; // Create a provider with your RPC URL const provider = new ethers.JsonRpcProvider(rpcUrl); // Create a wallet using your private key const wallet = new ethers.Wallet(privateKey, provider); // Replace with the recipient's address and the amount to send const recipientAddress = '<RecipientAddress>'; const amountToSend = ethers.utils.parseEther('1'); // Send 1 USDT (async () => { try { // Check the wallet balance const balance = await wallet.getBalance(); console.log(`Balance: ${ethers.utils.formatEther(balance)} MATIC`); // Check if the wallet has sufficient funds if (balance.lt(amountToSend)) { console.error('Insufficient balance'); return; } // Create a transaction const tx = { to: recipientAddress, value: amountToSend, }; // Sign and send the transaction const txResponse = await wallet.sendTransaction(tx); console.log(`Transaction hash: ${txResponse.hash}`); } catch (error) { console.error('Error:', error); } })();