Last active
August 2, 2022 22:08
-
-
Save adityawarmanfw/2fed30899638e48a02aa27d98827c8aa to your computer and use it in GitHub Desktop.
PancakeSwap SwapExactETHForTokens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ethers = require('ethers'); | |
const prompt = require('prompt-sync')({sigint: true}); | |
const addresses = { | |
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", | |
router: "0x10ed43c718714eb63d5aa57b78b54704e256024e", | |
target: "0x8129686c77E63C22bE6a7F06F9C61f135BD0a0CF" // Change this to your address ELSE YOU GONNA SEND YOUR BEANS TO ME | |
} | |
const BNBAmount = ethers.utils.parseEther('0.1').toHexString(); | |
const gasPrice = ethers.utils.parseUnits('10', 'gwei'); | |
const gas = { | |
gasPrice: gasPrice, | |
gasLimit: 300000 | |
} | |
const mnemonic = 'PUT YOUR MNEMONIC HERE'; | |
const provider = new ethers.providers.WebSocketProvider('wss://bsc-ws-node.nariox.org:443'); | |
const wallet = ethers.Wallet.fromMnemonic(mnemonic); | |
const account = wallet.connect(provider); | |
const router = new ethers.Contract( | |
addresses.router, | |
[ | |
'function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)' | |
], | |
account | |
); | |
const snipe = async (token) => { | |
const tx = await router.swapExactETHForTokens( | |
0, // Degen ape don't give a fuxk about slippage | |
[addresses.WBNB, token], | |
addresses.target, | |
Math.floor(Date.now() / 1000) + 60 * 10, // 10 minutes from now | |
{ | |
...gas, | |
value: BNBAmount | |
} | |
); | |
console.log(`Swapping BNB for tokens...`); | |
const receipt = await tx.wait(); | |
console.log(`Transaction hash: ${receipt.transactionHash}`); | |
} | |
const token = prompt('Input token address:'); | |
(async () => { | |
await snipe(token); | |
})(); |
Does this script work with tokens have buy/sell taxes? I notice it's using swapExactETHForTokens instead of swapExactETHForTokensSupportingFeeOnTransferTokens. Seems like a lot of projects nowadays use the token taxes so I assume a version with swapExactETHForTokensSupportingFeeOnTransferTokens is required for those instead?
I'm getting Uncaught SyntaxError: Unexpected identifier
basically I have the whole code in, but it can't find the code itself lol
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i came back to the script, need to make a few modifications here to use this awesome piece, in my tiny project:
basically instead for taking user input - reading a variable from json file, and executing on its own…
what modification to make? sounds easy but I really don’t know much about js yet and need to get it running.