Ошибка: сбой транзакции на swapExactEthForTokens

Я пытался купить конкретный токен в сети BSC, используя javascript со следующим кодом:

      const ethers = require('ethers');

const addresses = {
  WBNB: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
  factory: '0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73',
  router: '0x10ed43c718714eb63d5aa57b78b54704e256024e',
  recipient: '0xb083653f11a5133868D56dAcD723B837E27b7d17'
}

const init = async () => {

    const mnemonic = 'seed phrase left our for obvious reasons';

    const provider = new ethers.providers.WebSocketProvider('wss://bsc-ws-node.nariox.org:443');
    const wallet = ethers.Wallet.fromMnemonic(mnemonic);
    const account = wallet.connect(provider);

    const router = new ethers.Contract(
        addresses.router,
        [
          'function swapExactETHForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'
        ],
        account
      );
    
    const options = { gasPrice: 5000000000, gasLimit: 400000};
    const amountIn = ethers.utils.parseUnits('0.1', 'ether');    
    const amountOutMin = 0
    const tx = await router.swapExactETHForTokens(
    amountIn,
    amountOutMin,
    [addresses.WBNB, '0xb3225ac90b741f762beca76dea1ead278ef26a96'],
    addresses.recipient,
    Date.now() + 1000 * 60 * 10, //10 minutes
    options
    );
    console.log(`Transaction hash: ${tx.hash}`);

    const receipt = await tx.wait();
    console.log(`Transaction was mined in block ${receipt.blockNumber}`);
    }

init();

После запуска кода я всегда получаю следующую ошибку:

      (node:22256) UnhandledPromiseRejectionWarning: Error: transaction failed (transactionHash="0x35bb3f987f4f99fab4572db341886220a400f791cb68bce401dcf00fd5099396", transaction={"nonce":348,"gasPrice":{"type":"BigNumber","hex":"0x012a05f200"},"gasLimit":{"type":"BigNumber","hex":"0x061a80"},"to":"0x10ED43C718714eb63d5aA57B78B54704E256024E","value":{"type":"BigNumber","hex":"0x00"},"data":"0xa5be382e000000000000000000000000000000000000000000000000000009184e72a000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000b083653f11a5133868d56dacd723b837e27b7d17000000000000000000000000000000000000000000000000000001799a15a8690000000000000000000000000000000000000000000000000000000000000002000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000b3225ac90b741f762beca76dea1ead278ef26a96","chainId":56,"v":148,"r":"0xb536f633a90b06f69a33467d24478dad64f868006a417ebbcd5525a372d6c9bf","s":"0x67c071f07c38723651c1b0e26dfa2bb42cc279587dc43326a2a4d52c81ed65d0","from":"0xb083653f11a5133868D56dAcD723B837E27b7d17","hash":"0x35bb3f987f4f99fab4572db341886220a400f791cb68bce401dcf00fd5099396"}, receipt={"to":"0x10ED43C718714eb63d5aA57B78B54704E256024E","from":"0xb083653f11a5133868D56dAcD723B837E27b7d17","contractAddress":null,"transactionIndex":324,"gasUsed":{"type":"BigNumber","hex":"0x5a8b"},"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","blockHash":"0x2ee5c5c282a605193f282aa34e31fa18c62ff3fdc6cd996e1592be49cdb60e03","transactionHash":"0x35bb3f987f4f99fab4572db341886220a400f791cb68bce401dcf00fd5099396","logs":[],"blockNumber":7663738,"confirmations":1,"cumulativeGasUsed":{"type":"BigNumber","hex":"0x02bf7565"},"status":0,"byzantium":true}, code=CALL_EXCEPTION, version=providers/5.0.24)
    at Logger.makeError (C:\Users\Genray\Desktop\trading-bot\node_modules\@ethersproject\logger\lib\index.js:180:21)
    at Logger.throwError (C:\Users\Genray\Desktop\trading-bot\node_modules\@ethersproject\logger\lib\index.js:189:20)
    at WebSocketProvider.<anonymous> (C:\Users\Genray\Desktop\trading-bot\node_modules\@ethersproject\providers\lib\base-provider.js:1162:36)
    at step (C:\Users\Genray\Desktop\trading-bot\node_modules\@ethersproject\providers\lib\base-provider.js:48:23)
    at Object.next (C:\Users\Genray\Desktop\trading-bot\node_modules\@ethersproject\providers\lib\base-provider.js:29:53)
    at fulfilled (C:\Users\Genray\Desktop\trading-bot\node_modules\@ethersproject\providers\lib\base-provider.js:20:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:22256) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:22256) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Иногда я получаю сообщение об ошибке мгновенно, а иногда это занимает до пары минут. Пытался найти решение, включил газ и даже попытался поднять, но это не помогает. Я нашел решение, в котором мне, по-видимому, нужно сначала одобрить, но я где-то читал, что это не обязательно для swapExactEthForTokens и необходимо только для swapExactTokensForTokens. Кто-нибудь может мне помочь? Кажется, я не могу определить причину ошибки.

0 ответов

Другие вопросы по тегам