New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: cannot estimate gas Pancake swap bot. #62
Comments
This works const tx = await router.swapExactTokensForTokens( But now getting code: -32000, |
I'm having the same issue |
Were you able to solve this? |
this gets me past the estimated gas issues
|
… On Wed, May 19, 2021 at 6:10 PM Martín Schere ***@***.***> wrote:
Were you able to solve this?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#62 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATE52OBXMIDTW3UFJROTWWDTORANPANCNFSM45AWF6AQ>
.
|
But you are able to call |
No I don’t care about that. I have hard coded the gas
…On Thu, May 20, 2021 at 7:43 AM Martín Schere ***@***.***> wrote:
But you are able to call getAmountsOut?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#62 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATE52OHY6F3JA34VFNUC4EDTOT7W3ANCNFSM45AWF6AQ>
.
|
Yes, but when I run your code I get the error in |
You need to add BNB and WBNB in your test wallet
***************
const ethers = require(‘ethers’);
const addresses = {
WBNB: ‘0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c’,
BUSD: ‘0xe9e7cea3dedca5984780bafc599bd69add087d56’,
factory: ‘0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73’,
router: ‘0x10ed43c718714eb63d5aa57b78b54704e256024e’,
recipient: ‘’
}
//First address of this mnemonic must have enough BNB to pay for tx fess
const privateKey = ‘’;
const mygasPrice = ethers.utils.parseUnits(‘5’, ‘gwei’);
const provider = new ethers.providers.WebSocketProvider(‘wss://
muddy-young-frost.bsc.quiknode.pro/’);
const wallet = new ethers.Wallet(privateKey);
const account = wallet.connect(provider);
const factory = new ethers.Contract(
addresses.factory,
[‘event PairCreated(address indexed token0, address indexed token1, address
pair, uint)’],
account
);
const router = new ethers.Contract(
addresses.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)’
],
account
);
const wbnb = new ethers.Contract(
addresses.WBNB,
[
‘function approve(address spender, uint amount) public returns(bool)’,
],
account
);
console.log(Before Approve);
const valueToapprove = ethers.utils.parseUnits(‘0.1’, ‘ether’);
const init = async () => {
const tx = await wbnb.approve(
router.address,
valueToapprove,
{
gasPrice: mygasPrice,
gasLimit: ‘162445’
}
);
console.log(After Approve);
const receipt = await tx.wait();
console.log(‘Transaction receipt’);
console.log(receipt);
}
factory.on(‘PairCreated’, async (token0, token1, pairAddress) => {
console.log(after factory.on:);
console.log( New pair detected ================= token0: ${token0} token1:
${token1} pairAddress: ${pairAddress} );
//The quote currency needs to be WBNB (we will pay with WBNB)
let tokenIn, tokenOut;
if(token0 === addresses.WBNB) {
tokenIn = token0;
tokenOut = token1;
}
if(token1 == addresses.WBNB) {
tokenIn = token1;
tokenOut = token0;
}
//The quote currency is not WBNB
if(typeof tokenIn === ‘undefined’) {
return;
}
//We buy for 0.1 BNB of the new token
//ethers was originally created for Ethereum, both also work for BSC
//‘ether’ === ‘bnb’ on BSC
console.log(line 87);
const amountIn = ethers.utils.parseUnits(‘0.01’, ‘ether’);
const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
//Our execution price will be a bit different, we need some flexbility
const amountOutMin = amounts[1].sub(amounts[1].div(10));
console.log(line 92);
console.log( Buying new token ================= tokenIn: ${amountIn}
${tokenIn} (WBNB) tokenOut: ${amountOutMin} ${tokenOut} );
console.log(line 101);
const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[tokenIn, tokenOut],
addresses.recipient,
Math.floor(Date.now() / 1000) + 60 * 20, // 20 minutes from the current
Unix time
{
gasPrice: mygasPrice,
gasLimit: 162445
}
);
console.log(line 117);
const receipt = await tx.wait();
console.log(‘Transaction receipt’);
console.log(receipt);
});
init();
…On Thu, May 20, 2021 at 8:18 AM Martín Schere ***@***.***> wrote:
Yes, but when I run your code I get the error in getAmountsOut like I do
when I run mine
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#62 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATE52OG5D6D6O5ZU2HRS5ETTOUD27ANCNFSM45AWF6AQ>
.
|
Thank you. It very helpful for me :) I'm a developer but stuck after 2 hours research |
Hi, I am facing the same issue, and I have transferred a small amount of WBNB and definitely have BNB in my wallet. However, I am still getting this error. Currently setting mygasFee as
|
Okay I added different gas prices for the approval and swap request, and the transaction went through, but I am still receiving a |
I am looking to add .gasLimit and or .gasPrice to solve the estimate gas error..
I get the WBNB approval to work but then the script errors with estimate gas during the swap
The text was updated successfully, but these errors were encountered: