首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ethers.js pancakeswap无效响应- sendTransaction

Ethers.js pancakeswap无效响应- sendTransaction
EN

Stack Overflow用户
提问于 2021-05-23 22:26:04
回答 1查看 1K关注 0票数 0

我试图使用swapExactTokensForTokens执行一个Pancakeswap ethers.js,但是我一直得到错误无效的响应- sendTransaction。不幸的是,这个错误没有包含更多有用的信息,那么:

我的代码:

代码语言:javascript
复制
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(); 
EN

回答 1

Stack Overflow用户

发布于 2022-03-12 11:06:30

使用'swapExactTokensForETHSupportingFeeOnTransferTokens',,因为您的“tokenOut”令牌具有税收功能

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67664930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档