Solidity

Get started with the Aave smart contracts


The Aave smart contract interfaces provide methods for interacting with Aave Protocol v4. They enable lending, borrowing, and collateral workflows inside custom integrations. We recommend using Foundry for Solidity development.

For those beginning a new project, the Foundry boilerplate tailored for Aave v4 is highly recommended. It offers a foundational setup for efficiently deploying and testing smart contracts that integrate with the protocol.

Included in the boilerplate are:

  • /src: A sample smart contract demonstrating how to fetch user positions.

  • /script: Deployment scripts for your contracts.

  • /test: Example tests for your contracts.

  • foundry.toml: A Foundry configuration file customized for Aave v4.

Install or update Foundry:

curl -L https://foundry.paradigm.xyz | bashfoundryup

Then, follow these steps to get started:

1

Clone the Repository

Clone the boilerplate repository into a new project directory:

git clone https://github.com/aave/aave-v4-foundry-template.git my-projectcd my-project

2

Install Dependencies

Install the project dependencies:

forge install

3

Setup Environment

Create .env file from the .env.example template:

cp .env.example .env

and populate the required environment variables:

PRIVATE_KEY=0x…

Usage

The project includes several Foundry commands designed to streamline your workflow:

  • forge build: Compiles the contracts.

  • forge test: Executes tests.

  • forge script <script-path>: Deploys contracts using deployment scripts.

  • forge clean: Removes build artifacts from the project.

  • forge fmt: Formats the Solidity code.

Example Deployment

To deploy the example UserPositions contract:

forge script script/Deploy_UserPositions.s.sol:DeployUserPositions \  --sig "run(address)" <SPOKE_ADDRESS> \  --rpc-url $RPC_URL \  --private-key $PRIVATE_KEY \

Advanced

Add to Existing Project

If you have an existing Foundry project and want to add Aave v4 contracts, install the dependency:

forge install aave/aave-v4

Update remappings.txt for imports to resolve correctly:

aave-v4/=lib/aave-v4/forge-std/=lib/forge-std/src/

Then explore the Solidity section in the rest of the documentation for integration examples.