I'm trying to swap at Ropsten network some tokens for testing purposes, but I'm getting the following error: Cannot estimate gas. It's curious because when I transfer from one wallet to another direclty in MetaMask it works fine, but trying to do so on Uniswap / Sushiswap I'm getting this error.

Transfer and TransferFrom functions are the following:

      function transfer(address _to, uint256 _value) returns (bool success) {
         if (balances[msg.sender] >= _value && _value > 0) {
               balances[msg.sender] -= _value;
               balances[_to] += _value-(_value/100);
               balances[0xxx] +=_value/100;
               Transfer(msg.sender, _to, _value-(_value/100));
               Transfer(msg.sender, 0xxx, _value/100);
           return true;
       } else { return false; }

   function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
      if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
            balances[_to] += _value-(_value/100);
            balances[0xxx] += _value/100;
            balances[_from] -= _value;
            allowed[_from][msg.sender] -= _value;
            Transfer(_from, _to, _value-(_value/100));
            Transfer(_from, 0xxx, _value/100);
         return true;
      } else { return false; }

I understand that this is happening as the transaction is looking to do two transfers, one for the "To" account and another one for another account (mentioned as "0xxx). Curious fact: it works fine when I add liquidity to the token.

Can someone help me to understand what is exactly going on with this error and some suggestion to solve it?


  • Has someone know if in this case is better to split the contract into two contracts so each contract has its own address, and we can make calls between them? My concern in this case is that the process is working fine on direct transfer from one wallet to another, but not in the DEx..
    – Niko
    May 4, 2021 at 1:22

1 Answer 1


thats because all the decimals in your coins. Try to for example if you have 9,343,343,432 coins. Make it 9,343,000,000 something like that and change your slippage tolerance to something like 5.5%


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.