Set Up Your Local Environment
This guide describes how to set up your environment using a specific toolset: Node.js
+ npm
+ hardhat
. It also shows you how to install the Uniswap V3 Periphery contracts, which are required for the contract examples in the Uniswap Docs V3 guides.
Once you have set up your environment, read the guides on liquidity mining, implementing swaps, and so on, which provide example contracts for those interactions.
Create a Node.js Project
Download and install Node.js and npm.
Create a new directory and navigate to it. Also, create a new node project with
npm init
.
- npm
- yarn
$ mkdir swap-example
$ cd swap-example
$ npm init
$ mkdir swap-example
$ cd swap-example
$ yarn init
Install Hardhat and the Periphery Contracts
- Install Hardhat, a development environment to compile, deploy, test, and debug your Smart Contracts.
- npm
- yarn
$ npm add --save-dev hardhat
$ yarn add --dev hardhat
- Install the V3 Periphery contracts so that you can inherit what you need from them in your Smart Contracts.
- npm
- yarn
$ npm add @uniswap/v3-periphery
$ yarn add @uniswap/v3-periphery
- Create a new hardhat config file, which you can use for compiling and testing contracts. For an example of how a typical smart contract repo is structure, select the "create a sample project" option during setup.
- npm
- yarn
$ npx hardhat
$ yarn hardhat
Set the Solidity Version for Hardhat
For this example, we'll need to change ./hardhat.config.js to include the appropriate solidity version for compiling the Uniswap V3 contracts. If you are using Hardhat's example project, you can skip this step.
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: '0.7.6',
}
Compile Your Contracts
- npm
- yarn
$ npx hardhat compile
$ yarn hardhat compile
If everything worked correctly, and you used hardhat's simple example project, you should see the following output:
Downloading compiler 0.8.4
Compiled 2 Solidity files successfully
✨ Done in 6.75s.