title: Transaction exited with an error (status 0)
body: <p>I am trying to make a few transactions on binance test net using a script in solidity and truffle. The contracts are just a clone of pancakeswap. My script basically adds liquidity to a pool. I was able to successfully compile and execute the script once. When I tried to do it again on different addresses for router and factory it gave me the following error:</p>
  <pre><code>StatusError: Transaction: 0xc94424b8c6037e75e0eaf5f21982e2f73f88e71e18e0e5e783c642d6210e686f exited with an error (status 0). 
      at module.exports (D:\Blockchain\pancake\createpool\scripts\deploypool.js:18:18)
      at runMicrotasks (&lt;anonymous&gt;)
      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
    tx: '0xc94424b8c6037e75e0eaf5f21982e2f73f88e71e18e0e5e783c642d6210e686f',
    receipt: {
      blockHash: '0xc4bea040096811e809c18216d85fc82813b60db9545d4e1bf6ab7c4dd344fe87',
      blockNumber: 8023495,
      contractAddress: null,
      cumulativeGasUsed: 699140,
      from: '0xe95745a8f4e3cdb1cf5bffd4a94f0b249e99f489',
      gasUsed: 29046,
      logs: [],
      logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
      status: false,
      to: '0x7632ae832440032fb4ca93e56873a92a01b06e13',
      transactionHash: '0xc94424b8c6037e75e0eaf5f21982e2f73f88e71e18e0e5e783c642d6210e686f',
      transactionIndex: 2,
      rawLogs: []
    },
    reason: undefined,
    hijackedStack: 'StatusError: Transaction: 0xc94424b8c6037e75e0eaf5f21982e2f73f88e71e18e0e5e783c642d6210e686f exited with an error (status 0). \n' +
      '     Please check that the transaction:\n' +
      '     - satisfies all conditions set by Solidity `require` statements.\n' +
      '     - does not trigger a Solidity `revert` statement.\n' +
      '\n' +
      '    at Object.receipt (C:\\Users\\DELL\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\contract\\lib\\handlers.js:124:1)\n' +
      '    at runMicrotasks (&lt;anonymous&gt;)\n' +
      '    at processTicksAndRejections (internal/process/task_queues.js:97:5)\n' +
      '    at Function.start (C:\\Users\\DELL\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\contract\\lib\\override.js:49:1)'
  </code></pre>
  <p>My <strong>truffle-config.js</strong>:</p>
  <pre><code>//SPDX-License-Identifier: MIT 
  require('dotenv').config();
  var HDWalletProvider = require(&quot;truffle-hdwallet-provider&quot;);
  
  const infuraKey = process.env.infuraKey;
  const mnemonic = process.env.mnemonic;
  
  module.exports = {
  
    networks: {
      // Useful for testing. The `development` name is special - truffle uses it by default
      // if it's defined here and no other network is specified at the command line.
      // You should run a client (like ganache-cli, geth or parity) in a separate terminal
      // tab if you use this network and you must also set the `host`, `port` and `network_id`
      // options below to some value.
      //
      development: {
        host: &quot;127.0.0.1&quot;,     // Localhost (default: none)
        port: 8545,            // Standard Ethereum port (default: none)
        network_id: &quot;*&quot;,       // Any network (default: none)
      },
      rinkeby: {
        provider: function () {
          return new HDWalletProvider(mnemonic, &quot;https://rinkeby.infura.io/v3/&quot; + infuraKey);
        },
  
        network_id: 4,
        gas: 4500000,
        gasPrice: 10000000000,
      },
  
      bscTestnet: {
        provider: () =&gt; new HDWalletProvider(
          mnemonic,
          'https://data-seed-prebsc-1-s1.binance.org:8545'
        ),
        from: '0xe95745a8F4E3cDb1cF5bfFD4A94F0B249e99f489',
        network_id: 97,
        gas: 4500000,
        gasPrice: 10000000000,
        skipDryRun: true
      },
      mainnet: {
        provider: () =&gt; new HDWalletProvider(
          mnemonic,
          'https://bsc-dataseed.binance.org/'
        ),
        network_id: 56,
        gas: 4500000,
        gasPrice: 10000000000,
        skipDryRun: true
      }
  
    },
  
    mocha: {
      // timeout: 100000
    },
  
    // Configure your compilers
    compilers: {
      solc: {
        version: &quot;0.8.0&quot;,    // Fetch exact version from solc-bin (default: truffle's version)
        // docker: true,        // Use &quot;0.5.1&quot; you've installed locally with docker (default: false)
        // settings: {          // See the solidity docs for advice about optimization and evmVersion
        //  optimizer: {
        //    enabled: false,
        //    runs: 200
        //  },
        //  evmVersion: &quot;byzantium&quot;
        // }
      },
    },
  };
  </code></pre>
  <p>The <strong>liquidity functions</strong> in contract</p>
  <pre><code>// **** ADD LIQUIDITY ****
      function _addLiquidity(
          address tokenA,
          address tokenB,
          uint amountADesired,
          uint amountBDesired,
          uint amountAMin,
          uint amountBMin
      ) private returns (uint amountA, uint amountB) {
          // create the pair if it doesn't exist yet
          if (INiftFactory(factory).getPair(tokenA, tokenB) == address(0)) {
              INiftFactory(factory).createPair(tokenA, tokenB);
          }
          (uint reserveA, uint reserveB) = NiftLibrary.getReserves(factory, tokenA, tokenB);
          if (reserveA == 0 &amp;&amp; reserveB == 0) {
              (amountA, amountB) = (amountADesired, amountBDesired);
          } else {
              uint amountBOptimal = NiftLibrary.quote(amountADesired, reserveA, reserveB);
              if (amountBOptimal &lt;= amountBDesired) {
                  require(amountBOptimal &gt;= amountBMin, 'NiftRouter: INSUFFICIENT_B_AMOUNT');
                  (amountA, amountB) = (amountADesired, amountBOptimal);
              } else {
                  uint amountAOptimal = NiftLibrary.quote(amountBDesired, reserveB, reserveA);
                  assert(amountAOptimal &lt;= amountADesired);
                  require(amountAOptimal &gt;= amountAMin, 'NiftRouter: INSUFFICIENT_A_AMOUNT');
                  (amountA, amountB) = (amountAOptimal, amountBDesired);
              }
          }
      }
      function addLiquidity(
          address tokenA,
          address tokenB,
          uint amountADesired,
          uint amountBDesired,
          uint amountAMin,
          uint amountBMin,
          address to,
          uint deadline
      ) external override ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) {
          (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);
          address pair = NiftLibrary.pairFor(factory, tokenA, tokenB);
          TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA);
          TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB);
          liquidity = INiftPair(pair).mint(to);
      }
  </code></pre>
  <p>My <strong>deploypool.js</strong> script:</p>
  <pre><code>const Factory = artifacts.require('Factory.sol');
  const Router = artifacts.require('Router.sol');
  const Pair = artifacts.require('Pair.sol');
  const Token1 = artifacts.require('token1.sol');
  const Token2 = artifacts.require('token2.sol');
  
  module.exports = async done =&gt; {
    try {
      //const [admin, _] = await web3.eth.getAccounts();
      const factory = await Factory.at('0x78A47245BC7BDaa0DB7c19b7B6116E1E11e9fE20');
      const router = await Router.at('0xE1672640636a56E2905B8a303224b65A605286CF');
      const token1 = await Token1.new();
      const token2 = await Token2.new();
      const pairAddress = await factory.createPair.call(token1.address, token2.address);
      const tx = await factory.createPair(token1.address, token2.address);
      await token1.approve(router.address, 10000);
      await token2.approve(router.address, 10000);
      await router.addLiquidity(
        token1.address,
        token2.address,
        9000,
        9000,
        10000,
        10000,
        mymetamaskaddress,
        Math.floor(Date.now() / 1000) + 60 * 10
      );
      const pair = await Pair.at(pairAddress);
      const balance = await pair.balanceOf(&quot;0xe95745a8F4E3cDb1cF5bfFD4A94F0B249e99f489&quot;);
      console.log(`balance LP: ${balance.toString()}`);
    } catch (e) {
      console.log(e);
    }
    done();
  };
  </code></pre>