A TypeScript SDK for the Hyperdrive AMM.
This is a foundational package. If you're looking to use the SDK. Checkout the list of binding packages below.
This package contains the core logic for interacting with the Hyperdrive contracts, but doesn't include a web3 library for communicating with a network. For this, we publish thin binding packages which seamlessly integrate the SDK with a specific web3 library and re-export everything from the core. This design enables us to be flexible in the web3 libraries (and even persistence layers) we support.
Use the Hyperdrive TypeScript SDK with your web3 library of choice:
Web3 Library | Package |
---|---|
Viem | @delvtech/hyperdrive-viem |
Ethers | @delvtech/hyperdrive-ethers (coming soon) |
Web3.js | @delvtech/hyperdrive-web3 (coming soon) |
To abstract away the web3 library, the SDK uses
@delvtech/evm-client. Each SDK binding
package uses a corresponding @delvtech/evm-client
binding package.
SDK binding package | EVM Client binding package |
---|---|
@delvtech/hyperdrive-viem |
@delvtech/evm-client-viem |
@delvtech/hyperdrive-ethers (coming soon) |
@delvtech/evm-client-ethers |
@delvtech/hyperdrive-web3 (coming soon) |
@delvtech/evm-client-web3 (coming soon) |
Find or create the evm-client package for the web3 library you want to support
and use it to create CachedReadContract
, CachedReadWriteContract
, and
Network
instances.
Viem ReadHyperdrive
example:
import { IHyperdrive } from "@delvtech/hyperdrive-artifacts/IHyperdrive";
import { ReadHyperdrive } from "@delvtech/hyperdrive-js-core";
import {
SimpleCache,
createCachedReadContract,
createNetwork,
} from "@delvtech/evm-client-viem";
import { Address, PublicClient } from "viem";
interface CreateReadHyperdriveOptions {
address: Address;
publicClient: PublicClient;
cache?: SimpleCache;
namespace?: string;
}
export function createReadHyperdrive({
address,
publicClient,
cache,
namespace,
}: CreateReadHyperdriveOptions): ReadHyperdrive {
// Create a new ReadHyperdrive using the evm-client bindings for Viem.
return new ReadHyperdrive({
contract: createCachedReadContract({
abi: IHyperdrive.abi,
address,
publicClient,
cache,
namespace,
}),
network: createNetwork(publicClient),
});
}