Why cant I add liquidity over bsc testnet using my own router and factory address

Hi. I posted the question before as well but it didnt solve my problem. I am trying to add liquidity on pancakeswap using this script. When I run the script using pancakeswap’s own router and factory address I am successful but when I try to do the same with the address on which my router and factory are deployed after running truffle migrate command I always get a hijacked stack error.

My script:

const Factory = artifacts.require(‘Factory.sol’);

const Router = artifacts.require(‘Router.sol’);

const Pair = artifacts.require(‘Pair.sol’);

const Token1 = artifacts.require(‘token1.sol’);

const Token2 = artifacts.require(‘token2.sol’);

module.exports = async done => {

try {

// const [admin, _] = await web3.eth.getAccounts();

const factory = await Factory.at('0x45c6a69001ff95B30043345BAD67Bf2aEA2636d6');

const router = await Router.at('0xd389468Ea139a8Ac8856c948C8AE0c3068AF84B2');

const token1 = await Token1.new();

const token2 = await Token2.new();

const pairAddress = await factory.createPair.call(token1.address, token2.address);

const tx = await factory.createPair(token1.address, token2.address);

await token1.approve(router.address, 10000);

await token2.approve(router.address, 10000);

await router.addLiquidity(








  Math.floor(Date.now() / 1000) + 60 * 10


const pair = await Pair.at(pairAddress);

const balance = await pair.balanceOf("0xe95745a8F4E3cDb1cF5bfFD4A94F0B249e99f489");

console.log('Pair address: ', pairAddress);

console.log(`balance LP: ${balance.toString()}`);

} catch (e) {





Factory address used: 0x45c6a69001ff95B30043345BAD67Bf2aEA2636d6
Router address used: 0xd389468Ea139a8Ac8856c948C8AE0c3068AF84B2

Link of the failed transaction

And this is the error that I get:

PS D:\Blockchain\Niftswap\createpool> truffle exec ./scripts/deploypool.js --network bscTestnet
Using network ‘bscTestnet’.

StatusError: Transaction: 0x1e1d1d673fb574409c68d517623dcd0c92299a2864752ebdb008193e7a096eee exited with an error (status 0).
at module.exports (D:\Blockchain\Niftswap\createpool\scripts\deploypool.js:18:18)
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
tx: ‘0x1e1d1d673fb574409c68d517623dcd0c92299a2864752ebdb008193e7a096eee’,
receipt: {
blockHash: ‘0xfba65866ea91a515192faca29b5a82c2598c1910274f68525c008713a33d1277’,
blockNumber: 8253409,
contractAddress: null,
cumulativeGasUsed: 344517,
from: ‘0xe95745a8f4e3cdb1cf5bffd4a94f0b249e99f489’,
gasUsed: 29040,
logs: ,
logsBloom: ‘0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000’,
status: false,
to: ‘0xd389468ea139a8ac8856c948c8ae0c3068af84b2’,
transactionHash: ‘0x1e1d1d673fb574409c68d517623dcd0c92299a2864752ebdb008193e7a096eee’,
transactionIndex: 4,
reason: undefined,
hijackedStack: ‘StatusError: Transaction: 0x1e1d1d673fb574409c68d517623dcd0c92299a2864752ebdb008193e7a096eee exited with an error (status 0). \n’ +
’ Please check that the transaction:\n’ +
’ - satisfies all conditions set by Solidity require statements.\n’ +
’ - does not trigger a Solidity revert statement.\n’ +
‘\n’ +
’ at Object.receipt (C:\Users\DELL\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\handlers.js:124:1)\n’ +
’ at runMicrotasks ()\n’ +
’ at processTicksAndRejections (internal/process/task_queues.js:97:5)\n’ +
’ at Function.start (C:\Users\DELL\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\override.js:49:1)’

@Yoshiko created a new post as you asked.

Are the factory and the router that you are using have correct contract code in them?

Checking both of them I do not see the code verified.

Your factory and your router should have verified code, as does Pancake Swap’s at


@Yoshiko I have verified both the router and factory contracts on bsc testnet now. The router address now is ‘0x73D58041eDdD468e016Cfbc13f3BDc4248cCD65D’ and the factory address now is ‘0x81338c4e7a7f30297aF1dd1dBF02Fc1299b0EA12’ so if you do test it, then test with the given addresses

Thanks! In the transaction you have linked, you are using addLiquidity. Not addLiquidityETH.

Did you try addLiquidityETH first as shown in the tutorial in the other thread? From the script I think you will need to do addLiquidityETH.

@Yoshiko I ran the script by runing the addLiquidityETH function and ran into the same error. Here is the link for the failed transaction https://testnet.bscscan.com/tx/0x077283d3fa77c51b9f7f517bfb817f998e15fff83712233746d6d87a548f5f05

Looking at your code I notice some things.

In PancakeRouter.sol

contract PancakeRouter is IPancakeRouter01 {

This should be

contract PancakeRouter is IPancakeRouter02 {

I also noticed that you commented out the Remove Liquidity Functions and the Swap functions.

I think in order to first build your own swapper, you should start from their base code and work your way up. Just copy and paste it, upload to a new address in its exactness, then get it to work, then make your modifications.

I just commented out supporting fee on transfer functions because otherwise the code was too long to be deployed and it kept giving me gas errors.

That’s really unusual. I highly recommend doing the hardhat tutorial and going through it. At the end of it you will have a dev environment set up where you can deploy easily and test easily. Perhaps there is something wrong in the configuration.

Okay after spending days on this issue I came to know that I was just changing the init_hash once before multiple deployments over testnet. The init_hash changes everytime, so you have to copy the init_hash from pancake pair file into pancake library each time. After doing so I was able to successfully add liquidity using my own router and factory address over bsc testnet.


this solved my problem too. thanks!

1 Like

i dont have anything called init_hash from pancake pair file. Am running into the same problem.
Firtly, How exactly should i calculate the init_hash? Can you please share example init_hash?
(I have INIT_CODE_PAIR_HASH in PancakeFactory though. When should i execute that code anyway?)
If i get it after deploying factory contract, i get ‘0xcfa13…’ noticeably starts with 0x and i can’t put in in hex’’.
Secondly, is it must to verify the contracts on bscscan testnet of deployed contracts?

Compile pancakeFactory.sol and then copy the value of INIT_CODE_PAIR_HASH. Paste this value in pairFor method located in pancakePair library. While pasting you have to omit the 0x and paste the rest of the hex value.
And no, it is not necessary to verify contracts. It’s your choice. The benefits of verifying a contract are that the people and specially developers can see the code of the smart contract they want to interact with and this develops trust.
Secondly, you can call the functions of the contract directly from there instead of using an IDE and that saves times.

1 Like

This solved the problem. Thanks!!!

1 Like

Hi all, I have try to deploy the factory and router, and I follow the explanation to change the INI_HASH on the router pairFor function. But I still can’t get it to work, and it still give me error execution reverted…
Can anyone share the working deployment on Testnet so that I can have a look?