Can't add liquidity on PancakeSwap with burnable ERC20 token

Hello, i created token using this code:

    pragma solidity ^0.6.2;

    import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/contracts/token/ERC20/ERC20.sol";

    contract Name is ERC20 {

        uint256 private _minimumSupply = 10000000000000 * (10 ** 18);

        /**
         * @dev Constructor that gives msg.sender all of existing tokens.
         */
        constructor () public ERC20( "Name", "NAME") {
            _mint(msg.sender, 1000000000000000 * (10 ** uint256(decimals())));
        }

        function transfer(address to, uint256 amount) public override returns (bool) {
            return super.transfer(to, _partialBurn(amount));
        }

        function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
            return super.transferFrom(from, to, _partialBurn(amount));
        }

        function _partialBurn(uint256 amount) internal returns (uint256) {
            uint256 burnAmount = _calculateBurnAmount(amount);

            if (burnAmount > 0) {
                _burn(msg.sender, burnAmount);
            }

            return amount.sub(burnAmount);
        }

        function _calculateBurnAmount(uint256 amount) internal view returns (uint256) {
            uint256 burnAmount = 0;

            // burn amount calculations
            if (totalSupply() > _minimumSupply) {
                burnAmount = amount.mul(2).div(100);
                uint256 availableBurn = totalSupply().sub(_minimumSupply);
                if (burnAmount > availableBurn) {
                    burnAmount = availableBurn;
                }
            }

            return burnAmount;
        }   
    }

But I can’t add liquidity on PancakeSwap, nothing happens when I click Supply (I tried this on TestNet)

2 Likes

You might want to look at some examples like safemoon, where they use the Uniswap/Pancakeswap router in order to correctly pair up the liquidity.

Have you been able to pair up a token without the burnable functionality?

1 Like

Yes, I added liquidity with other not-burnable tokens.

I don’t see anything outwardly wrong with your code. I can help debug, but I ran into a problem of my own.

I uploaded the contract to the testnet here.

But when I went to try out PancakeSwap on the Testnet I was very confused on the interface.

Can you help me understand what inputs I need to use for writing to these functions? If you can, I might be able to figure out the error and then help you debug what went wrong with the burn function.

How do I make a liquidity pair from here? Pancake Swap’s GUI Would not let me use BSC Test Net ha.

Hi, welcome!
So what is the error when you add liquidity on PancakeSwap? Could you please show me the failed transaction hash.

There is no error, PancakeSwap doesn’t even let me create a transaction. When I click Supply it loads for a second and then it returns to Supply again, without any Metamask notifications.

1 Like

Did you find the solution to this?
I have the same exact issue, I tried using the Safemoon contract too but nothing.

1 Like

Did you find a solution to this, having same issue.

@LSparkzwz I can assist with this.
I deployed a similar contract to SafeMoon and was able to create liquidity.

This assumes you have the SafeMoon tokens in your Wallet along with some BNB.

Step 1. Approval

First navigate to your contract’s “Write Contract” tab. I’ll use SafeMoon’s contract as an example. https://bscscan.com/token/0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3#writeContract

Connect to Web3

Using function 1. Approve, you are going to Approve the amount to allow Pancake Swap to spend for you.

spender (address) = Pancake Swap’s Router Address, for our example it will be 0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F for the live address.

amount (uint256) = The amount of token required. You will need to do some math to figure out what amount this needs to be. If you have 9 decimals, then to add 100 tokens, you would multiply 100 x 10^9 to get the amount you need to input here, 100,000,000,000.

Consult the screen shot below for guidance.

After making sure your parameters are correct, click Write

Then confirm if the transaction is valid.

Step 2. Create the LP Pair on Pancake Swap

Navigate to https://bscscan.com/address/0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F

Which is the Router Address for Pancake Swap.

Go to the Contract tab.

Connect to Web3

Assuming you are starting a brand new LP token, you will use function 2 “addLiquidityETH” and fill out the below functions.

addLiquidityETH = The amount of BNB you want to use when creating the LP.

token (address) = Your token’s contract address. If using a proxy, use the proxy address, not the implementation. We will use SafeMoon’s address as an example. 0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3

amountTokenDesired (uint256) = The amount of token required as done in the Approval step. 100,000,000,000.

amountTokenMin (uint256) = This should be the same as above. 100,000,000,000.

amountETHMin (uint256) = This should be the same as your input amount in addLiquidityETH.

to (address) = The address you want to send your LP tokens to, in general this will be your wallet.

