React
Get started with AaveKit React
AaveKit React for Aave v4 is a collection of React hooks for building decentralized applications on top of the Aave Protocol v4.
Getting Started
To get started, follow the steps below.
Then, create an AaveClient instance that will be used to interact with the protocol.
client.ts
import { AaveClient } from "@aave/react";
export const client = AaveClient.create();You don't need to install the @aave/client package as it's already included and re-exported by the @aave/react package.
Next, wrap your app with the <AaveProvider> component and pass the client instance.
App.tsx
import { AaveProvider } from "@aave/react";
import { client } from "./client";
export function App() { return ( <AaveProvider client={client}> {/* Your application components */} </AaveProvider> );}That's it—you can now start using AaveKit React. Here's a basic example to fetch supported chains:
Example
import { useChains } from "@aave/react";
export function SupportedChains() { const { data: chains } = useChains();
return ( <div> <h2>Supported Chains</h2> {chains?.map((chain) => ( <div key={chain.id}> <h3>{chain.name}</h3> <p>Chain ID: {chain.chainId}</p> </div> ))} </div> );}Using Hooks
Hooks in the SDK follow clear usage patterns you can apply in your app.
Declarative Read Hooks
Declarative read hooks execute on render with the given inputs, refresh when inputs change, and update after successful write operations; Aave React read hooks support two modes: loading state and React Suspense.
- Loading State
- React Suspense
Handle loading state manually in your component:
Loading State
function ChainsList() { const { data, loading, error } = useChains();
if (loading) return <div>Loading…</div>;
if (error) return <div>Error: {error.message}</div>;
return ( <div> {data.map((chain) => ( <div key={chain.id}>{chain.name}</div> ))} </div> );}Pausable Reads
Aave React read hooks support pausing—a powerful pattern that lets you temporarily suspend data fetching until certain conditions are met. This is particularly useful when:
Waiting for user input (e.g., wallet connection, user address)
Conditional data loading (e.g., only fetch when a user is authenticated)
Dependent data (e.g., fetch user data only after chain selection)
Type safety is maintained by allowing nullish request parameters and returning a paused state, which clearly signals when a hook is inactive and lets TypeScript precisely narrow types between paused and active states.
Imperative Hooks
Imperative hooks return an execute function and a state object. These are tailored for when you need explicit control—like event handlers or multi‑step flows.
const [execute, state] = useImperativeHook();Read hooks that follow this pattern do not watch for updates. Prefer the imperative variant over the declarative one when you need on-demand, fresh data (e.g., in an event handler).
Execute Function
The execute function takes the hook arguments and, when awaited, yields a Result<T, E>.
Use isOk() and isErr() to check the outcome and narrow the type:
const result = await execute();
if (result.isOk()) { console.log("Result:", result.value);} else { console.error("Error:", result.error);}See the Result Objects section for more information about the Result object.
State Object
The state object provides information about the operation status:
const { called, data, error, loading } = state;Where:
called: true once the hook has run at least once.
data: last successful result of type T, otherwise undefined.
error: error of type E if the operation failed, otherwise undefined.
loading: true while the operation is in progress, otherwise false.
Integrations
AaveKit React includes first-class support for viem, ethers v6, Privy, Dynamic and thirdweb.
- Viem
- Ethers
- Privy
- Dynamic
- thirdweb
Ensure you have viem package installed in your project.
Send Aave Transactions
AaveKit React provides transaction hooks that handle protocol interactions like supply, borrow, withdraw, repay, and more.
There are two types of transaction hooks:
Simple transactions - single transactions that can be sent directly to the wallet
Complex transactions - transactions that could require approval beforehand
To send transactions, follow the steps below.
First, use the provider‑specific useSendTransaction hook to send transactions with the connected wallet.
const [sendTransaction, { loading, error }] = useSendTransaction(/* args */);It abstracts wallet differences and provides a consistent interface that interoperates with the other SDK hooks.
- Viem
- Ethers
- Privy
- Dynamic
- thirdweb
Import the useSendTransaction hook from the @aave/react/viem entry point and wire it up with the viem's WalletClient.
Viem
import { useSendTransaction } from "@aave/react/viem";import { useWalletClient } from "wagmi";
function MyComponent() { const { data: walletClient } = useWalletClient(); const [sendTransaction, sending] = useSendTransaction(walletClient);
// Use with transaction hooks…}The example uses wagmi to get the WalletClient from the connected wallet.
Then, instantiate the specific transaction hook for the operation you want to perform.
- Simple Transactions
- Complex Transactions
Call sendTransaction (from useSendTransaction) inside the simple‑transaction hook callback, as shown below.
Simple Transactions
const [sendTransaction, sending] = useSendTransaction(/* … */);const [prepare, preparing] = useSimpleTransaction((request) => sendTransaction(request));You can bail out of the operation at any point by calling the cancel(message) function.
Bail Out
const [execute, { loading, error }] = useSimpleTransaction( (request, { cancel }) => { if (window.confirm("Are you sure you want to continue?") === false) { return cancel("User cancelled the operation"); } return sendTransaction(request); });Finally, execute the hook.
- Simple Transactions
- Complex Transactions
In your callback, call the execute function with the operation arguments and handle the result accordingly.
Simple Transactions
const result = await execute(/* args */);
if (result.isErr()) { switch (result.error.name) { case "CancelError": // The user cancelled the operation return;
case "SigningError": console.error(`Failed to sign the transaction: ${result.error.message}`); break;
case "TimeoutError": console.error(`Transaction timed out: ${result.error.message}`); break;
case "TransactionError": console.error(`Transaction failed: ${result.error.message}`); break;
case "UnexpectedError": console.error(result.error.message); break; } return;}
console.log(result.value); // TxHashYou can also take a declarative approach by using the loading and error state objects to drive your UI.
function MyComponent() { // …
return ( <div> <button disabled={loading}> {loading ? "Sending…" : "Send Transaction"} </button>
{error && <p style={{ color: "red" }}>{error.message}</p>} </div> );}That's it—you now know the standard approach for handling Aave transactions with AaveKit React
Sign ERC-20 Permits
Some Aave operations support permit functionality using EIP-2612 signatures to authorize ERC-20 token transfers within the same transaction. The permit approach has a few benefits:
Single Transaction: Execute operations without separate approval transactions
Exact Amounts: Sign permissions for specific amounts instead of infinite approvals
Time Limited: Permits have deadlines for enhanced security
Permit is available for ERC-20 tokens that implement EIP-2612.
As with useSendTransaction, use the provider-specific useERC20Permit hook to sign ERC-20 permits.
- Viem
- Ethers
- Privy
- Dynamic
- thirdweb
Import the useERC20Permit hook from the @aave/react/viem entry point and wire it up with the viem's WalletClient.
Viem
import { useERC20Permit } from "@aave/react/viem";import { useWalletClient } from "wagmi";
function MyComponent() { const { data: walletClient } = useWalletClient(); const [signPermit, sending] = useERC20Permit(walletClient);
// Use with transaction hooks…}The example uses wagmi to get the WalletClient from the connected wallet.
Then, use the signPermit function as described in the specific operation guide.
Appendix
Result Objects
AaveKit uses a functional approach to error handling, it's based on Result<T, E> that represents one of two states:
Ok<T>: A successful result containing a value of type T
Err<E>: A failure containing an error of type E
Example
import { ok, err, Result } from "@aave/react";
function parseNumber(input: string): Result<number, string> { return isNaN(Number(input)) ? err(new Error("Invalid number")) : ok(Number(input));}With a Result<T, E>, you can use the convenient isOk() and isErr() methods to check the outcome and narrow the type.
const result = parseNumber("123");
if (result.isOk()) { console.log(result.value); // 123} else { console.error(result.error); // Error}This approach avoids reliance on try/catch blocks and promotes predictable, type-safe code by ensuring errors are handled explicitly.
AaveKit uses the NeverThrow library as underlying implementation for the Result object.
ResultAsync<T, E> is the async, thenable variant of Result<T, E>. Awaiting it resolves to a Result<T, E>.
import { ResultAsync } from "@aave/react";
function fetchUser(id: number): ResultAsync<{ name: string }, Error> { return ResultAsync.fromPromise( fetch(`/api/users/${id}`).then((r) => r.json()), () => new Error("Not found") );}
const result = await fetchUser(1);
if (result.isOk()) { console.log(result.value); // { name: "John" }} else { console.error(result.error); // Error}