Documentation

Deploying Uniswap V3 on BuildBear Sandbox

Step-by-step guide to deploy the full Uniswap V3 suite (factory, router, swap pools) in a BuildBear Sandbox for testing and custom protocol development.

BuildBear sandboxes let you fork mainnet or testnets into a private, stateful environment, ideal for spinning up protocols like Uniswap V3 from scratch, tweaking them, and running deterministic tests without spending real funds.

You will need to create a BuildBear sandbox first. If you haven't done so, please follow the guide below:

1. Initialize a Hardhat Project

Initialize a new Hardhat workspace with an empty Hardhat config:

mkdir uniswap-v3-sandbox
cd uniswap-v3-sandbox
npm init -y
npm install hardhat
npx hardhat
# • Choose “Create an empty hardhat.config.js”
# • Decline the sample project

2. Install Dependencies

Add Uniswap V3 packages, Hardhat plugins, and Ethereum utilities:

// package.json
{
  "name": "hardhat-project",
  "devDependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.2",
    "@nomiclabs/hardhat-waffle": "^2.0.1",
    "chai": "^4.3.4",
    "ethereum-waffle": "^3.4.0",
    "ethers": "^5.8.0",
    "hardhat": "^2.24.0"
  },
  "dependencies": {
    "@tokamak-network/tokamak-uniswap-v3-deploy": "^1.0.6-0.7",
    "dotenv": "^16.5.0",
    "hardhat-deploy": "^1.0.2",
    "install": "^0.13.0",
    "npm": "^11.4.0",
  }
}

3. Configure Hardhat

Edit hardhat.config.js to point at your BuildBear RPC and load your private key:

/** @type import('hardhat/config').HardhatUserConfig */
 
require("uniswap-v3-deploy-plugin");
require("hardhat-deploy");
require("@tokamak-network/tokamak-uniswap-v3-deploy");
require("dotenv").config();
 
module.exports = {
  solidity: "0.7.3",
  defaultNetwork: "hardhat",
  networks: {
    hardhat: {},
    buildbear: {
      url: process.env.BUILDBEAR_RPC,
      accounts: [process.env.PRIVATE_KEY],
    },
  },
};

4. Verify Hardhat Tasks

Run the Hardhat CLI to confirm the installation of deploy plugin, and to check if it is available in the list of tasks:

npx hardhat
 
 
AVAILABLE TASKS:
 
  check                    	Check whatever you need
  clean                    	Clears the cache and deletes all artifacts
  compile                  	Compiles the entire project, building all artifacts
  console                  	Opens a hardhat console
  deploy                   	Deploy contracts
  deploy-uniswap           	Deploys Uniswap V3 contracts
  etherscan-verify         	submit contract source code to etherscan
  export                   	export contract deployment of the specified network into one file
  export-artifacts         	
  flatten                  	Flattens and prints contracts and their dependencies. If no file is passed, all the contracts in the project will be flattened.
  help                     	Prints this message
  node                     	Starts a JSON-RPC server on top of Hardhat EVM
  run                      	Runs a user-defined script after compiling the project
  sourcify                 	submit contract source code to sourcify (https://sourcify.dev)
  test                     	Runs mocha tests
  tokamak-uniswap-v3-deploy	Deploys Uniswap V3 contracts

5. Environment Variables

Create a .env file in your project root:

BUILDBEAR_RPC=https://rpc.buildbear.io/{YOUR_SANDBOX_ID}
PRIVATE_KEY=your_private_key_here

6. Obtain Your Private Key

Each sandbox ships with a funded mnemonic. To extract the first account’s key:

cast wallet private-key "YOUR_MNEMONIC_HERE"

Copy the output into your .env as PRIVATE_KEY.


7. Deploy to BuildBear

With .env set, run:

npx hardhat tokamak-uniswap-v3-deploy --network buildbear

If setup correctly, the contracts should deploy on BuildBear Sandbox and following output will be displayed:

Your Uniswap V3 core and periphery contracts are now live in your sandbox, and are ready to be interacted with, to create pools, run tests, etc!


Why This Matters

Deploying a full Uniswap V3 stack in a BuildBear sandbox lets you:

  • Customize & fork: Tweak factory parameters, router fees, or pool logic before going live.
  • Test deterministically: Run complex scenarios repeatedly without affecting mainnet.
  • Speed up iteration: Launch fresh sandboxes in seconds, pre-funded and ready for on-chain debug tools.