# 部署私有swap

By [leefbiant.eth](https://paragraph.com/@leefbiant) · 2022-04-01

---

1 安装ganache
-----------

docker run -itd --name ganache --detach --publish 8545:8545 trufflesuite/ganache:latest --host xxxxx

2 安装前端
------

git clone [https://github.com/Uniswap/uniswap-interface.git](https://github.com/Uniswap/uniswap-interface.git)

cd uniswap-interface

// for yarn

sudo apt remove yarn

curl -sS [https://dl.yarnpkg.com/debian/pubkey.gpg](https://dl.yarnpkg.com/debian/pubkey.gpg) | sudo apt-key add -

echo "deb [https://dl.yarnpkg.com/debian/](https://dl.yarnpkg.com/debian/) stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

sudo apt update && sudo apt install yarn

// for node

curl -fsSL [https://deb.nodesource.com/setup\_14.x](https://deb.nodesource.com/setup_14.x) | sudo -E bash -

sudo apt-get install -y nodejs

yarn

yarn start

// for 合约

git clone [https://github.com/Uniswap/uniswap-v2-core.git](https://github.com/Uniswap/uniswap-v2-core.git) git clone [https://github.com/Uniswap/uniswap-v2-periphery.git](https://github.com/Uniswap/uniswap-v2-periphery.git)

    mkdir uniswap-contracts
    cd uniswap-v2-core
    yarn && yarn compile
    cp -r build ../uniswap-contracts
    cd ..
    
    创建 deploy.js 
    const endpoint = '';
    const hexPrivateKey = '';
    修改这两个地址
    

    
    git clone https://github.com/Uniswap/uniswap-interface.git
    cd uniswap-interface && git checkout v2.6.5
    
    
    yarn
    
    下面的步骤中我们假设私有网络的名称为 PRIVNET，ChainId 是 1024，请根据自身情况进行替换。WETH 合约地址 0x5740F4E31A84FcB79720e807d022BD0833809e4A 请参考上一篇文章进行部署。
    
    打开 node_modules/@uniswap/sdk/dist/sdk.cjs.development.js 文件，找到 function (ChainId) 方法，在方法最后添加代码 ChainId[ChainId["PRIVNET"] = 1024] = "PRIVNET";。然后再找到全局对象 WETH，再里面添加 _WETH[exports.ChainId.PRIVNET] = new Token(exports.ChainId.PRIVNET, '0x5740F4E31A84FcB79720e807d022BD0833809e4A', 18, 'WETH', 'Wrapped ETH')。
    打开 node_modules/@uniswap/sdk/dist/sdk.esm.js 文件，找到 function (ChainId) 方法，在方法最后添加代码 ChainId[ChainId["PRIVNET"] = 1024] = "PRIVNET";。然后再找到全局对象 WETH，再里面添加 _WETH[ChainId.PRIVNET] = new Token(ChainId.PRIVNET, '0x5740F4E31A84FcB79720e807d022BD0833809e4A', 18, 'WETH', 'Wrapped ETH')。
    打开 src/components/Header/index.tsx 文件，在全局对象 NETWORK_LABELS 里面添加 [ChainId.PRIVNET]: 'Privnet'。
    打开 src/connectors/index.ts 文件，在 supportedChainIds 数组里面添加 ChainId 1024。
    打开 src/constants/index.ts 文件，在全局对象 WETH_ONLY 里面添加 [ChainId.PRIVNET]: [WETH[ChainId.PRIVNET]]。
    打开 src/constants/multicall/index.ts 文件，在全局对象 MULTICALL_NETWORKS 里面添加 [ChainId.PRIVNET]: '0xE4cB75D35af81EcCb44eB9521524C9C6f93440d2'，里面的地址是之前我们部署的 multicall 合约地址。
    打开 src/constants/v1/index.ts 文件，在全局对象 V1_FACTORY_ADDRESSES 里面添加 [ChainId.PRIVNET]: '0x0000000000000000000000000000000000000000'。
    打开 src/state/lists/hooks.ts 文件，在全局对象 EMPTY_LIST 里面添加 [ChainId.PRIVNET]: {}。
    打开 src/utils/index.ts 文件，在全局对象 ETHERSCAN_PREFIXES 里面添加 1024: ''。其中 1024 是私链的 ChainId。
    node_modules/@uniswap/sdk/dist/entities/token.d.ts 最后的export WETH

---

*Originally published on [leefbiant.eth](https://paragraph.com/@leefbiant/swap)*
