Skip to main content

Getting Started

A TypeScript SDK for the Hyperdrive AMM.

The SDK has been designed to seamlessly integrate with multiple web3 libraries. Choose one below to get started:

Viem Quickstart

To use the Hyperdrive SDK with Viem:

Install

npm i viem @delvtech/hyperdrive-viem

Using the ReadHyperdrive

The ReadHyperdrive interface provides methods for fetching data and performing calculations with a public client.

import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
import { createReadHyperdrive } from "@delvtech/hyperdrive-viem";

// 1. Create a public client
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});

// 2. Create a ReadHyperdrive instance
const hyperdrive = createReadHyperdrive({
address: "0x...",
publicClient,
});

// 3. Get data from the contracts
const liquidity = await hyperdrive.getIdleLiquidity();

Using the ReadWriteHyperdrive

The ReadWriteHyperdrive interface extends ReadHyperdrive with additional methods for sending transactions with a wallet client.

import { createPublicClient, createWalletClient, custom, http } from "viem";
import { mainnet } from "viem/chains";
import { createReadHyperdrive } from "@delvtech/hyperdrive-viem";

// 1. Create a public client
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});

// 2. Create a wallet client
const client = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum!),
});

// 3. Create a ReadWriteHyperdrive instance
const hyperdrive = createReadWriteHyperdrive({
address: "0x...",
publicClient,
walletClient,
});

// 4. Send a transaction
const transactionHash = await hyperdrive.pause(true);

Ethers Quickstart

Coming soon!

Web3.js Quickstart

Coming soon!