How to fix Pancakeswap's Router address in Safemoon

I am trying the function but truffle says this:

 TypeError: Immutable variables can only be initialized inline or assigned directly in the constructor.
        uniswapV2Pair = IUniswapV2Factory(_newPancakeRouter.factory()).createPair(address(this), _newPancakeRouter.WETH());

So it can not actually be changed by a function? Trying to find a solution which would work when pancake swaps to new version.

1 Like

Hi, putting your solution to constructor () public leads to ParserError: Expected '(' but got identifier function setRouterAddress(address newRouter) public onlyOwner() { ^--------------^

Can’t actually get it right, would be glad to hear some help, thanks

1 Like

i guess this expected to be in constructor as it says, but anyway leads to some errors

1 Like

Of course it is not supposed to be in a constructor. It is a separate function. But I am not a proper solidity dev (yet) and do not understand why it can not set a variable right now, going to google a little bit.

1 Like

Just remove “immutable” keyword

1 Like

check your syntax. You are doing something wrong

1 Like

Thank you, removing Immutable seems to be doing the trick. Can you please clarify what “immutable” means? Like, not changeable by function or something? Thanks in advance.

1 Like

Only read outside contructor and you can assign values only within contructor

4 Likes

Hi FreezyEx, Great post thanks, can you describe where in the contract is the best place to put this function or can we put it anywhere in the sol file? Newbie, learning by doing stuff!

I suggets to put it at the end

2 Likes

Fail with error ‘Pancake: PAIR_EXISTS’ when I try calling it after removing “Immutable” keyword. Any ideas?

I'm getting a checksum error in remix for v2 router, I'm assuming I can ignore this as have checked the address on BCScan site. Wont let me compile the contract actually
0x10ed43c718714eb63d5aa57b78b54704e256024e

just error for CAP LETTERS
0x10ED43C718714eb63d5aA57B78B54704E256024E

1 Like

Hi FreezyEx, the contract looks good and compiles to BSC live, however when I try to activate the function to change the router I get this strange error.

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error. { “code”: 3, “message”: “execution reverted: Pancake: PAIR_EXISTS”, “data”: "0x08c379a0000000…

Hi did you find a solution for this?

how you are calling the function? which parameter are you gving?

I tried in remix giving the the testnet address, also tried the V2 address so the same as the hardcoded version. Also tried on bsc write contract page.

it is normal that you get version because the router are not good

1 sec let me try setting it to the old router address, see if its to do with the router.

ok that seems to work, :frowning: however now realised its not possible to change it back to the V2 setting as its giving me the same error. I guess this is supposed to only change to a new setting once not back and forth.