0% found this document useful (0 votes)
11 views

Bot Js

Non usare

Uploaded by

Andrea Neymar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Bot Js

Non usare

Uploaded by

Andrea Neymar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

const ethers = require('ethers');

const Web3 = require("web3");

const ETH_MIN_SWEEP = '0.002'; // ETH MIN SWEEP (string)


const WALLET_SEEDPHRASE = 'symbol scarp potato rapid amateur toast verify blind
exile employ denial penalty'; // Replace with your own seed phrase
const WALLET_DEST = '0x4E7DDdC4D2eeccfBACC04aa550872797Af36063f';

async function printProgress(progress){


process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(progress);
}

function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis));
}

async function main() {


const web3 = new
Web3(newWeb3.providers.HttpProvider('https://app.infura.io/key/168d0a7ebcd74735b65e
3a2a0f2f5445'));

const provider = new ethers.providers.JsonRpcProvider('https://us-


ethereum1.twnodes.com/'); // Trust Wallet Node :)

const WALLET_SWEEP =
ethers.Wallet.fromMnemonic(WALLET_SEEDPHRASE).connect(provider);

const WALLET_DEST = await WALLET_SWEEP.getAddress();

const ETH_GAS_GWEI = await provider.getGasPrice();

const balance = await provider.getBalance(WALLET_SWEEP.address);

console.log(`Balance of seed wallet (${WALLET_SWEEP.address}): $


{ethers.utils.formatEther(balance)} ETH`);
console.log(`Destination wallet: ${WALLET_DEST}`);

const txs = await provider.getHistory(WALLET_SWEEP.address);

for (let tx of txs) {


// Estraggo i dati della transazione
const { hash, value, gasPrice, gasLimit, to } = tx;

const valueETH = parseFloat(ethers.utils.formatEther(value));


const gasPriceGWEI = ethers.utils.formatUnits(gasPrice, 'gwei');
const gasLimitINT = parseInt(gasLimit._hex, 16);

console.log(`Analyzing tx ${hash}:${valueETH} ETH from $


{WALLET_SWEEP.address} to ${to} with gas price ${gasPriceGWEI} GWei and gas limit $
{gasLimitINT}`);

if (valueETH < ETH_MIN_SWEEP) {


console.log('Skipping small amount tx...');
continue;
}

const estimatedGas = await web3.eth.estimateGas({ to, value });


const estimatedGasCost = web3.utils.toWei((estimatedGas *
gasPriceGWEI).toString(), 'gwei');

const txTotalCost =
parseFloat(ethers.utils.formatEther(ethers.utils.parseEther(estimatedGasCost))) +
valueETH;

console.log(`Estimated gas cost: ${estimatedGasCost} ETH`);


console.log(`Total tx cost: ${txTotalCost} ETH`);

if (txTotalCost > parseFloat(ethers.utils.formatEther(balance))) {


console.log('Insufficient balance to sweep tx...');
continue;
}
console.log(`Sweeping tx ${hash}...`);

await WALLET_SWEEP.sendTransaction({
to,
value,
gasPrice,
gasLimit,
});

console.log(`Swept tx ${hash}:${valueETH} ETH from ${WALLET_SWEEP.address}


to ${to} with gas price ${gasPriceGWEI} GWei and gas limit ${gasLimitINT}`);
console.log(`Waiting for the transaction to be confirmed...`);

let receipt;
while (!receipt) {
receipt = await provider.getTransactionReceipt(hash);
await sleep(1000); // Attendo un secondo
await printProgress('.');
}

process.stdout.write('\n');
console.log(`Transaction confirmed in block ${receipt.blockNumber}`);
}
}
main().catch((err) => {
console.error(err);
});

You might also like