Giter VIP home page Giter VIP logo

pancakeswap-frontend-hardhat-testnet's Introduction

A hardhat testnet environment base on pancake-frontend

Node Environment

(recommend)
nvm use 12

Install

sh install.sh

Serve

sh serve.sh

Deploy

sh deploy.sh

Start

sh start.sh

  • Note: Make sure the connected wallet address on PancakeSwap Frontend Page matches your deployed address.
  • Default deployed address: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

Running in the serve

If you plan to push your local project to the server:
Configuresrc/config/index.ts=>BASE_URLto address of the server

cd pancake-frontend
npm run build

local serve:

serve -s build -p 3000

Example

Image text Image text Image text

Configuration

If you want to try out the process of configuring Pancake-frontend for yourself and build your own testnet environment, the following will show you which files need to be modified:

Preparing source

  • Clonepancake-swap-core
git clone [email protected]:pancakeswap/pancake-swap-core.git  
yarn install  
yarn compile  
  • Clonepancake-swap-periphery
git clone [email protected]:pancakeswap/pancake-swap-periphery.git  
yarn install  
yarn compile  
  • Clonepancake-frontend
git clone [email protected]:pancakeswap/pancake-frontend.git  
yarn install  

tip: If you got a compilation error about: import @uniswap/v2-core/contracts/interfaces/IPancakePair.sol
Please refer to upchain

Setup

  • The source code for the contract address https://bscscan.com/address/your_address#code

In the pancake-swap-coredirectory

  • Install hardhatand edit PancakeFactory.sol;
    npm install --save-dev hardhat;
    npx hardhat (choose Create an empty hardhat.config.js);
  • Deploy tab => Select PancakeFactory -> Fill your address as feeToSetter in constructor -> Deploy
    creat
    scripts/deploy.js npx hardhat run scripts/deploy.js --network dev;
    Remember to save: INIT_CODE_PAIR_HASH;

In the pancake-swap-peripherydirectory

  • Install hardhatand edit PancakeRouter.sol file;
    npm install --save-dev hardhat;
    npx hardhat (choose Create an empty hardhat.config.js);
  • In the PancakeLibrary.sol to find pairForfunction,read INIT_CODE_PAIR_HASH -> Copy this hash without prefix 0x;
  • creat
    scripts/deploy.js npx hardhat run scripts/deploy.js --network dev (If you got an error about:error:max code size exceeded,set solidity->optimizer->runs to 200);

In the pancake-frontenddirectory

All the files that need to be modified:

/.env.development 
/.env.production
/src/config/constants/networks.ts
/src/config/constants/index.ts
/src/config/constants/tokens.ts
{
Local testnet(e.Hardhat):
/src/config/constants/lists.ts
/public/pancake-default.tokenlist.json
Other testnet:
/src/config/constants/lists.ts
/src/config/constants/tokenlists/pancake-default.tokenlist.json
}
/src/config/constants/contracts.ts
/scr/config/constants/farms.ts
/src/config/constants/pools.ts  
/src/config/constants/ifo.ts  
/src/config/constants/priceHelperLps.ts
/src/config/constants/types.ts
/src/config/index.ts
/src/config/constants/nftsCollections/index.ts

Switch to the pancake-swap-sdk directory, and modify the file

cd ../pancake-swap-sdk

Modify the file:

/src/constants.ts

and run:

$ pancake-swap-sdk/
npm run build
cp -r ./dist ./local-pancakeswap-libs/sdk/
cp -r ./local-pancakeswap-libs ../pancake-frontend/node_modules

