simple-pancakeswap-sdk icon indicating copy to clipboard operation
simple-pancakeswap-sdk copied to clipboard

findBestRoute not working for testnet

Open jojonicho opened this issue 2 years ago • 0 comments

Background

I was trying to use pancakeSwapPairFactory.trade(tokenAmount); but noticed it threw out of bounds error. Upon further tests, it seems the error was from findBestRound. I've tested this with mainnet tokens and it worked fine.

Steps to reproduce

    const RPC_URL = "https://data-seed-prebsc-1-s1.binance.org:8545/";
    const pancakeswapPair = new PancakeswapPair({
      // the contract address of the token you want to convert FROM
      fromTokenContractAddress: tokenFrom.address,
      //fromTokenContractAddress: WBNB.token().contractAddress,
      // the contract address of the token you want to convert TO
      toTokenContractAddress: tokenTo.address,
      // the ethereum address of the user using this part of the dApp
      ethereumAddress: "0x6aA9d7DB4035cA7BbacB48fe00095a619231b1fC",
      providerUrl: RPC_URL,
    });
    
      const bestRoute = await pancakeSwapPairFactory.findBestRoute("10");
      console.log(bestRoute);

Output

Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.5.0)
    at Logger.makeError (index.js:185:1)
    at Logger.throwError (index.js:194:1)
    at Reader._peekBytes (abstract-coder.js:126:1)
    at Reader.readBytes (abstract-coder.js:138:1)
    at Reader.readValue (abstract-coder.js:144:1)
    at AddressCoder.decode (address.js:22:1)
    at array.js:91:1
    at Array.forEach (<anonymous>)
    at unpack (array.js:70:1)
    at TupleCoder.decode (tuple.js:54:1)
    at AbiCoder.decode (abi-coder.js:93:1)
    at Multicall.<anonymous> (multicall.js:184:1)
    at step (multicall.js:32:1)
    at Object.next (multicall.js:13:1)
    at fulfilled (multicall.js:4:1)

jojonicho avatar Apr 20 '22 08:04 jojonicho