0

I am trying to sell a token (DOBO). Buying DOBO is no problem and it goes through. But I cannot sell it. I get a failed transaction, but no error message on node.js (see https://bscscan.com/tx/0x2a1e3af0c800dc1280c5f5a7e45cdb1a8914f2dcd66a63cd44ba397411a30442). I have sufficient DOBO and sufficient BNB in my wallet. At first I thought it is because DOBO was not approved on Pancakeswap. I tried implementing approval in code (see below), but that didn't work. I eventually approved it manually, but I still get a failed sell transaction.

Why can't I approve the token sale? Why do I get an error when trying to sell the token?

Thanks for your help!

const ethers           = require('ethers');
const WSS              = "wss:/XXX" // NODE CONNECTION
const Seed             = 'XXX XXX'  // WALLET SEEDPHRASE
const recipientaddress = '0x8d25C18e2280A05aF12c2620388116Fb2a72a236' // WALLET ADDRESS
const routeraddress    = '0x10ed43c718714eb63d5aa57b78b54704e256024e' // PANCAKESWAP ROUTER
const amountIn         = ethers.utils.parseUnits('10', 'ether');      // SELL 10 DOBO
const minBuy           = ethers.utils.parseUnits('0',  'ether')       // NO MINIMUM
const shitCoin         = 'ae2df9f730c54400934c06a17462c41c08a06ed8'; // DOBO
const moneyToken       = 'bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'; // wBNB
const provider         = new ethers.providers.WebSocketProvider(WSS);
const wallet           = ethers.Wallet.fromMnemonic(Seed);
const account          = wallet.connect(provider);

const router = new ethers.Contract(
    routeraddress,
    ['function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'],
    account
  );

// APPROVE TOKEN
    const fullToken1 = ("0x"+shitCoin); // DOBO
    const approveToken = new ethers.Contract(
        fullToken1,
        [
          'function approve(address spender, uint amount) public returns(bool)',
        ],
        account
      );

      const init = async () => {
        const tx = await approveToken.approve(
          routeraddress, 
          '1000' // APPROVE TRADING 1000 DOBO?
        );
        const receipt = await tx.wait(); 
        console.log('Transaction receipt');
        console.log(receipt);
      }


      // SELL TOKEN
      router.swapExactTokensForTokens(
        amountIn, // 10 DOBO
        minBuy, // set to 0
        [shitCoin, moneyToken],
        recipientaddress,
        Date.now() + 1000 * 60 * 10,
        {
            gasPrice: ethers.utils.parseUnits('10', 'gwei'),
            gasLimit: '2100000'
        }
      )

2 Answers 2

1

You are approving only 1000 wei of DOBO but trying to swap 10 ether of DOBO (10*10^18).

Try changing the 1000 to amountIn in your approve tx.

5
  • Ah, that is great. Thank you. That also means I was trying to sell 10*10^18 DOBO although I only had ~92.000.000? When changing amountIn to amountIn = ethers.utils.parseUnits('10', 'gwei'); and changing the 1000 to amountIn as well I get a new error: "replacement fee too low (error={"code":-32000,"response":"{\"jsonrpc\":\"2.0\",\"id\":7,\"error\":{\"code\":-32000,\"message\":\"replacement transaction underpriced\"}}\n"}, method="sendTransaction", transaction="0xf8aa2585012a05f20082721c94ae2df9f [...]
    – LDK
    Commented Jan 5, 2022 at 15:10
  • A quick google search suggests that my gasPrice is too low, however, I doubt that given that it is currently set to 10 gwei.
    – LDK
    Commented Jan 5, 2022 at 15:20
  • I am not sure if you still have this problem, but if yes, increase the gasLimit. Anyway it won't be used fully and this should circumvent this error. Commented Jan 5, 2022 at 16:05
  • Richard helped me solve that issue. However, now I can only sell tiny bits of DOBO (like here: bscscan.com/tx/…) or the transaction fails (like here: bscscan.com/tx/…
    – LDK
    Commented Jan 5, 2022 at 18:23
  • Since DOBO takes fee on transfer, you need to use the router's swapExactTokensForTokensSupportingFeeOnTransferTokens function. [edit: ah, I see you already found this in another comment :)] Commented Jan 6, 2022 at 1:44
1

Additional to the answer from Kenzo.

Looking at the transaction you shared and the state of bsc it seems that you are approving the from transaction.

The internal tx fails when it tries to transfer DOBO from 0x8d25c18e2280a05af12c2620388116fb2a72a236 to 0xbe80839a3be4d3953d5588a60a11aeaed286b593.

Querying the allowance for this combination returns 0, therefore it looks like no allowance is set.

Also the init block which sets the allowance is never called in your snipped.

enter image description here

7
  • That's odd. I have manually enabled selling DOBO and manually selling on pancakeswap also works (bscscan.com/tx/…). However there it is bridging with BP-USD. Do you have an idea why the allowance is set to 0 although I have (1) manually enabled DOBO selling and also now (2) used the code (corrected using Kenzo's suggestion by replacing '1000' with amountIn?
    – LDK
    Commented Jan 5, 2022 at 15:17
  • Did you try adjusting the address in the allowance function and making sure that init is called?
    – Richard
    Commented Jan 5, 2022 at 15:26
  • I am a noob. How do I do that?
    – LDK
    Commented Jan 5, 2022 at 15:30
  • gist.github.com/rmeissner/55d7b1b8ad2923332f6f4b99a2bd4e32 I also adjusted the decimals, as DOBO only has 9, but you used ether with is a synonym for 18 decimals.
    – Richard
    Commented Jan 5, 2022 at 15:37
  • 1
    I got it to work. Because there is a selling fee for DOBO, you need to use swapExactTokensForTokensSupportingFeeOnTransferTokens instead of swapExactTokensForTokens.
    – LDK
    Commented Jan 5, 2022 at 21:08

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.