# How to fix Pancakeswap's Router address in Safemoon

**URL:** <https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113>\
**Category:** Guides and Tutorials\
**Tags:** safemoon\
**Created:** [May 11, 2021, 12:16pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113 "2021-05-11T12:16:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![FreezyEx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/freezyex/32/5498_2.png) [@FreezyEx](https://forum.openzeppelin.com/u/FreezyEx)\
**Post date:** [May 11, 2021, 12:16pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/1 "2021-05-11T12:16:41Z")

</div>

Hey guys, with Safemoon we discovered a huge problem. They hardcoded Pancake v1 Router so all the people that are trying to fork Safemoon will run into the same problem. If you want to leave it hardcoded, then just change it with Pancake v2 Router address 0x10ED43C718714eb63d5aA57B78B54704E256024E.  
Otherwise, if you want to avoid another time this situation... maybe with Pancake v3... you can add these lines of code.

```
//New Pancakeswap router version?
    //No problem, just change it!
    function setRouterAddress(address newRouter) public onlyOwner() {
       //Thank you FreezyEx
        IUniswapV2Router02 _newPancakeRouter = IUniswapV2Router02(newRouter);
        uniswapV2Pair = IUniswapV2Factory(_newPancakeRouter.factory()).createPair(address(this), _newPancakeRouter.WETH());
        uniswapV2Router = _newPancakeRouter;
    }

```

I didn't test it, so let me know if there are any problems. I hope it works 😁

---

<div class="post-metadata">

**Author:** ![Yoshiko](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/yoshiko/32/6858_2.png) [@Yoshiko](https://forum.openzeppelin.com/u/Yoshiko)\
**Post date:** [May 11, 2021, 9:54pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/2 "2021-05-11T21:54:41Z")

</div>

Great solution. Hope this gets more attention from people making clones.

---

<div class="post-metadata">

**Author:** ![martriay](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/martriay/32/20_2.png) [@martriay](https://forum.openzeppelin.com/u/martriay)\
**Post date:** [May 11, 2021, 10:03pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/3 "2021-05-11T22:03:19Z")

</div>

Thanks for sharing @FreezyEx! Just edited your post’s title so it says more to someone scrolling through the guides, please be mindful of it next time! 🙂

---

<div class="post-metadata">

**Author:** ![FreezyEx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/freezyex/32/5498_2.png) [@FreezyEx](https://forum.openzeppelin.com/u/FreezyEx)\
**Post date:** [May 11, 2021, 10:14pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/4 "2021-05-11T22:14:55Z")

</div>

Ups You are right, Sorry😁

---

<div class="post-metadata">

**Author:** ![bnwater](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/bnwater/32/10390_2.png) [@bnwater](https://forum.openzeppelin.com/u/bnwater)\
**Post date:** [May 12, 2021, 6:45pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/5 "2021-05-12T18:45:49Z")

</div>

Hey I randomly ran into this looking for a soluttion to using pancake swap on testnet. I can’t seem to add liquidity and have rand into errors like

`Error: Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" }`

I am able to create the pair successfully but i can’t add. I have even tried the safemoon code and still the same issue

---

<div class="post-metadata">

**Author:** ![FreezyEx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/freezyex/32/5498_2.png) [@FreezyEx](https://forum.openzeppelin.com/u/FreezyEx)\
**Post date:** [May 12, 2021, 7:13pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/6 "2021-05-12T19:13:49Z")

</div>

Please share more info. Did you approved the router address to use tokens?

---

<div class="post-metadata">

**Author:** ![bnwater](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/bnwater/32/10390_2.png) [@bnwater](https://forum.openzeppelin.com/u/bnwater)\
**Post date:** [May 12, 2021, 8:36pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/7 "2021-05-12T20:36:27Z")

</div>

Hey,

I’m now attempting with safemoon contract but i updated it to testnet with:

```
        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0xD99D1c33F9fC3444f8101754aBC46c52416550D1);

        uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
            .createPair(address(this), _uniswapV2Router.WETH());

        uniswapV2Router = _uniswapV2Router;

```

I’ve tried two ways, through here: [https://testnet.bscscan.com/address/0xD99D1c33F9fC3444f8101754aBC46c52416550D1#writeContract](https://testnet.bscscan.com/address/0xD99D1c33F9fC3444f8101754aBC46c52416550D1#writeContract)

and with the code itself, both don’t work

```
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) public {
    // approve token transfer to cover all possible scenarios
    _approve(address(this), address(uniswapV2Router), tokenAmount);

    // add the liquidity
    uniswapV2Router.addLiquidityETH{value: ethAmount}(
        address(this),
        tokenAmount,
        0, // slippage is unavoidable
        0, // slippage is unavoidable
        owner(),
        block.timestamp
    );
}

```

The error comes from the code above.

The pair is working as i can check for it but can’t add.

Even with the safemoon adding liquidity if the contract goes above `500000 * 10 **6 * 10** 9`, it won’t work because then it tells me that there isn’t enough liquidity, although, this makes sense because i never added any. Or? Should it just work regardless and add tthe BNB/SAFEMOON\>?

---

<div class="post-metadata">

**Author:** ![FreezyEx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/freezyex/32/5498_2.png) [@FreezyEx](https://forum.openzeppelin.com/u/FreezyEx)\
**Post date:** [May 12, 2021, 8:59pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/8 "2021-05-12T20:59:41Z")

</div>

to add liqudiity you have to go on router address

---

<div class="post-metadata">

**Author:** ![bnwater](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/bnwater/32/10390_2.png) [@bnwater](https://forum.openzeppelin.com/u/bnwater)\
**Post date:** [May 12, 2021, 9:06pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/9 "2021-05-12T21:06:27Z")

</div>

This is testnet pancake swap router address

```
Factory: 0x6725F303b657a9451d8BA641348b6761A6CC7a17

Router: 0xD99D1c33F9fC3444f8101754aBC46c52416550D1

```

Have you tried this in testnet?

The token i am building isn’t a copy of safemoon but it does include a pricing floor similar to safemoon so i need to be able to provide liquidity on demand

I figured since theres works, i could just copy it but i ran into the same issues

---

<div class="post-metadata">

**Author:** ![FreezyEx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/freezyex/32/5498_2.png) [@FreezyEx](https://forum.openzeppelin.com/u/FreezyEx)\
**Post date:** [May 12, 2021, 9:07pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/10 "2021-05-12T21:07:22Z")

</div>

yes \<i have testest on testnet

---

<div class="post-metadata">

**Author:** ![bnwater](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/bnwater/32/10390_2.png) [@bnwater](https://forum.openzeppelin.com/u/bnwater)\
**Post date:** [May 12, 2021, 9:13pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/11 "2021-05-12T21:13:36Z")

</div>

And you were able to add liquidity?

Can you share?

---

<div class="post-metadata">

**Author:** ![bnwater](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/bnwater/32/10390_2.png) [@bnwater](https://forum.openzeppelin.com/u/bnwater)\
**Post date:** [May 12, 2021, 11:52pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/12 "2021-05-12T23:52:40Z")

</div>

A quick update. I was able to create a pair on 2 test tokens i made with `createPair`

I then used the same thing but with `addLiquidityETH` but i get the same error. I’ve tried from remix, truffle, genache, and web3 through module.exports but i still get the same error…

`StatusError: Transaction: 0x000.... exited with an error (status 0)`

```
receipt: {
    blockHash: '0x000',
    blockNumber: 00...,
    contractAddress: null,
    cumulativeGasUsed: 2611469,
    from: '0x000',
    gasUsed: 2055052,
    logs: [],
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    status: false,
    to: '0xd99d1c33f9fc3444f8101754abc46c52416550d1',
    transactionHash: '0x000',
    transactionIndex: 1,
    type: '0x0',
    rawLogs: []
  },

```

I assume maybe pancake hasn’t set this up yet?

Did you add liquidity with WBNB/BNB or what? I’m super confused

---

<div class="post-metadata">

**Author:** ![coinzep](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@coinzep](https://forum.openzeppelin.com/u/coinzep)\
**Post date:** [May 13, 2021, 2:38am UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/13 "2021-05-13T02:38:50Z")

</div>

why do they use the multiple ‘uniswap’ references in the code when its clearly for pancakeswap though?

---

<div class="post-metadata">

**Author:** ![bnwater](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/bnwater/32/10390_2.png) [@bnwater](https://forum.openzeppelin.com/u/bnwater)\
**Post date:** [May 13, 2021, 2:58am UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/14 "2021-05-13T02:58:58Z")

</div>

Well yeah i’m trying to test on pancake testnet but i couldnt add liquidity so i grabbed safemoon since i new they’re doing it but same issues. so now im just using their file until i figure it out.

You able to addd liquidity to their testnet?

I was able to ddo it with 2 tokens i made together but not WBNB or BNB

---

<div class="post-metadata">

**Author:** ![FreezyEx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/freezyex/32/5498_2.png) [@FreezyEx](https://forum.openzeppelin.com/u/FreezyEx)\
**Post date:** [May 13, 2021, 7:13am UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/15 "2021-05-13T07:13:53Z")

</div>

Did you approbe Pancake Router?

---

<div class="post-metadata">

**Author:** ![FreezyEx](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/freezyex/32/5498_2.png) [@FreezyEx](https://forum.openzeppelin.com/u/FreezyEx)\
**Post date:** [May 13, 2021, 7:14am UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/16 "2021-05-13T07:14:17Z")

</div>

Because Pancake is Uniswap Fork

---

<div class="post-metadata">

**Author:** ![bnwater](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/bnwater/32/10390_2.png) [@bnwater](https://forum.openzeppelin.com/u/bnwater)\
**Post date:** [May 13, 2021, 8:47am UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/17 "2021-05-13T08:47:06Z")

</div>

> [@FreezyEx](#):
>
> approbe

Tried both uniswap and pancake.

Although i am having an issue in rinkbey adding liquidity manually into uniswap. I get

```
Something went wrong
RangeError: Division by zero
    at Function.value (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:46528)
    at t.get (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:31545)
    at new t (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:31890)
    at Function.t.fromFractionalAmount (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:32113)
    at t.r.divide (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:32772)
    at e.get (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:238684)
    at e.t.priceOf (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:235699)
    at https://app.uniswap.org/static/js/main.8d689671.chunk.js:1:525377
    at Object.Eo [as useMemo] (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:1485830)
    at t.useMemo (https://app.uniswap.org/static/js/4.5121d2e8.chunk.js:2:1405284)

```

I cant even launch safemoon on ropsten due to a gas issue. Unsure if it is remix or not.

This same error happens on kovan as well. If i use a normal erc20 like openzepp default, it works. I assume this may be some deflationary issue. although i can add liq on v3

---

<div class="post-metadata">

**Author:** ![boahs](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/boahs/32/5546_2.png) [@boahs](https://forum.openzeppelin.com/u/boahs)\
**Post date:** [May 17, 2021, 10:41am UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/18 "2021-05-17T10:41:20Z")

</div>

Great solution thanks for sharing this @FreezyEx😀

---

<div class="post-metadata">

**Author:** ![Isa\_O](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/isa_o/32/6171_2.png) [@Isa\_O](https://forum.openzeppelin.com/u/Isa_O)\
**Post date:** [May 17, 2021, 1:14pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/19 "2021-05-17T13:14:39Z")

</div>

> [@FreezyEx](#):
>
> ```auto
> function setRouterAddress(address newRouter) public onlyOwner() {
> IUniswapV2Router02 _newPancakeRouter = IUniswapV2Router02(newRouter);
> uniswapV2Pair = IUniswapV2Factory(_newPancakeRouter.factory()).createPair(address(this), _newPancakeRouter.WETH());
> uniswapV2Router = _newPancakeRouter;
> }
> 
> ```

The default address will be kept like this?

IUniswapV2Router02 \_uniswapV2Router =  
IUniswapV2Router02(0x10ed43c718714eb63d5aa57b78b54704e256024e);

---

<div class="post-metadata">

**Author:** ![Isa\_O](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/isa_o/32/6171_2.png) [@Isa\_O](https://forum.openzeppelin.com/u/Isa_O)\
**Post date:** [May 17, 2021, 1:16pm UTC](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113/20 "2021-05-17T13:16:11Z")

</div>

Which pancake testnet you are using? Link?

[Next page](https://forum.openzeppelin.com/t/how-to-fix-pancakeswaps-router-address-in-safemoon/8113.md?page=2)
