Scott-778 / coinmarketcap-sniper-bot

Sniper bot to buy new tokens listed on Coinmarketcap.
MIT License
133 stars 61 forks source link

didn't snipe #7

Closed Investionsforlife closed 2 years ago

Investionsforlife commented 2 years ago

[Running] node "c:\Users\x\cmcBot.js" [2022-01-17T05:05:06.149Z] [INFO] - [Running gramJS version 2.4.1] [2022-01-17T05:05:06.164Z] [INFO] - [Connecting to 149.154.167.91:80/TCPFull...] [2022-01-17T05:05:08.136Z] [INFO] - [Connection to 149.154.167.91:80/TCPFull complete!] ? xxxxxxxxxxxxxxxx 

Hello again, I think I got a bit further with your help already, but the bot did not do its job when a new cmc listing was released. Line 84 was left unedited. However on the line 98 I wrote if(msg.includes('COINMARKETCAP || COINGECKO') && msg.includes('BNB')) I would like to snipe cg and cmc.

thank you

Scott-778 commented 2 years ago

You almost coded it right but there were some mistakes. Use this code instead to snipe cmc and cg.

if(msg.includes('BNB')){ tokenOut = address; buy(); }

Investionsforlife commented 2 years ago

/* coinmarketcap-new-listings-sniper-bot Coinmarketcap new listings sniper bot that uses telegram notifications from this telegram channel https://t.me/joinchat/b17jE6EbQX5kNWY8 use this link and subscribe. Turn on 2 step verification in telegram. Go to my.telegram.org and create App to get api_id and api_hash.

If this helped you buy me a cup of coffee 0x17CCCc30297bCC1287943ea1bb549fF843878669 */

const {TelegramClient } = require("telegram"); //npm install telegram const { StringSession } = require("telegram/sessions"); const input = require("input"); // npm install input const { NewMessage } = require('telegram/events') const ethers = require('ethers'); // npm install ethers

/ ----------------------------------- / const apiId = 12345667788;
const apiHash = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'; const stringSession = new StringSession(""); // fill this later with the value from session.save() const addresses = { WBNB: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', pancakeRouter: '0x10ED43C718714eb63d5aA57B78B54704E256024E', recipient: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' // Your wallet address } const mnemonic = 'ZZZZ ZZZZZZ ZZZZZ ZZZZZZZ ZZZZZ ZZZZZZZZ ZZZZZZZZZZ ZZZZZ ZZZZZZ'; // Your wallet seed phrase const myGasPrice = ethers.utils.parseUnits('7', 'gwei'); // Adjust your gas here, the higher the better const myGasLimit = 1000000; // Gas limit const investmentAmount = '0.05'; // The amount you want to buy in BNB / ----------------------------------- /