deadline (uint256) = This is how long it should take for the transaction to take as a UnixTime stamp. If the transaction’s deadline hits, then it will revert. I normally give it a day. I create my UnixTime stamp from https://www.unixtimestamp.com/ see the below screenshot for guidance. The example timestamp I will use is 1619341416

See the below screenshot for guidance on using this function.

After making sure your parameters are correct, click Write

Then confirm if the transaction is valid.

NOTE - You can test this!

You can do this using BSC’s test net using Pancake’s Test Router Address, 0xD99D1c33F9fC3444f8101754aBC46c52416550D1.

You can also do this in for Uniswap on any testnet, I prefer Rinkeby. The Uniswap Test Router Address is 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, but you should verify with the actual Uniswap documentation that this is still true.

I hope this helps and it works, if it doesn’t then post screen shots with what the error says, and include your contract you are trying to do this with.

5 Likes

Thank you, but I think doing the same exact thing on testnet instead of mainnet, using 0xD99D1c33F9fC3444f8101754aBC46c52416550D1 as router and its respective factory address, doesn't work.

I'll test on Rinkeby later though and see how that goes.

I just tried it and was able to get it to work on the BSC Test net.
https://testnet.bscscan.com/tx/0x0966d6f938aa0108daefbbf0dc6a3faa66f4193bee3af79d98e68ea0be937e55 - Approval of 1000000000000 NIP, on Spender

0xD99D1c33F9fC3444f8101754aBC46c52416550D1 (Pancake Swap Router Test Net)
https://testnet.bscscan.com/tx/0x00300f4e23e8094919eb29463873d3b02cb06e72298b19a15ad618e7a81222d3 - Pairing of 1 BNB and NIP, using the same amount from the approval.

If you post your transactions I can see what the error is.

1 Like

@Yoshiko can we not add liquidity in pancakeswap if we use our own addresses of factory and router in BSC testnet?

I’m not sure I understand what you are asking.

You can manually add liquidity to Pancake Swap following the instructions I outlined.
You will need to change the BSC Router/Factory address depending on if you are in Live or Test.

LIVE BSC Router Address: 0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F
LIVE BSC Factory Address:0xfa249Caa1D16f75fa159F7DFBAc0cC5EaB48CeFf (?, not sure on this)

TEST BSC Router Address: 0xD99D1c33F9fC3444f8101754aBC46c52416550D1
TEST BSC Factory Address: 0x6725F303b657a9451d8BA641348b6761A6CC7a17

1 Like

Actually when I try to add liquidity on testnet using pancakeswap’s own router and factory address I am successful and get LP tokens in return. But if I try to do the same with the router and factory address generated by my code I always get hijacked stack error. This is the link to my question Unable to add liquidity to pancakeswap can you have a look please?

But if I try to do the same with the router and factory address generated by my code

What are these addresses? Please make a new topic for a new question. This is probably a different error in that your contract is making erroneous addresses.

I managed to add liquidity in BSC Testnet using your guide, but trying to use the pancakeswap gui in testnet to try a trade shows me there’s no liquidity.

2021-04-25_180437

This is the transaction to add liquidity: https://testnet.bscscan.com/tx/0xcf71e0697a8158507badf439281b20d4b34e5dbb0f952425756142de20932e3e
And this is the cake-LP: https://testnet.bscscan.com/token/0xb78bc6fb66234c5969dd5cf643eea9b8bd24233a

What’s weirder is that I tried to add liquidity using the GUI on pancake too, the transaction was accepted but it didn’t create any liquidity, it just ate 5 bnb: https://testnet.bscscan.com/tx/0x4c9bb166dba3c15486cd1bf67b6acfd89a264fe3980fbae7d4749e07967a3c33

I added liquidity like this:

And it sent my bnb there: 0x10ED43C718714eb63d5aA57B78B54704E256024E and that’s it.

I don’t know if there’s problems with Pancake at this point and that’s it, since when I first posted in this thread I couldn’t even add liquidity like you told me to.

1 Like

@LSparkzwz please have a look at my question as well Why cant I add liquidity over bsc testnet using my own router and factory address - #3 by Tsushima_Yoshiko

Thank you, now everything works well.

2 Likes

I don’t know if there’s problems with Pancake at this point and that’s it, since when I first posted in this thread I couldn’t even add liquidity like you told me to.

I think this is it, I wasn't aware that using the GUI on PancakeSwap for the testnet was up yet.

@LSparkzwz So does the GUI work for PancakeSwap on the testnet?

Glad to hear everything works though, what was the problem?

Remember that Pancakeswap is migrating to Router V2 so don’t forget to update router address

1 Like