Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@beanstalk/sdk

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beanstalk/sdk

A JavaScript framework for interacting with the Beanstalk protocol and ecosystem

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source
Beanstalk logo

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 = {
  // etherjs Signer. Optional
  signer,

  // etherjs Provider. Optional
  provider,

  // rpcUrl
  rpcUrl,

  // Data source for balances. Optional, either
  //  - DataSource.LEDGER (default)
  //  - DataSource.SUBGRAPH
  source,

  // bool, print debug output. default `false`
  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; // 0.1% : 0.1/100

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

Keywords

FAQs

Package last updated on 11 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc