https://github.com/nhancv/pancake-swap-testnet#readme

Preparing source
- Clone
pancake-swap-core
git clone [email protected]:pancakeswap/pancake-swap-core.git
cd pancake-swap-core
git checkout -b factory 3b214306770e86bc3a64e67c2b5bdb566b4e94a7
yarn install
yarn compile
- Clone
pancake-swap-periphery
git clone [email protected]:pancakeswap/pancake-swap-periphery.git
cd pancake-swap-periphery
git checkout -b router d769a6d136b74fde82502ec2f9334acc1afc0732
yarn install
yarn add @uniswap/[email protected]"file:../pancake-swap-core"
yarn compile
- Clone
pancake-swap-interface-v1
git clone [email protected]:pancakeswap/pancake-swap-interface-v1.git
cd pancake-swap-interface-v1
git checkout -b v1 0257017f2daaae2f67c24ded70b5829f74a01b3c
yarn install
Setup
Install contract merger: https://www.npmjs.com/package/sol-merger
npm install sol-merger -g
Prepare PancakeFactory
and PancakeRouter
sol-merger pancake-swap-core/contracts/PancakeFactory.sol ./build
sol-merger pancake-swap-core/contracts/PancakePair.sol ./build
sol-merger pancake-swap-periphery/contracts/PancakeRouter01.sol ./build
sol-merger pancake-swap-periphery/contracts/PancakeRouter.sol ./build
Deploy PancakeFactory
and PancakeRouter
Deploy WBNB
- New File: WBNB.sol => Copy source from https://gist.github.com/nhancv/b0b35f16472e4998d0fd17b7a1e4f707
- Compiler tab => Select compiler: v0.8.3+commit.8d00100c
- Deploy tab => Select WBNB -> Deploy
Deploy PancakeFactory
- New File: PancakeFactory.sol => Copy source from ./build/PancakeFactory.sol
- Compiler tab => Select compiler: v0.5.16+commit.9c3226ce
- Deploy tab => Select PancakeFactory -> Fill your address as feeToSetter in constructor -> Deploy
Deploy PancakeRouter01
- New File: PancakeRouter01.sol => Copy source from ./build/PancakeRouter01.sol
- Expand PancakeFactory deployed above -> Read INIT_CODE_PAIR_HASH -> Copy this hash without prefix
0x
. Ex: bb600ba95884f2c2837114fd2f157d00137e0b65b0fe5226523d720e4a4ce539 - Edit PancakeRouter01: Find PancakeLibrary -> pairFor function => Replace new hex by INIT_CODE_PAIR_HASH above. Ex:
hex'd0d4c4cd0848c93cb4fd1f498d7013ee6bfb25783ea21593d5834f5d250ece66'
-> hex’bb600ba95884f2c2837114fd2f157d00137e0b65b0fe5226523d720e4a4ce539′ - Compiler tab => Select compiler: v0.6.6+commit.6c089d02
- Deploy tab => Select PancakeRouter01 -> Fill PancakeFactory address and WBNB address as constructor params -> Deploy
Deploy PancakeRouter (Main Router)
- New File: PancakeRouter.sol => Copy source from ./build/PancakeRouter.sol
- Expand PancakeFactory deployed above -> Read INIT_CODE_PAIR_HASH -> Copy this hash without prefix
0x
. Ex: bb600ba95884f2c2837114fd2f157d00137e0b65b0fe5226523d720e4a4ce539 - Edit PancakeRouter: Find PancakeLibrary -> pairFor function => Replace new hex by INIT_CODE_PAIR_HASH above. Ex:
hex'd0d4c4cd0848c93cb4fd1f498d7013ee6bfb25783ea21593d5834f5d250ece66'
-> hex’bb600ba95884f2c2837114fd2f157d00137e0b65b0fe5226523d720e4a4ce539′ - Compiler tab => Select compiler: v0.6.6+commit.6c089d02; Check on
Enable optimization: 200
to avoidContract code size limit
issue - Deploy tab => Select PancakeRouter -> Fill PancakeFactory address and WBNB address as constructor params -> Deploy
Setup Frontend
- Update .env
cd pancake-swap-interface-v1
cp .env.development .env
- Update
PancakeRouter
address toROUTER_ADDRESS
atsrc/constants/index.ts
- Update support chain to testnet:
src/connectors/index.ts
- Change from
supportedChainIds: [56, 97]
tosupportedChainIds: [97]
- Change from
56
to97
- Change from
- Update
PancakeFactory
address and code hash toFACTORY_ADDRESS
andINIT_CODE_HASH
atnode_modules/@pancakeswap-libs/sdk/dist/constants.d.ts
,node_modules/@pancakeswap-libs/sdk/dist/sdk.cjs.development.js
,node_modules/@pancakeswap-libs/sdk/dist/sdk.cjs.production.min.js
andnode_modules/@pancakeswap-libs/sdk/dist/sdk.esm.js
- Update
PancakeFactory
address tov2 factory
;PancakeRouter01
address tov2 router 01
andPancakeRouter
address tov2 router 02
atsrc/state/swap/hooks.ts
- Update
WBNB
address atnode_modules/@pancakeswap-libs/sdk/dist/sdk.cjs.development.js
,node_modules/@pancakeswap-libs/sdk/dist/sdk.cjs.production.min.js
,node_modules/@pancakeswap-libs/sdk/dist/sdk.esm.js
- VERIFY CHANGES by
Find All
old addresses and replace new one:- WBNB: 0xaE8E19eFB41e7b96815649A6a60785e1fbA84C1e
- PancakeFactory: 0xBCfCcbde45cE874adCB698cC183deBcF17952812
- INIT_CODE_HASH: 0xd0d4c4cd0848c93cb4fd1f498d7013ee6bfb25783ea21593d5834f5d250ece66
- PancakeRouter01: 0xf164fC0Ec4E93095b804a4795bBe1e041497b92a
- PancakeRouter: 0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F
- Deploy your own tokens
- Deploy your own tokens and update info (token address + chainId to 97) to
src/constants/token/pancakeswap.json
- Remember update token icon with name as token address in lowercase mode to
public/images/coins
- Update support network from
ChainId.MAINNET
toChainId.BSCTESTNET
atsrc/constants/index.ts
- Update coin addresses to your at
src/constants/index.ts
- Update
src/components/Menu/index.tsx
: FrompriceData.data[CAKE.address].price
topriceData.data[CAKE.address]?.price ?? 0
- Update
src/hooks/useGetDocumentTitlePrice.ts
: FrompriceData.data[CAKE.address].price
topriceData.data[CAKE.address]?.price ?? 0
- Deploy your own tokens and update info (token address + chainId to 97) to
- Custom menu at
src/components/Menu/config.ts
Start and Build Frontend
- Start
yarn start
- Build
yarn build
Deployment
- WBNB: 0x0dE8FCAE8421fc79B29adE9ffF97854a424Cad09
- PancakeFactory: 0x5Fe5cC0122403f06abE2A75DBba1860Edb762985
- INIT_CODE_HASH: 0xbb600ba95884f2c2837114fd2f157d00137e0b65b0fe5226523d720e4a4ce539
- PancakeRouter01: 0x3E2b14680108E8C5C45C3ab5Bc04E01397af14cB
- PancakeRouter: 0xCc7aDc94F3D80127849D2b41b6439b7CF1eB4Ae0
- Frontend: https://pcs.nhancv.com
Tokens
- BAKE Token: 0xb289b361a633A9D2b0B39BAE76BB458d83f58CEC
- BUSD Token: 0xE0dFffc2E01A7f051069649aD4eb3F518430B6a4
- ETH Token: 0xE282a15DBad45e3131620C1b8AF85B7330Cb3b4B
- USDT Token: 0x7afd064DaE94d73ee37d19ff2D264f5A2903bBB0
- XRP Token: 0x3833B175Af1900b457cf83B839727AF6C9cF0bEe
- DAI Token: 0x3Cf204795c4995cCf9C1a0B3191F00c01B03C56C
- CAKE Token: 0xB8F5B50ed77596b5E638359d828000747bb3dd89
Thank you for your article. I have faced with unknown problem while deploying PancakeRouter (Main Router)
It shows smth like (testnet):
“`
Deploying ‘PancakeRouter’
————————-
> transaction hash: 0x8c5158a71173550a53f0e7a77ba0362e2f4e1d83a049f400327a44d6061dc7c4
Error: *** Deployment Failed ***
“PancakeRouter” — Cannot create instance of PancakeRouter; no code at address 0x73c8a3Bbd746E9C258859E4c744f27Ec21958f9e.
“`
and ‘no code at address’ part changing address everytime when I trying to deploy the contract.
I am using truffle in order to deploy to the testnet(binance testnet).
Hi,
Thank you for this amazing tutorial,
I have made the steps in this tutorial, but it seems that something is wrong, because the Cake token price is gotten from PancakeSwap when doing a simple swap between BNB to Cake.
Might I know why this problem is orruring please ???
King regards
Thank you. When I tried to run it in my own geth, I cannot deploy contracts with iUniswap interface, whenever I call:
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0xA166ddFA31756C8e66C9e2971D0DC843E9D68a60); // Router address deployed as per nhancv method
I get:
{
“code”: -32000,
“message”: “execution reverted”
}
Do you have any suggestion to me?
Hello,
I need of fond end like this:
https://exchange.zeroswap.io/swap
How many please?
Hello,
Thanks for your great information. Followed your guide and worked. May I ask what are the procedures to put it on the bsc main net (not testnet)?
For example:
supportedChainIds 97 back to 56?
switch .env to production one?
Thank you very much
Hey, thank you very much for your tutorial. I have a question how did you deploy the site? Can you make a tutorial also or point out how to do it? I really appreciate any help you can provide.