1

After installing Hardhat's npm package latest version following this brief guide and setting up my first 'sample project', i tried to create a script and deploy a contract on the BSC mainnet. I edited the hardhat.config.js file in order to do that in this way:

      module.exports = {
      defaultNetwork: "bnbmainnet",
      networks: {
        hardhat: {
        },
        bnbmainnet: {
          url: "https://bsc-dataseed1.defibit.io/",
          accounts: ["privateKey"]
        }
      },
      solidity: "0.7.6"
    };

I took the BSC JSON-RPC Endpoint from the ufficial page, so should be fine; i should also be under their requests limit of 8K/5min.

Then i took from here the Flashbot.sol script from here, which retrieves some pair infos (primarly price) from UniswapV2 fork on the BSC network and then successfully deployed it to mainnet.

The script i created to interact with the contract is this:


    const { ethers } = require('hardhat');
    
    const BNB_MAINNET = '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c';
    const BUSD_MAINNET = '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56';
    
    const pancake =
    {
        name : "pancakeswap",
        router: "0x10ed43c718714eb63d5aa57b78b54704e256024e",
        factory: "0xca143ce32fe78f1f7019d7d551a6402fc5350c73",
    };
    
    const knightswap = {
        name : "knightswap",
        router: "0x05E61E0cDcD2170a76F9568a110CEe3AFdD6c46f",
        factory: "0xf0bc2E21a76513aa7CC2730C7A1D6deE0790751f"
    };
    
    const dexes = [ pancake, babyswap, knightswap, biswap, bakeryswap];
    
    const pair = 
        {
            name: 'BNB to BUSD',
            amountTokenPay: ["0.1","0.5", "1", "2", "5", "10", "20", "50", "100","200", "500", "1000"],
            tokenPay: BNB_MAINNET,
            tokenSwap: BUSD_MAINNET
        }
    
    let flashswap, Flashswap, sign;
    
    (async () => {
    
        sign = await ethers.getSigner("signerAccount");
        
        Flashswap = await ethers.getContractFactory("Flashswap");
        
        flashswap = await new ethers.Contract("contractAddress", Flashswap.interface, sign);
    })();
    
    const init = async () => {
    
        pair.amountTokenPay.forEach(async (qnt) => {
        
            dexes.forEach(async (dex) => {
                try 
                {
                    if(dex != dexes[0]){
                        const check = await flashswap.check(pair.tokenPay, pair.tokenSwap, ethers.utils.parseUnits(qnt, 18), dexes[0].router, dex.router);
                        var profit = check[0]/10e18;
                        if(profit >= 0)
                            console.log(`pair: ${pair.name} -> ${dex.name}, amount: ${qnt}, profit: ${profit}.`);
                    }
                }
                catch (e)
                {
                    console.log("Something went wrong with the execution of check method. \n " + e);
                    process.exit(-1);
                }                    
            });
        });
    }
    
    ethers.provider.on("block", (blk) => {
        init();
    });

Essentally calling the check method of the contract for each new block created and doing some basic arbitrage operations. This code actually runs correctly, but no matter what, after a certain point it will throw the error:

Error: missing revert data in call exception; Transaction reverted without a reason 
string [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (data="0x", transaction=
{"from":"","to":"","data":"0xc08757bc000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9
173bc095c000000000000000000000000e9e7cea3dedca5984780bafc599bd69add087d560000000000000000000
000000000000000000000000000001bc16d674ec8000000000000000000000000000010ed43c718714eb63d5aa57
b78b54704e256024e000000000000000000000000cde540d7eafe93ac5fe6233bee57e1270d3e330f","accessLi
st":null}, error={"name":"ProviderError","code":-32603,"_isProviderError":true},
code=CALL_EXCEPTION, version=providers/5.6.8)

And i'm really struggling to understand what does that means; The last mentioned error -32603 according to the JSON-RPC specification means 'Internal JSON-RPC error.' which obviously can't help, nor the Hardhat error which is quite general too, so hope you can!

1
  • Looks like using a Websocket provider solved the issue. Jun 18, 2022 at 7:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.