当前位置:   article > 正文

pancakeswap 开盘抢跑机器人 (附代码)_scan0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c

scan0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c

这个机器人主要就是抢跑用的:机器人一次只能狙击一个令牌。

如何运行
1. 拷贝代码
2. $ npm 安装
3. 复制你的 env.example到 .env
4. 使用以下说明设置您的 .env:        

WBNB_CONTRACT=0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c

购买代币的 WBNB 合约

FACTORY=0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73

Pancake Factory 合约获得购买功能 ROUTER=0x10ED43C718714eb63d5aA57B78B54704E256024E

Pancake Factory 合约处理购买功能

YOUR_ADDRESS=

您来自 trustwallet 或其他钱包的 BSC (BEP20) 地址。

SLIPPAGE=5

在这里自定义您的滑点,不能小数。 (例如:1、5、10)。如果你买早期代币推荐 30+ Slippage

GWEI=5

在这里自定义您的 GWEI(gas 费),不能小数。 (例如:5、10、25)。如果买早期代币推荐15+ GWEI

GAS_LIMIT=345684

最低限度是 210000,越多越好。

MIN_LIQUIDITY_ADDED=3

设置您想购买的配对地址中添加多少最低流动性。设置在 BNB 中。 (例如:2、4、7)。 2 表示增加了 2 个 BNB 流动性。

YOUR_MNEMONIC=

在这里输入您的私钥,您可以从您的钱包隐私中获得。

AMOUNT_OF_WBNB=0.002

您想在WBNB中购买代币的金额。 TO_PURCHASE=0xe9e7cea3dedca5984780bafc599bd69add087d56

