Beanstalk SDK
This is a JavaScript SDK for the Beanstalk web app.
The current version of the Beanstalk SDK is considered a beta release. The codebase is novel and has not been tested in the "real world" prior to use by Root and Paradox. Use of the Beanstalk SDK could result in loss of funds, whether due to bugs or misuse.
The SDK is dependent on Beanstalk, and therefore inherits all of the risks associated with Beanstalk. The security of Beanstalk is assumed. For an exhaustive list, consult the Beanstalk whitepaper and Beanstalk DAO Disclosures.
Using the SDK
Create an instance
import { BeanstalkSDK } from "@beanstalk/sdk";
const sdk = new BeanstalkSDK(options);
SDK contructor options:
const options = {
signer,
provider,
rpcUrl,
source,
DEBUG
};
options
object is optional. If ommited, SDK will use an ethers.getDefaultProvider()
- If
rpcUrl
is provided, SDK will use a WebSocketProvider
or JsonRpcProvider
, depending on the protocol in the url (ws
vs http
) - If
signer
is provided, sdk.provider
will be set to signer.provider
Library Exports
The following objects are available for import from the library:
import {
BeanstalkSDK,
Utils,
TokenValue
Token,
NativeToken,
ERC20Token,
BeanstalkToken,
Address,
ChainID
} from "@beanstalk/sdk";
Example
Swap 1.5 ETH to BEAN
const sdk = new BeanstalkSDK({ signer });
const fromToken = sdk.tokens.ETH;
const toToken = sdk.tokens.BEAN;
const account = signer.address;
const amount = sdk.tokens.ETH.amount(1.5);
const slippage = 0.1;
const swap = sdk.swap.buildSwap(fromToken, toToken, account);
const est = await swap.estimate(amount);
console.log(`You'd receive ${est.toHuman()} ${toToken.symbol}`);
const txr = await swap.execute(amount, slippage);
await txr.wait();
API Docs
View full API documentation