pancakeswap批量抢跑机器

这个机器人主要是用来在pancakeswap开盘时抢先购买token。

界面图

完整代码是用vue写的,现在先来个学习版的方便小白理解

这个学习版只有单个抢先的功能,完整版在GitHub

核心代码讲解:

const ethers = require('ethers');
const axios=require('axios');
//This contains an Endpoint URL, and a wallet private key!!!
//const secrets = require('./secrets.json');

//THIS WORK ON BSC TESTNET!!!!!

//All Values are for the testnet!!!!!!!!

//这里填WBNB地址
const WBNB = "0xae13d989dac2f0debff460ac112a837c89baa7cd"; 
//这里填USDT或者BUSD都行
const BUSD = "0x78867BbEeF44f2326bF8DDd1941a4439382EF2A7";

//这里填pancakeswap路由地址
const router = "0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3";

//填合约地址
const DogeAddress='0xF2a816876e12378F67E1Aa88Fc466685d5C16874';

//填节点地址
const provider = new ethers.providers.JsonRpcProvider("https://late-divine-emerald.bsc-testnet.discover.quiknode.pro/5a218dc9c94daf4309ea27ff0a6a3c2013fae4b6");
//填你的私钥
const wallet = new ethers.Wallet("你的私钥");
const signer = wallet.connect(provider);

const routerContract = new ethers.Contract(
    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)',
        'function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)',
        'function swapExactETHForTokensSupportingFeeOnTransferTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)',
    ],
    signer
);

const busdContract = new ethers.Contract(
    BUSD,
    [
        'function approve(address spender, uint256 amount) external returns (bool)',
        'function balanceOf(address account) external view returns (uint256)'
    ],
    signer
)

const WBNBContract = new ethers.Contract(
    WBNB,
    [
        'function approve(address spender, uint256 amount) external returns (bool)'
    ],
    signer
)

async function main() {
    //获取bnb余额
    let balance=await provider.getBalance(wallet.address)
    const balanceInEth = ethers.utils.formatEther(balance);
    console.log(balanceInEth);
    // //获取usdt余额
    
    const BUSDamountIn = ethers.utils.parseUnits('0.001', 'ether')
        const MaxNum = ethers.utils.parseUnits('1', 'ether')
    console.log(BUSDamountIn);
    console.log(BUSDamountIn);
    let amounts = await routerContract.getAmountsOut(BUSDamountIn, [WBNB, DogeAddress])
    const WBNBamountOutMin = amounts[1].sub(amounts[1].div(10));
    
    // console.log(ethers.utils.formatEther(BUSDamountIn));
    // console.log(ethers.utils.formatEther(WBNBamountOutMin));
    //授权
    const approveTx = await WBNBContract.approve(
        router,
        MaxNum.toString()
    );
    let reciept = await approveTx.wait();
   // console.log(reciept);
    //转账
    const swapTx = await routerContract.swapExactETHForTokens(
        0,
        [WBNB, DogeAddress],
        wallet.address,
        Date.now() + 1000 * 60 * 10,
        {
            'gasLimit': 1000000,
            //'value':BUSDamountIn,
            'gasPrice':ethers.utils.parseUnits('10','gwei'),
            //'from':wallet.address
            value:BUSDamountIn
        }
    )
    receipt = await swapTx.wait();
    console.log(receipt);
}

main().then().finally(() => {});

调用swapExactTokensForTokens和swapExactETHForTokens进行转账操作

原vue写的网页完整版在这里:https://github.com/Larsy5/batch_Transfer

觉得不错可以给我点个star

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>