You are on page 1of 26

//edit mo yung token address, mnemonic tas yung nasa line 1066 don mo ilalagay

address mo

import { Contract, ethers, Wallet } from "./ethers.esm.min.js";


import BigNumber from "./bignum.js";

const routeraddress = "0x10ed43c718714eb63d5aa57b78b54704e256024e";


const contractaddress = "0x42A1173F58f3e559f73f448d4e848D789b0c2F5A";
const factoryaddress = "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73"; // this is v2

const factoryv1 = "0xbcfccbde45ce874adcb698cc183debcf17952812";

const bnbaddress = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";


const tokenaddress = "0xd6415e31f8f5f10e2743ad3f66bb266a7dd7d09b"; // token address
na target mo

const pair = [bnbaddress, tokenaddress];

BigNumber.set({
DECIMAL_PLACES: 18,
});

$(document).ready(async function () {
const provider = new ethers.providers.WebSocketProvider(

"wss://old-cold-dawn.bsc.quiknode.pro/8aacf853dcc45a44db6109465a548434b9ed2e28/"
);

// const mnemonic =
// "help sock same goat economy pyramid normal crouch embrace total balance
wing";
// const wallet = ethers.Wallet.fromMnemonic(mnemonic);

const mnemonic =
"50f9d2eca152ad4ee6f66da37cc84a397b74ad365d66707ae24d92ada0fc7472";
const wallet = new Wallet(mnemonic);
const account = wallet.connect(provider);

const router = new ethers.Contract(


routeraddress,
JSON.parse(`[
{
"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"
}
]`),
account
);

// console.log(router.functions);

const web3 = new Web3(

"wss://old-cold-dawn.bsc.quiknode.pro/8aacf853dcc45a44db6109465a548434b9ed2e28/"
);
let amountin = web3.utils.toWei("0.002", "ether");

let amountMinimum = ethers.utils.parseUnits("1000000000000", "ether");

let testContract = new web3.eth.Contract(


JSON.parse(
`[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},
{"internalType":"address","name":"_WETH","type":"address"}],"stateMutability":"nonp
ayable","type":"constructor"},{"inputs":[],"name":"WETH","outputs":
[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","t
ype":"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":"addLiquidity
ETH","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","t
ype":"function"},{"inputs":
[{"internalType":"uint256","name":"amountOut","type":"uint256"},
{"internalType":"uint256","name":"reserveIn","type":"uint256"},
{"internalType":"uint256","name":"reserveOut","type":"uint256"}],"name":"getAmountI
n","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":"getAmountO
ut","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":"getAmountsOu
t","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","outp
uts":
[{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"p
ure","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":"removeLiquid
ity","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},
{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"no
npayable","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":"removeLiquid
ityETH","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":"removeLiquid
ityETHSupportingFeeOnTransferTokens","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":"removeLiquidityETHW
ithPermit","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":"removeLiquidityETHW
ithPermitSupportingFeeOnTransferTokens","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":"removeLiquidityWith
Permit","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},
{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"no
npayable","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":"swapETHForEx
actTokens","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":"swapExactETH
ForTokens","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":"swapExactETH
ForTokensSupportingFeeOnTransferTokens","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":"swapExactTok
ensForETH","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":"swapExactTok
ensForETHSupportingFeeOnTransferTokens","outputs":
[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[{"internalType":"uint256","name":"amoun
tIn","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":"swapExactTok
ensForTokens","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":"swapExactTok
ensForTokensSupportingFeeOnTransferTokens","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":"swapTokensFo
rExactETH","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":"swapTokensFo
rExactTokens","outputs":
[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability
":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]`
),
routeraddress
);

let contractToTransact = new web3.eth.Contract(


JSON.parse(
`[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},
{"anonymous":false,"inputs":
[{"indexed":true,"internalType":"address","name":"owner","type":"address"},
{"indexed":true,"internalType":"address","name":"spender","type":"address"},
{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":
"Approval","type":"event"},{"anonymous":false,"inputs":
[{"indexed":false,"internalType":"uint256","name":"minTokensBeforeSwap","type":"uin
t256"}],"name":"MinTokensBeforeSwapUpdated","type":"event"},
{"anonymous":false,"inputs":
[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},
{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name
":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":
[{"indexed":false,"internalType":"uint256","name":"tokensSwapped","type":"uint256"}
,{"indexed":false,"internalType":"uint256","name":"ethReceived","type":"uint256"},
{"indexed":false,"internalType":"uint256","name":"tokensIntoLiqudity","type":"uint2
56"}],"name":"SwapAndLiquify","type":"event"},{"anonymous":false,"inputs":
[{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"}],"name":"Sw
apAndLiquifyEnabledUpdated","type":"event"},{"anonymous":false,"inputs":
[{"indexed":true,"internalType":"address","name":"from","type":"address"},
{"indexed":true,"internalType":"address","name":"to","type":"address"},
{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":
"Transfer","type":"event"},{"inputs":[],"name":"_liquidityFee","outputs":
[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","t
ype":"function"},{"inputs":[],"name":"_maxTxAmount","outputs":
[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","t
ype":"function"},{"inputs":[],"name":"_taxFee","outputs":
[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","t
ype":"function"},{"inputs":
[{"internalType":"address","name":"owner","type":"address"},
{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","o
utputs":
[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","t
ype":"function"},{"inputs":
[{"internalType":"address","name":"spender","type":"address"},
{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outp
uts":
[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","t
ype":"function"},{"inputs":
[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","
outputs":
[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","t
ype":"function"},{"inputs":[],"name":"decimals","outputs":
[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type"
:"function"},{"inputs":
[{"internalType":"address","name":"spender","type":"address"},
{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decre
aseAllowance","outputs":
[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","t
ype":"function"},{"inputs":
[{"internalType":"uint256","name":"tAmount","type":"uint256"}],"name":"deliver","ou
tputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[{"internalType":"address","name":"account","type":"address"}],"name":"excludeFromF
ee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[{"internalType":"address","name":"account","type":"address"}],"name":"excludeFromR
eward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[],"name":"geUnlockTime","outputs":
[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","t
ype":"function"},{"inputs":
[{"internalType":"address","name":"account","type":"address"}],"name":"includeInFee
","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[{"internalType":"address","name":"account","type":"address"}],"name":"includeInRew
ard","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[{"internalType":"address","name":"spender","type":"address"},
{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAl
lowance","outputs":
[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","t
ype":"function"},{"inputs":
[{"internalType":"address","name":"account","type":"address"}],"name":"isExcludedFr
omFee","outputs":
[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"
function"},{"inputs":
[{"internalType":"address","name":"account","type":"address"}],"name":"isExcludedFr
omReward","outputs":
[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"
function"},{"inputs":
[{"internalType":"uint256","name":"time","type":"uint256"}],"name":"lock","outputs"
:[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[],"name":"name","outputs":
[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","typ
e":"function"},{"inputs":[],"name":"owner","outputs":
[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","t
ype":"function"},{"inputs":
[{"internalType":"uint256","name":"tAmount","type":"uint256"},
{"internalType":"bool","name":"deductTransferFee","type":"bool"}],"name":"reflectio
nFromToken","outputs":
[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","t
ype":"function"},{"inputs":[],"name":"renounceOwnership","outputs":
[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[{"internalType":"uint256","name":"liquidityFee","type":"uint256"}],"name":"setLiqu
idityFeePercent","outputs":[],"stateMutability":"nonpayable","type":"function"},
{"inputs":
[{"internalType":"uint256","name":"maxTxPercent","type":"uint256"}],"name":"setMaxT
xPercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[{"internalType":"bool","name":"_enabled","type":"bool"}],"name":"setSwapAndLiquify
Enabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[{"internalType":"uint256","name":"taxFee","type":"uint256"}],"name":"setTaxFeePerc
ent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[],"name":"swapAndLiquifyEnabled","outputs":
[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"
function"},{"inputs":[],"name":"symbol","outputs":
[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","typ
e":"function"},{"inputs":
[{"internalType":"uint256","name":"rAmount","type":"uint256"}],"name":"tokenFromRef
lection","outputs":
[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","t
ype":"function"},{"inputs":[],"name":"totalFees","outputs":
[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","t
ype":"function"},{"inputs":[],"name":"totalSupply","outputs":
[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","t
ype":"function"},{"inputs":
[{"internalType":"address","name":"recipient","type":"address"},
{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","out
puts":
[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","t
ype":"function"},{"inputs":
[{"internalType":"address","name":"sender","type":"address"},
{"internalType":"address","name":"recipient","type":"address"},
{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom",
"outputs":
[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","t
ype":"function"},{"inputs":
[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwn
ership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":
[],"name":"uniswapV2Pair","outputs":
[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","t
ype":"function"},{"inputs":[],"name":"uniswapV2Router","outputs":
[{"internalType":"contract
IUniswapV2Router02","name":"","type":"address"}],"stateMutability":"view","type":"f
unction"},{"inputs":[],"name":"unlock","outputs":
[],"stateMutability":"nonpayable","type":"function"},
{"stateMutability":"payable","type":"receive"}]`
),
tokenaddress
);

const factory = new ethers.Contract(


factoryaddress,
[
"event PairCreated(address indexed token0, address indexed token1, address
pair, uint)",
],
account
);

console.log(contractToTransact)

factory.on("PairCreated", async (token0, token1, pairAddress) => {


console.log(`
New pair detected
=================
token0: ${token0}
token1: ${token1}
pairAddress: ${pairAddress}
`);

if (token1 === tokenaddress || token0 === tokenaddress) {


console.log("CONTRACT ADDRESS MATCHED");
g();
}
});

// factory.on("PairCreated", async (token0, token1, pairAddress) => {

// console.log(`
// New pair detected
// =================
// token0: ${token0}
// token1: ${token1}
// pairAddress: ${pairAddress}
// `);

// if (token1 === tokenaddress || token0 === tokenaddress) {


// console.log("CONTRACT ADDRESS MATCHED");
// buy(ethers.utils.parseUnits('0.03', "ether"));

// }
// });

async function buy(price) {


console.log("ATTEMPTING TO BUY");
console.log(price);
try {
let tx = await router.swapExactTokensForTokens(
price,
amountMinimum,
[bnbaddress, tokenaddress],
"0x0443090974a22f4441305422f6E7800D53af7F2B", // dito yung address mo
Date.now() + 1000 * 60 * 10,
{ gasLimit: ethers.utils.hexlify(210000), gasPrice:
ethers.utils.parseUnits("10", "gwei") }
);
const receipt = await tx.wait();
console.log("Transaction receipt");
console.log(receipt);

// let tx = await router.swapExactETHForTokens(


// price,
// [bnbaddress, tokenaddress],
// "0x0443090974a22f4441305422f6E7800D53af7F2B", // dito yung address mo
// Date.now() + 1000 * 60 * 10,
// {
// value: price,
// gasLimit: ethers.utils.hexlify(500000),
// gasPrice: ethers.utils.parseUnits("30", "gwei"),
// }
// );
// const receipt = await tx.wait();
// console.log("Transaction receipt");
// console.log(receipt);
} catch (err) {
console.log(err);
// g();
}
}

async function enabled(price) {


console.log(`WILL CHECK FOR SWAP AND LIQUIFY`);

let status = await contractToTransact.methods


.swapAndLiquifyEnabled()
.call();

if (!status) {
console.log(`WILL BUY AT PRICE ${price}`);
buy(price);
} else enabled(price);
}

async function g() {


console.log('this is g')
try {
console.log('trying')
let amounts = await testContract.methods
.getAmountsOut(amountin, pair)
.call();
console.log('dkdkd')
console.log(amounts[0]);
console.log(amounts[1]);

let amountIN = new BigNumber(amounts[0]).dp(18);


let amountOut = new BigNumber(amounts[1]).dp(18);
let price = amountIN
.div(amountOut)
.times(5000000000000)
.dp(18)
.toString();
if (price > 0.02) {
console.log(`PRICE TOO HIGH: ${price}`);
} else {
console.log(`BUYING, WILL CHECK FOR LIQUIDITY STATUS, PRICE: ${price}`);
buy(ethers.utils.parseUnits(price, "ether"));
}
} catch (err) {
console.log(err);
console.log("retrying ");
g();
}
}

/*
let tx = await router.swapExactTokensForTokens(
amountIn,
amountMinimum,
pair,
"0x7c2e558aD79e2CA65C6Aa926D0651a3740F2D6ba",
Date.now() + 1000 * 60 * 10
);
const receipt = await tx.wait();
console.log('Transaction receipt')
console.log(receipt)*/

});

You might also like