0

我正在尝试使用 ethers.js 执行 Pancakeswap swapExactTokensForTokens 但我只是不断收到错误无效响应 - sendTransaction。不幸的是,该错误不包含任何有用的信息,然后:(

我的代码:

const provider = new ethers.providers.WebSocketProvider(config.network);
const tradeWallet = ethers.Wallet.fromMnemonic(config.mnemonic);
const account = tradeWallet.connect(provider);

const router = new ethers.Contract(
  '0x10ED43C718714eb63d5aA57B78B54704E256024E',
  [
    '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 
);

[snip]

    var amountIn = ethers.utils.parseUnits('0.001', 'ether');
    var tokenIn = '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c';
    var tokenOut = '0xd2de3fd31b5c9e1557cf329032615a2870a29ccd';
    var gasPrice = '5000000000';
    var gasLimit = '231795'
    
    var amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut])
    const amountOutMin = amounts[1].sub(amounts[1].div(10));
// values at the time where:
// tokenIn: 100000000000000 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c (WBNB)
// tokenOut: 1810636794711288351 0xd2de3fd31b5c9e1557cf329032615a2870a29ccd

    var tx =  router.swapExactTokensForTokens(
              amountIn,
              amountOutMin,
              [tokenIn, tokenOut],
              addresses.recipient,
              Date.now() + 1000 * 60 * 3, //10 minutes
              { gasPrice: gasPrice, 
                gasLimit: gasLimit
              }
            );
            const receipt = await tx.wait(); 
4

0 回答 0