desktop-arrow-downEnvironment Setup

Intro

In this step-by-step guide we'll walk through setting up a Hardhat development environment you can use to build the examples in the Guides section, or to start your own Algebra Integral integration.

You have two options: Quick Start — clone the boilerplate and jump straight to writing contracts, or Start from Scratch — build everything from the ground up.

Quick Start

The Algebra boilerplate repoarrow-up-right provides a Hardhat environment with the required Algebra packages already installed. Clone it and install the dependencies:

git clone https://github.com/cryptoalgebra/boilerplate
cd boilerplate
npm install

Then go to the Local Node with a Polygon Fork section below to complete setup and start building.

Start from Scratch

Prerequisites

Node.js v22 or later and NPM are required. If you haven't installed them yet:

Install Node.js and NPMarrow-up-right

Once installed, create a new directory and initialize a project:

Install Hardhat

Hardhatarrow-up-right is the Ethereum development toolset used for compiling, testing, and deploying contracts:

Initialize a Hardhat project:

When prompted, choose the JavaScript project template and accept the defaults.

This creates the standard folder structure: ./contracts for Solidity contracts, ./test for tests, and ./scripts for deployment scripts.

Install Algebra Packages

Add the Algebra Integral contracts as dependencies:

Install Hardhat Toolbox

Install the recommended Hardhat 3 bundle for Ethers.js and Mocha:

Update your hardhat.config.js to use the plugin:

Verify the Setup

To make sure the environment is set up correctly, try compiling a basic swap contract. Create ./contracts/Swap.sol and paste in the following:

Build it:

If successful you'll see:

Local Node with a Polygon Fork

Testing against live on-chain liquidity is critical but expensive. Hardhat lets you run a local Polygon fork for free.

As a prerequisite, you'll need an RPC that supports forking. Alchemyarrow-up-right includes this on its free tier.

Start the local fork node:

With the node running, use the --network localhost flag to run tests against it:

Next Steps

With your environment set up, head into the other guides to start building:

Last updated