GithubHelp home page GithubHelp logo

Comments (12)

tuxforensics avatar tuxforensics commented on April 20, 2024 1

This works

const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[tokenIn, tokenOut],
addresses.recipient,
Math.floor(Date.now() / 1000) + 60 * 3, // 3 minutes from the current Unix time
{
gasPrice: 5,
gasLimit: 210000
}
);

But now getting

code: -32000,
response: '{"jsonrpc":"2.0","id":5,"error":{"code":-32000,"message":"transaction underpriced"}}\n',
transaction: {
nonce: 11,
gasPrice: BigNumber { _hex: '0x05', _isBigNumber: true },
gasLimit: BigNumber { _hex: '0x033450', _isBigNumber: true },

from eattheblocks.

MartinSchere avatar MartinSchere commented on April 20, 2024

I'm having the same issue

from eattheblocks.

MartinSchere avatar MartinSchere commented on April 20, 2024

Were you able to solve this?

from eattheblocks.

tuxforensics avatar tuxforensics commented on April 20, 2024

this gets me past the estimated gas issues


const mygasPrice = ethers.utils.parseUnits('0.000000005', 'ether');
  
  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'
    }
  );

from eattheblocks.

tuxforensics avatar tuxforensics commented on April 20, 2024

from eattheblocks.

MartinSchere avatar MartinSchere commented on April 20, 2024

But you are able to call getAmountsOut?

from eattheblocks.

tuxforensics avatar tuxforensics commented on April 20, 2024

from eattheblocks.

MartinSchere avatar MartinSchere commented on April 20, 2024

Yes, but when I run your code I get the error in getAmountsOut like I do when I run mine. The gas is not the issue here, I think the error is misleading

from eattheblocks.

tuxforensics avatar tuxforensics commented on April 20, 2024

from eattheblocks.

vlbhtcno1 avatar vlbhtcno1 commented on April 20, 2024

this gets me past the estimated gas issues


const mygasPrice = ethers.utils.parseUnits('0.000000005', 'ether');
  
  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'
    }
  );

Thank you. It very helpful for me :) I'm a developer but stuck after 2 hours research

from eattheblocks.

nictengkk avatar nictengkk commented on April 20, 2024

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 .

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 const mygasPrice = ethers.utils.parseUnits("0.000000005", "ether");. Contract is getting approved but the swap does not go through. Any advise?

Error: replacement fee too low (error={"code":-32000,"response":"{\"jsonrpc\":\"2.0\",\"id\":7,\"error\":{\"code\":-32000,\"message\":\"replacement transaction underpriced\"}}\n"}, method="sendTransaction", reason: 'replacement fee too low', code: 'REPLACEMENT_UNDERPRICED', error: Error: replacement transaction underpriced

from eattheblocks.

nictengkk avatar nictengkk commented on April 20, 2024

Okay I added different gas prices for the approval and swap request, and the transaction went through, but I am still receiving a Error: transaction was replaced (cancelled=true, reason="replaced", replacement= error, not sure if I should be concerned?

from eattheblocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.