const channelId = 1517585345; const node = 'https://bsc-dataseed.binance.org/'; const wallet = new ethers.Wallet.fromMnemonic(mnemonic); const provider = new ethers.providers.JsonRpcProvider(node); const account = wallet.connect(provider); let tokenIn, tokenOut; tokenIn = addresses.WBNB; const amountIn = ethers.utils.parseUnits(investmentAmount, 'ether'); let pancakeAbi = [{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"amountADesired","type":"uint256"},{"internalType":"uint256","name":"amountBDesired","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountTokenDesired","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidityETH","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"reserveIn","type":"uint256"},{"internalType":"uint256","name":"reserveOut","type":"uint256"}],"name":"getAmountIn","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"reserveIn","type":"uint256"},{"internalType":"uint256","name":"reserveOut","type":"uint256"}],"name":"getAmountOut","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsIn","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsOut","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"reserveA","type":"uint256"},{"internalType":"uint256","name":"reserveB","type":"uint256"}],"name":"quote","outputs":[{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidity","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidityETH","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidityETHSupportingFeeOnTransferTokens","outputs":[{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityETHWithPermit","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityETHWithPermitSupportingFeeOnTransferTokens","outputs":[{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityWithPermit","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapETHForExactTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactETHForTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactETHForTokensSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForETH","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForETHSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForTokensSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapTokensForExactETH","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapTokensForExactTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]; const pancakeRouter = new ethers.Contract( addresses.pancakeRouter, pancakeAbi, account );

const buy = async () =>{ console.log('Buying Token Now'); const amounts = await pancakeRouter.getAmountsOut(amountIn, [tokenIn, tokenOut]); const amountOutMin = amounts[1].sub(amounts[1].div(10)); // 50% Slippage should be high enough so the transaction will not fail. //To change slippage tolerance change the last number on the line above. For example, 5 would be 20% slippage, 10 would be 10%, 2 would be 50%.

const tx = await pancakeRouter.swapExactETHForTokens(
    amountOutMin,
    [tokenIn, tokenOut],
    addresses.recipient,
    Math.floor(Date.now() / 1000) + 60 * 4, 
    {
    value: amountIn.toString(),
    gasPrice: myGasPrice,
    gasLimit: myGasLimit
    }
    );
    const receipt = await tx.wait();
    console.log('Transaction receipt');
    console.log(receipt);
    process.exit(); 

}

(async () => { const client = new TelegramClient(stringSession, apiId, apiHash, { connectionRetries: 5, }); await client.start({ phoneNumber: async () => await input.text("123455678924"), password: async () => await input.text("gggggggggggg32"), phoneCode: async () => await input.text("+49"), onError: (err) => console.log(err), }); console.log("You should now be connected."); console.log(client.session.save()); // Save this string to avoid logging in again client.addEventHandler(onNewMessage, new NewMessage({})); })();

async function onNewMessage(event) { const message = event.message; if(message.peerId.channelId == channelId){ const msg = message.message.replace(/\n/g, " ").split(" "); var address = ''; for (var i = 0; i < msg.length; i++){
if (msg[i].length == 42 && msg[i].startsWith("0x")){ address = msg[i]; }
}

    if(msg.includes('BNB')){
        tokenOut = address;
        buy();
        }
    }
}

}

Sorry there was still something wrong. Could You please check? I was particularly unsure about the way to type the phone number and phone code (tested 0049 and 49 aswell)

thank you

Investionsforlife commented 2 years ago

I assume the "password" is the 2 step verification password.

Scott-778 commented 2 years ago

Don't change any code from lines 72 to 85 and delete the last bracket. You'll login in to telegram through the command prompt it will ask for your telephone number, use your country code first for example 15555555555 then telegram will send you a code on the telegram app and you'll need to enter that in the command prompt, then enter your two step password. Then you leave it running until you get a notification from the cmc channel and it will buy that token.

Investionsforlife commented 2 years ago

I removed the last bracket on the line 104. I use VS code for coding and previously for running this file and those statements I wrote were in the output section there when running the bot. In the problems section there is nothing after remowing the last bracket. I previously did not notice the whole section though.

However I tried running the bot on windows cmd after installing node js and typing npm install telegram npm install input npm install ethers there too. Now I get redirected to VS code. I do not know what to do with the node anyway though.

Do you mean that although the phone number and the password are written in the code, it would ask them again when the bot is properly running?

Scott-778 commented 2 years ago

You should only edit lines 19 to 30. You should not put your phone number in cmcBot.js file. Run the bot in the command prompt using the command node cmcBot.js. Then when the bot is running it will ask for your phone number type your number in the command prompt and press enter. Then telegram will send you a login code and then you type that number into the command prompt and press enter. Then the bot will ask for you two factor password type that into the command prompt and press enter.

Scott-778 commented 2 years ago

If you want to buy both coinmarketcap and coingecko line 98 should look exactly like this if(msg.includes('BNB')){

Investionsforlife commented 2 years ago

thank you very much I will buy you a coffee soon I guess! Your last answer solved this. I just had to write. Somehow the instructions were changed to the phone number and password I previously typed but already changed back to normal. Anyway it seems to work so aswell - I just have to remember to type number and the password everytime but no problem. I will close the issue once the first snipe has been shot.

Scott-778 commented 2 years ago

To avoid logging in again in the future copy that long string that the command prompt prints after you log in and paste that in between the quotes on line 21 const stringSession = new StringSession("paste long string from command prompt here"); // fill this later with the value from session.save()