pancakeswap 开盘抢跑机器人 (附代码)
这个机器人主要就是抢跑用的:机器人一次只能狙击一个令牌。
如何运行 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
你想购买的代币地址。
下面就是具体的代码 :
import ethers from 'ethers';
import express from 'express';
import chalk from 'chalk';
import dotenv from 'dotenv';
import inquirer from 'inquirer';const app = express();
dotenv.config();const data = {WBNB: process.env.WBNB_CONTRACT, //wbnbto_PURCHASE: process.env.TO_PURCHASE, // token that you will purchase = BUSD for test '0xe9e7cea3dedca5984780bafc599bd69add087d56'AMOUNT_OF_WBNB : process.env.AMOUNT_OF_WBNB, // how much you want to buy in WBNBfactory: process.env.FACTORY, //PancakeSwap V2 factoryrouter: process.env.ROUTER, //PancakeSwap V2 routerrecipient: process.env.YOUR_ADDRESS, //your wallet address,Slippage : process.env.SLIPPAGE, //in PercentagegasPrice : ethers.utils.parseUnits(`${process.env.GWEI}`, 'gwei'), //in gweigasLimit : process.env.GAS_LIMIT, //at least 21000minBnb : process.env.MIN_LIQUIDITY_ADDED //min liquidity added
}let initialLiquidityDetected = false;
let jmlBnb = 0;const bscMainnetUrl = 'https://bsc-dataseed1.defibit.io/' //https://bsc-dataseed1.defibit.io/ https://bsc-dataseed.binance.org/
const wss = 'wss://bsc-ws-node.nariox.org:443';
const mnemonic = process.env.YOUR_MNEMONIC //your memonic;
const tokenIn = data.WBNB;
const tokenOut = data.to_PURCHASE;
const provider = new ethers.providers.WebSocketProvider(wss);
const wallet = new ethers.Wallet(mnemonic);
const account = wallet.connect(provider);const factory = new ethers.Contract(data.factory,['event PairCreated(address indexed token0, address indexed token1, address pair, uint)','function getPair(address tokenA, address tokenB) external view returns (address pair)'],account
);const router = new ethers.Contract(data.router,['function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)','function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)','function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'],account
);const erc = new ethers.Contract(data.WBNB,[{"constant": true,"inputs": [{"name": "_owner","type": "address"}],"name": "balanceOf","outputs": [{"name": "balance","type": "uint256"}],"payable": false,"type": "function"}],account
); const run = async () => {await checkLiq();
}let checkLiq = async() => {const pairAddressx = await factory.getPair(tokenIn, tokenOut);console.log(chalk.blue(`pairAddress: ${pairAddressx}`));if (pairAddressx !== null && pairAddressx !== undefined) {if (pairAddressx.toString().indexOf('0x0000000000000') > -1) {console.log(chalk.cyan(`pairAddress ${pairAddressx} not detected. Auto restart`));return await run();}}const pairBNBvalue = await erc.balanceOf(pairAddressx); jmlBnb = await ethers.utils.formatEther(pairBNBvalue);console.log(`value BNB : ${jmlBnb}`);if(jmlBnb > data.minBnb){setTimeout(() => buyAction(), 5000);}else{initialLiquidityDetected = false;console.log(' run again...');return await run();}}let buyAction = async() => {if(initialLiquidityDetected === true) {console.log('not buy cause already buy');return null;}console.log('ready to buy');try{initialLiquidityDetected = true;let amountOutMin = 0.;//We buy x amount of the new token for our wbnbconst amountIn = ethers.utils.parseUnits(`${data.AMOUNT_OF_WBNB}`, 'ether');//if ( parseInt(data.Slippage) !== 0 ){// const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);//Our execution price will be a bit different, we need some flexbility// amountOutMin = amounts[1].sub(amounts[1].div(`${data.Slippage}`));// }console.log(chalk.green.inverse(`Start to buy \n`)+`Buying Token=================tokenIn: ${(amountIn * 1e-18).toString()} ${tokenIn} (BNB)tokenOut: ${(amountOutMin / 1e-18).toString()} ${tokenOut}`);console.log('Processing Transaction.....');console.log(chalk.yellow(`amountIn: ${(amountIn * 1e-18)} ${tokenIn} (BNB)`));console.log(chalk.yellow(`amountOutMin: ${amountOutMin / 1e-18}`));console.log(chalk.yellow(`tokenIn: ${tokenIn}`));console.log(chalk.yellow(`tokenOut: ${tokenOut}`));console.log(chalk.yellow(`data.recipient: ${data.recipient}`));console.log(chalk.yellow(`data.gasLimit: ${data.gasLimit}`));console.log(chalk.yellow(`data.gasPrice: ${data.gasPrice}`));const tx = await router.swapExactTokensForTokensSupportingFeeOnTransferTokens( //uncomment this if you want to buy deflationary token// const tx = await router.swapExactTokensForTokens( //uncomment here if you want to buy tokenamountIn,amountOutMin,[tokenIn, tokenOut],data.recipient,Date.now() + 1000 * 60 * 5, //5 minutes{'gasLimit': data.gasLimit,'gasPrice': data.gasPrice,'nonce' : null //set you want buy at where position in blocks});const receipt = await tx.wait(); console.log(`Transaction receipt : https://www.bscscan.com/tx/${receipt.logs[1].transactionHash}`);setTimeout(() => {process.exit()},4000);}catch(err){let error = JSON.parse(JSON.stringify(err));console.log(`Error caused by : {reason : ${error.reason},transactionHash : ${error.transactionHash}message : Please check your BNB/WBNB balance, maybe its due because insufficient balance or approve your token manually on pancakeSwap}`);console.log(error);inquirer.prompt([{type: 'confirm',name: 'runAgain',message: 'Do you want to run again thi bot?',},]).then(answers => {if(answers.runAgain === true){console.log('= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =');console.log('Run again');console.log('= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =');initialLiquidityDetected = false;run();}else{process.exit();}});}}run();const PORT = 5001;app.listen(PORT, console.log(chalk.yellow(`Listening for Liquidity Addition to token ${data.to_PURCHASE}`)));
主要执行交易的就是这个方法:swapExactTokensForTokensSupportingFeeOnTransferTokens
代码是测试过的,执行过程中有问题,可以留言与我沟通。
pancakeswap 开盘抢跑机器人 (附代码)相关推荐
- 最新 | 用深度强化学习打造不亏钱的交易机器人(附代码)
今天,你AI了没? 关注:决策智能与机器学习,每天学点AI干货 --本文由<量化投资与机器学习>授权转载 在本文中,我们将创建深度强化学习agents,学习如何通过比特币交易赚钱.在本文中 ...
- 【双足机器人(3)】3D线性倒立摆Python仿真(附代码)
往期 本文是双足机器人系列的第三篇,在前面的文章中我们介绍了2D线性倒立摆的基本理论,详见: [双足机器人(1)]线性倒立摆及其运动控制(附代码) 在这篇文章中我们要详细介绍3D线性倒立摆的基本内容, ...
- 【双足机器人(2)】倒立摆运动学模型构建(附代码)
1. 简介 在上一期的文章中,我们对线性倒立摆在2D平面内的运动过程进行了分析,并给出了基于轨道能量的线性倒立摆控制过程. [双足机器人(1)]线性倒立摆及其运动控制(附代码) 在本期文章中,我们将建 ...
- python蜡烛图预测_【Python量化投资】系列之SVR预测第二天开盘趋势和股价的正负统计分析(附代码)...
原标题:[Python量化投资]系列之SVR预测第二天开盘趋势和股价的正负统计分析(附代码) 本期导读 ⊙ML.SVM介绍 ⊙股价的正负统计分析 ⊙预测第二天开盘趋势 机器学习方法是计算机科学的一个分 ...
- 一文弄懂元学习 (Meta Learing)(附代码实战)《繁凡的深度学习笔记》第 15 章 元学习详解 (上)万字中文综述
<繁凡的深度学习笔记>第 15 章 元学习详解 (上)万字中文综述(DL笔记整理系列) 3043331995@qq.com https://fanfansann.blog.csdn.net ...
- 使用英伟达NeMo让你的文字会说话,零基础即可实现自然语音生成任务 | 附代码...
语音合成技术可以将文字信息转换成标准流畅的语音且进行朗读,在公共服务.智慧交通.泛娱乐.智能硬件等领域具有广泛应用. 在第3期英伟达x量子位NLP公开课上,英伟达开发者社区经理分享了[使用NeMo让你 ...
- 微信公众平台开发教程(四) 实例入门:机器人(附源码)
微信公众平台开发教程(四) 实例入门:机器人(附源码) 上一篇文章,写了基本框架,可能很多人会觉得晕头转向,这里提供一个简单的例子来予以说明,希望能帮你解开谜团. 一.功能介绍 通过微信公众平台实现在 ...
- tradeblazer mysql_干货 | 用tradeblazer实现海龟交易法则(附代码)
原标题:干货 | 用tradeblazer实现海龟交易法则(附代码) 一个完整系统的成分 市场--买卖什么 头寸规模--买卖多少 入市--何时买卖 止损--何时退出亏损头寸 离市--何时退出赢利头寸 ...
- 路径规划算法:基于樽海鞘算法的路径规划算法- 附代码
路径规划算法:基于樽海鞘优化的路径规划算法- 附代码 文章目录 路径规划算法:基于樽海鞘优化的路径规划算法- 附代码 1.算法原理 1.1 环境设定 1.2 约束条件 1.3 适应度函数 2.算法结果 ...
- 路径规划算法:基于灰狼优化(GWO)的路径规划算法- 附代码
路径规划算法:基于灰狼优化(GWO)的路径规划算法- 附代码 文章目录 路径规划算法:基于灰狼优化(GWO)的路径规划算法- 附代码 1.算法原理 1.1 环境设定 1.2 约束条件 1.3 适应度函 ...
最新文章
- 递归/归并:count of smaller numbers求逆序数
- WinForm 窗体圆角、平角(不规则窗体)实现的几种方法
- .Net有关问题。在GridView中添加了一个HyperLinkField,用来显示显示详细信息,请教跳转后的详细信息页面该怎样写代码
- vc6开发一个抓包软件_开发一个软件多少钱?3种软件开发公司报价
- 题解报告:hihoCoder #1175:拓扑排序·二
- [论文阅读] End-to-End Incremental Learning
- github的学习和使用
- CodeBlocks下载安装与SDL下载使用配置教程
- “信用租车”来了 芝麻分满650可在飞猪免押租车
- 电视盒是计算机网络连接设备,电视盒子怎么连接电脑
- 戴戴戴师兄-数据分析课程笔记(第一讲)
- java 几种生成海报的方式
- 手机拨出等待时间长_手机打不出去电话怎么回事 一分钟轻松排查原因
- 在ALLEGRO中添加中文字体
- tagged pointer
- Cris 的 Scala 笔记整理(七):面向对象
- 关于RGB的学习,浅色RGB范围……
- Apache Druid 能够支持即席查询
- 硬盘丢失的文件还能恢复吗丨用什么法恢复
- matlab建模三要素,MATLAB建模与求解详解.ppt