Skip to main content

Getting Started

Overview

Pendle SDK is a typescript package to interact with the Pendle protocol.

Installation

With NPM:

npm i @pendle/sdk-v2

With Yarn:

yarn add @pendle/sdk-v2

Preparation

Pendle SDK is built on top of the Ethers.js library. To interact with the contracts using Ethers.js, first we need to prepare two things:

  • A provider, which is a connection to the Ethereum network.
  • A signer, which holds your private key and can sign things.

Typically, provider and signer that interacts with the Ethereum network via JSON-RPC can be created as follows:

import ethers from 'ethers';

const jsonRpcUrl = 'your-json-rpc-url';
const privateKey = 'your-private-key';
const provider = new ethers.providers.JsonRpcProvider(jsonRpcUrl);
const signer = new ethers.Wallet(privateKey, provider);

Please check the documentation of Ethers.js for the usage of provider and signer.

To demonstrate the usage of the SDK, we will use a prepared provider and some test accounts with filled balances in a local forked network. Check how you can try out the Pendle SDK in a local playgrond to see how they are created.

import ethers from 'ethers';
import { provider, testAccounts } from './sdk-doc-playground.mjs';

{
const address = testAccounts[0].address;
const ethBalance = ethers.utils.formatEther(await testAccounts[0].wallet.getBalance());
console.log('Test account info:', { address, ethBalance });
}

Output:

Test account info: {
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
ethBalance: '9959.796037708252906401'
}

Create Pendle SDK Router

Pendle SDK Router is an object that interacts with PendleRouter contract. It can be created as follows:

import { Router } from '@pendle/sdk-v2';

const router = Router.getRouter({
chainId: 1, // ethereum chain id
provider,
signer: testAccounts[0].wallet,
});

console.log('Router address:', router.address);

Output:

Router address: 0x0000000001e4ef00d069e71d6ba041b0a16f7ea0

Usage

Please check out the next guides for detailed explanation on using the Pendle SDK.

Other resources