1

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?

Thanks!

1
  • 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 '21 at 1:22
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%

1
  • It worked, bro! Thanks a lot!
    – Niko
    May 13 '21 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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