0

ethers.js を使用して pancakeswap スワップを作成しようとしていますが、同じエラーが発生し続けます。

これは私が使用しているコードです:

const ethers = require('ethers');


const init = async function() {
    // testnet
    const addresses = {
        WBNB: "0xae13d989dac2f0debff460ac112a837c89baa7cd",
        BUSD: "0x78867BbEeF44f2326bF8DDd1941a4439382EF2A7", 
        factory: "0x182859893230dC89b114d6e2D547BFFE30474a21",
        router: "0xD99D1c33F9fC3444f8101754aBC46c52416550D1",
        me: "0xAaE06F48e6559112D876eCcD6128FD4e5949c656"
    }
    

    const provider = new ethers.providers.WebSocketProvider("wss://speedy-nodes-nyc.moralis.io/api-key/bsc/testnet/ws");
    const wallet = new ethers.Wallet("private-key");
    const account = wallet.connect(provider);

    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)',
            'function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'
        ],
        account
    );

    const wbnbContract = new (await ethers).Contract(
        addresses.WBNB,
        [
            'function approve(address guy, uint wad) public returns (bool)'
        ],
        account
    );

    const amountIn = (await ethers).utils.parseUnits('0.1', "ether");
    const gas = {
        gasPrice: (await ethers).utils.parseUnits('50', 'gwei'),
        gasLimit: '500000'
    };


    const approveTx = await wbnbContract.approve(addresses.router, ethers.utils.parseUnits('1'), gas);
    const approveRecipt = await approveTx.wait();
    console.log(approveRecipt.transactionHash);


    const amounts = await router.getAmountsOut(amountIn, [addresses.WBNB, addresses.BUSD]);
    const amountOutMin = amounts[1].sub(amounts[1].div(10)); 
    
    
    const swapTx = await router.swapExactTokensForTokens(
        amountIn, 
        amountOutMin, 
        [addresses.WBNB, addresses.BUSD], 
        addresses.me,
        Date.now() + 1000 * 60 * 10,
        gas 
    );

    const swapReceipt = await swapTx.wait();
    console.log(swapReceipt);
    console.log("Swap success!!");
}

init();

swapExactTokensForTokens() メソッドを呼び出すときに、ファクトリ コントラクトから常にエラーが発生します。

{
  reason: 'transaction failed',
  code: 'CALL_EXCEPTION',
  transactionHash: '0xa09327a225a45e5edcf5fab6cf2d8701b5e0356149802a72372de7e11a0920ed',
  transaction: {
    nonce: 44,
    gasPrice: BigNumber { _hex: '0x0ba43b7400', _isBigNumber: true },
    gasLimit: BigNumber { _hex: '0x07a120', _isBigNumber: true },
    to: '0xD99D1c33F9fC3444f8101754aBC46c52416550D1',
    value: BigNumber { _hex: '0x00', _isBigNumber: true },
    data: '0x38ed1739000000000000000000000000000000000000000000000000016345785d8a00000000000000000000000000000000000000000000000000027fb3074bd8bec32700000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000aae06f48e6559112d876eccd6128fd4e5949c6560000000000000000000000000000000000000000000000000000017e71f4732e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000ae13d989dac2f0debff460ac112a837c89baa7cd00000000000000000000000078867bbeef44f2326bf8ddd1941a4439382ef2a7',
    chainId: 97,
    v: 230,
    r: '0x09c531c204781e81427901cff8d5d9055f9c45ba113bacb5534b26d8d2ea90cc',
    s: '0x763b947719c148c276786162f6e5549511c4144e97f9f433d84d6b235fa0d7b2',
    from: '0xAaE06F48e6559112D876eCcD6128FD4e5949c656',
    hash: '0xa09327a225a45e5edcf5fab6cf2d8701b5e0356149802a72372de7e11a0920ed',
    type: null,
    confirmations: 0,
    wait: [Function (anonymous)]
  },
  receipt: {
    to: '0xD99D1c33F9fC3444f8101754aBC46c52416550D1',
    from: '0xAaE06F48e6559112D876eCcD6128FD4e5949c656',
    contractAddress: null,
    transactionIndex: 0,
    gasUsed: BigNumber { _hex: '0x8358', _isBigNumber: true },
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    blockHash: '0x3bd5ea8d342b27a64ba74cd270599d4982c557391bf1c72157703d80bd739912',
    transactionHash: '0xa09327a225a45e5edcf5fab6cf2d8701b5e0356149802a72372de7e11a0920ed',
    logs: [],
    blockNumber: 15997793,
    confirmations: 1,
    cumulativeGasUsed: BigNumber { _hex: '0x8358', _isBigNumber: true },
    status: 0,
    type: 0,
    byzantium: true
  }
}

Bsc テストネットで ~2BNB を持っています。メインネットで同じスワップを試みましたが、同じエラーが発生しました。私は何を間違っていますか?

4

0 に答える 0