The following is the specific content to be modified:

  • ethers.providers.StaticJsonRpcProvider(RPC_URL) is in the src/utils/providers.ts,that parameter is in the env.development of REACT_APP_NODE_PRODUCTION;
  • network url is in the PANCAKE-FRONTEND/src/config/constants/networks.ts;
  • testnet tokensconfiguration is in the src/config/constants/tokens.ts;
  • tokenlist in the src/config/constants/tokenlists/pancake-default.tokenlist.json(In order to facilitate local access, I copied it to public/, you can do the same;
  • PANCAKE_EXTENDEDPANCAKE_TOP100 is in the src/config/constants/lists.ts
  • The configuration of the wallet connection network is in the src/utils/wallet.ts
  • ROUTER_ADDRESS is in the src/config/constants/index.ts;
  • masterCheflotteryV2multiCall all these contract address are in the src/config/constants/contracts.ts
  • The configuration of the ABI and address are in the config/abi/, utils/addressHelpers, the reference in src/utils/contractHelpers.ts,src/hooks/useContract.ts
  • The configuration of the priceHelperLps are in the src/config/constants/priceHelperLps.ts;
  • In the src/config/constants/types.ts about addressneed to be modified;
  • In the src/state/farms/hooks.ts about useFarmFromPid(251)need to be modified;
  • src/utils/getTokenList.tsabout getting tokenlist, I modified intohttpto access. If you want to build project to serve, you may modify url into httpsto get tokenlist. Detailed see annotation that 42 line on src/utils/getTokenList.ts;
  • In the src/config/index.ts about BASE_BSC_SCAN_URLS,BASE_URL,BASE_BSC_SCAN_URLneed to be modified;
  • In the src/config/constants/nftsCollections/index.ts about addressneed to be modified;
  • farmpoolsifopricehelpercontracts all these about chainId need to be modified, which are in the
    src/config/constants/farm.ts
    src/config/constants/pools.ts
    src/config/constants/ifo.ts
    src/config/constants/pricehelper.ts
    src/config/constants/contract.ts
  • The configuration of FACTORY_ADDRESS_JSON and INIT_CODE_HASH_JSON are in the node_modules/local-pancakeswap-libs/sdk/dist/sdk.cjs.development.js, see pancakeswap-frontend-hardhat-testnet/depoly.sh => cp -r ./local-pancakeswap-libs ../pancake-frontend/node_modules;
    PS:
  1. If you want to change it
    set These parameters aboutFACTORY_ADDRESS_JSON INIT_CODE_HASH_JSON ChainId in pancakeswap-frontend-hardhat-testnet/pancake-swap-sdk/src/constants.ts and then
$ pancakeswap-frontend-hardhat-testnet/pancake-swap-sdk/:
npm run build  
cp -r ./local-pancakeswap-libs ../pancake-frontend/src/node_modules
  1. If you want to build frontend project and deploy on your server
    FACTORY_ADDRESS_JSON and INIT_CODE_HASH_JSON should be hard coded in pancakeswap-frontend-hardhat-testnet/pancake-swap-sdk/src/constants.ts.

pancakeswap-frontend-hardhat-testnet's People

Contributors

chobynleo avatar iamlqb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pancakeswap-frontend-hardhat-testnet's Issues

pancake-frontend Failed to compile

when I start the pancake-frontend, and the path of this " ../../../deployments/31337" is right, the error info is as follows

Failed to compile.

./src/config/constants/contracts.ts
Module not found: You attempted to import ../../../deployments/31337/AnniversaryAchievement.json which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.

deploy.sh errors

Compilation finished successfully
Error: Cannot find module '../../deployments/31337/SyrupBar.json'
Require stack:

  • /home/tcscat/Downloads/pancakeswap-frontend-hardhat-testnet-master/pancake-swap-core/scripts/deploy.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object. (/home/tcscat/Downloads/pancakeswap-frontend-hardhat-testnet-master/pancake-swap-core/scripts/deploy.js:2:22)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    Compiling 25 files with 0.6.6
    Compilation finished successfully
    Error: Cannot find module '../../../deployments/31337/INIT_CODE_PAIR_HASH.json'
    Require stack:
  • /home/tcscat/Downloads/pancakeswap-frontend-hardhat-testnet-master/pancake-swap-periphery/scripts/writeFile/writeFile.js
  • /home/tcscat/Downloads/pancakeswap-frontend-hardhat-testnet-master/pancake-swap-periphery/scripts/deploy.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object. (/home/tcscat/Downloads/pancakeswap-frontend-hardhat-testnet-master/pancake-swap-periphery/scripts/writeFile/writeFile.js:5:34)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)

Multicall error

Error: call revert exception (method="aggregate((address,bytes)[])", errorArgs=["Multicall aggregate: call failed"], errorName="Error", errorSignature="Error(string)", reason="Multicall aggregate: call failed", code=CALL_EXCEPTION, version=abi/5.4.0)

Error: sending a transaction requires a signer (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=contracts/5.4.0)

Deploy on BSC testnet

Hi, How to deploy pancakeswap smart contract on BSC testnet instead of local blockchain server?

deploy error

/tmp/build-1656468360807.sh: line 2: tsdx: command not found
cp: cannot stat './dist': No such file or directory

PancakeSwap pair reserves swapped for some reasons

Hi,
Thank you for your project. I have a question not connected with your repository directly, but could you help me?
Have you faced the problem when all hardhat tests worked fine but for some reason crashed because the PancakeSwap pair reserved swapped? So, if you change the reserves logic in the contract code tests work again.

I have been looking for the reason for this few weeks and can't find any explanation.

Thank you!

Unhandled Rejection (Error)

Hi, While sh start.sh localhost were unable to detect as baseurl.

Unhandled Rejection (Error): could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.4.1)
Logger.makeError
/workspace/pancakeswap-frontend-hardhat-testnet/src.ts/index.ts:213
Logger.throwError
/workspace/pancakeswap-frontend-hardhat-testnet/src.ts/index.ts:225
StaticJsonRpcProvider.<anonymous>
/workspace/pancakeswap-frontend-hardhat-testnet/src.ts/json-rpc-provider.ts:396
  393 | this.emit("debug", {
  394 |     action: "response",
  395 |     error: error,
> 396 |     request: request,
      | ^  397 |     provider: this
  398 | });
  399 | throw error;

The one-click deploy.sh script is faulty, causing front-end startup errors

deploy.sh error:

Error: ENOENT: no such file or directory, mkdir '/Users/cecilia-xiaoyu/code/pancakeswap-frontend-hardhat-testnet/deployments/31337'
at Object.mkdirSync (node:fs:1336:3)
at writeAddr (/Users/cecilia-xiaoyu/code/pancakeswap-frontend-hardhat-testnet/hardhat-token/scripts/artifact_log.js:19:8)
at main (/Users/cecilia-xiaoyu/code/pancakeswap-frontend-hardhat-testnet/hardhat-token/scripts/deploy.js:29:11)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
errno: -2,
syscall: 'mkdir',
code: 'ENOENT',
path: '/Users/cecilia-xiaoyu/code/pancakeswap-frontend-hardhat-testnet/deployments/31337'
}

Error: Cannot find module '../../deployments/31337/SyrupBar.json'
Require stack:

  • /Users/cecilia-xiaoyu/code/pancakeswap-frontend-hardhat-testnet/pancake-swap-core/scripts/deploy.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object. (/Users/cecilia-xiaoyu/code/pancakeswap-frontend-hardhat-testnet/pancake-swap-core/scripts/deploy.js:2:22)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)

.......

start.sh error :

./node_modules/local-pancakeswap-libs/sdk/dist/sdk.esm.js
Module not found: Can't resolve '../../../../../deployments/31337/INIT_CODE_PAIR_HASH.json' in '/Users/cecilia-xiaoyu/code/pancakeswap-frontend-hardhat-testnet/pancake-frontend/node_modules/local-pancakeswap-libs/sdk/dist'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.