你想购买的代币地址。

 下面就是具体的代码 :

  1. import ethers from 'ethers';
  2. import express from 'express';
  3. import chalk from 'chalk';
  4. import dotenv from 'dotenv';
  5. import inquirer from 'inquirer';
  6. const app = express();
  7. dotenv.config();
  8. const data = {
  9. WBNB: process.env.WBNB_CONTRACT, //wbnb
  10. to_PURCHASE: process.env.TO_PURCHASE, // token that you will purchase = BUSD for test '0xe9e7cea3dedca5984780bafc599bd69add087d56'
  11. AMOUNT_OF_WBNB : process.env.AMOUNT_OF_WBNB, // how much you want to buy in WBNB
  12. factory: process.env.FACTORY, //PancakeSwap V2 factory
  13. router: process.env.ROUTER, //PancakeSwap V2 router
  14. recipient: process.env.YOUR_ADDRESS, //your wallet address,
  15. Slippage : process.env.SLIPPAGE, //in Percentage
  16. gasPrice : ethers.utils.parseUnits(`${process.env.GWEI}`, 'gwei'), //in gwei
  17. gasLimit : process.env.GAS_LIMIT, //at least 21000
  18. minBnb : process.env.MIN_LIQUIDITY_ADDED //min liquidity added
  19. }
  20. let initialLiquidityDetected = false;
  21. let jmlBnb = 0;
  22. const bscMainnetUrl = 'https://bsc-dataseed1.defibit.io/' //https://bsc-dataseed1.defibit.io/ https://bsc-dataseed.binance.org/
  23. const wss = 'wss://bsc-ws-node.nariox.org:443';
  24. const mnemonic = process.env.YOUR_MNEMONIC //your memonic;
  25. const tokenIn = data.WBNB;
  26. const tokenOut = data.to_PURCHASE;
  27. const provider = new ethers.providers.WebSocketProvider(wss);
  28. const wallet = new ethers.Wallet(mnemonic);
  29. const account = wallet.connect(provider);
  30. const factory = new ethers.Contract(
  31. data.factory,
  32. [
  33. 'event PairCreated(address indexed token0, address indexed token1, address pair, uint)',
  34. 'function getPair(address tokenA, address tokenB) external view returns (address pair)'
  35. ],
  36. account
  37. );
  38. const router = new ethers.Contract(
  39. data.router,
  40. [
  41. 'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)',
  42. 'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)',
  43. 'function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'
  44. ],
  45. account
  46. );
  47. const erc = new ethers.Contract(
  48. data.WBNB,
  49. [{"constant": true,"inputs": [{"name": "_owner","type": "address"}],"name": "balanceOf","outputs": [{"name": "balance","type": "uint256"}],"payable": false,"type": "function"}],
  50. account
  51. );
  52. const run = async () => {
  53. await checkLiq();
  54. }
  55. let checkLiq = async() => {
  56. const pairAddressx = await factory.getPair(tokenIn, tokenOut);
  57. console.log(chalk.blue(`pairAddress: ${pairAddressx}`));
  58. if (pairAddressx !== null && pairAddressx !== undefined) {
  59. if (pairAddressx.toString().indexOf('0x0000000000000') > -1) {
  60. console.log(chalk.cyan(`pairAddress ${pairAddressx} not detected. Auto restart`));
  61. return await run();
  62. }
  63. }
  64. const pairBNBvalue = await erc.balanceOf(pairAddressx);
  65. jmlBnb = await ethers.utils.formatEther(pairBNBvalue);
  66. console.log(`value BNB : ${jmlBnb}`);
  67. if(jmlBnb > data.minBnb){
  68. setTimeout(() => buyAction(), 5000);
  69. }
  70. else{
  71. initialLiquidityDetected = false;
  72. console.log(' run again...');
  73. return await run();
  74. }
  75. }
  76. let buyAction = async() => {
  77. if(initialLiquidityDetected === true) {
  78. console.log('not buy cause already buy');
  79. return null;
  80. }
  81. console.log('ready to buy');
  82. try{
  83. initialLiquidityDetected = true;
  84. let amountOutMin = 0.;
  85. //We buy x amount of the new token for our wbnb
  86. const amountIn = ethers.utils.parseUnits(`${data.AMOUNT_OF_WBNB}`, 'ether');
  87. //if ( parseInt(data.Slippage) !== 0 ){
  88. // const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
  89. //Our execution price will be a bit different, we need some flexbility
  90. // amountOutMin = amounts[1].sub(amounts[1].div(`${data.Slippage}`));
  91. // }
  92. console.log(
  93. chalk.green.inverse(`Start to buy \n`)
  94. +
  95. `Buying Token
  96. =================
  97. tokenIn: ${(amountIn * 1e-18).toString()} ${tokenIn} (BNB)
  98. tokenOut: ${(amountOutMin / 1e-18).toString()} ${tokenOut}
  99. `);
  100. console.log('Processing Transaction.....');
  101. console.log(chalk.yellow(`amountIn: ${(amountIn * 1e-18)} ${tokenIn} (BNB)`));
  102. console.log(chalk.yellow(`amountOutMin: ${amountOutMin / 1e-18}`));
  103. console.log(chalk.yellow(`tokenIn: ${tokenIn}`));
  104. console.log(chalk.yellow(`tokenOut: ${tokenOut}`));
  105. console.log(chalk.yellow(`data.recipient: ${data.recipient}`));
  106. console.log(chalk.yellow(`data.gasLimit: ${data.gasLimit}`));
  107. console.log(chalk.yellow(`data.gasPrice: ${data.gasPrice}`));
  108. const tx = await router.swapExactTokensForTokensSupportingFeeOnTransferTokens( //uncomment this if you want to buy deflationary token
  109. // const tx = await router.swapExactTokensForTokens( //uncomment here if you want to buy token
  110. amountIn,
  111. amountOutMin,
  112. [tokenIn, tokenOut],
  113. data.recipient,
  114. Date.now() + 1000 * 60 * 5, //5 minutes
  115. {
  116. 'gasLimit': data.gasLimit,
  117. 'gasPrice': data.gasPrice,
  118. 'nonce' : null //set you want buy at where position in blocks
  119. });
  120. const receipt = await tx.wait();
  121. console.log(`Transaction receipt : https://www.bscscan.com/tx/${receipt.logs[1].transactionHash}`);
  122. setTimeout(() => {process.exit()},4000);
  123. }catch(err){
  124. let error = JSON.parse(JSON.stringify(err));
  125. console.log(`Error caused by :
  126. {
  127. reason : ${error.reason},
  128. transactionHash : ${error.transactionHash}
  129. message : Please check your BNB/WBNB balance, maybe its due because insufficient balance or approve your token manually on pancakeSwap
  130. }`);
  131. console.log(error);
  132. inquirer.prompt([
  133. {
  134. type: 'confirm',
  135. name: 'runAgain',
  136. message: 'Do you want to run again thi bot?',
  137. },
  138. ])
  139. .then(answers => {
  140. if(answers.runAgain === true){
  141. console.log('= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =');
  142. console.log('Run again');
  143. console.log('= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =');
  144. initialLiquidityDetected = false;
  145. run();
  146. }else{
  147. process.exit();
  148. }
  149. });
  150. }
  151. }
  152. run();
  153. const PORT = 5001;
  154. app.listen(PORT, console.log(chalk.yellow(`Listening for Liquidity Addition to token ${data.to_PURCHASE}`)));

主要执行交易的就是这个方法:swapExactTokensForTokensSupportingFeeOnTransferTokens

代码是测试过的,执行过程中有问题,可以留言与我沟通。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号