2.1.3-o • Published 1 year ago

@reach-sh/humble-sdk v2.1.3-o

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

HumbleSDK v2.0.0

A Javascript library for interacting with the HumbleSwap DEx.


Documentation

Documentation has moved here.


v2 Changes

v2 introduces a few changes and adds new functionality, including staking pools. Some functions may have been renamed: review changes in our changelog, and view our documentation for additional info.


Installing the SDK

Option 1. NPM (recommended)

The fastest way is to use npm:

$. npm i -s @reach-sh/humble-sdk

Option 2. Cloning the repo directly

To get started without NPM, you can clone and build the SDK from the repository.

# Clone the repository 
$. git clone https://github.com/reach-sh/humble-sdk.git

# Enter the directory with the repo (replace with path to your repository clone)
$. cd path/to/humble-sdk 

# and install dependencies (there aren't a lot)
$. npm install

# Build the SDK. Will output to a ./lib directory in the same folder as the 
# package.json file. This takes seconds and doesn't output anything to your terminal.
$. npm run build

You will know it is complete when your (terminal's) typing prompt reappears.\ Then, as a FINAL STEP, copy or move the new lib/ directory into your project. This will allow you to access it like any other JS module:

import { initHumbleSDK } from "path/to/lib";

Example Usage

Subscribing to a stream of Liquidity Pool data

import { subscribeToPoolStream, createReachAPI } from "@reach-sh/humble-sdk";

const stdlib = createReachAPI();
const acc = await stdlib.createAccount();

// Fetch existing streams and get notified when a new one is created
subscribeToPoolStream(acc, {
    // Pool ID (and id of pool tokens) received from contract.
    // Pool data has NOT been fetched yet.
    onPoolReceived: (info) => { 
        const [poolAddr, tokenAId, tokenBId] = info;
        // ... do something with data
     },

    // Pool and Token data has been received from network. 
    onPoolFetched: (result: FetchPoolTxnResult) => { 
        const { succeeded, poolAddress, data, message } = result;
        if (succeeded) // ... do something with data
     }
})

Swapping between a pair of tokens

Note: Swapping does not use routing. Read the docs to learn how to fetch pools for DEx operations.

import { calculateTokenSwap, performSwap } from "@reach-sh/humble-sdk";

const pool = / pool source /

// Calculate expected swap output const { tokenAId, tokenBId } = pool; const amountA = 100; const swap = calculateTokenSwap({ pool, swap: { amountA, tokenAId, tokenBId } });

// Perform swap const swapOpts = { poolAddress: pool.poolAddress, swap, pool }; const { data, message, succeeded } = await performSwap(acc, swapOpts); // if (succeeded) data == { amountIn: string; amountOut: string }

--- 

## Local Testing
The `humble-sdk` contains some helper scripts for running the SDK on a command line. See more [**here**](./cli/README.md)
2.1.3-b

1 year ago

2.1.3-d

1 year ago

2.1.3-c

1 year ago

2.1.3-f

1 year ago

2.1.3-e

1 year ago

2.1.3-h

1 year ago

2.1.3-g

1 year ago

2.1.3-j

1 year ago

2.1.3-i

1 year ago

2.1.3-l

1 year ago

2.1.3-k

1 year ago

2.1.3-n

1 year ago

2.1.3-m

1 year ago

2.1.3-o

1 year ago

3.0.0-beta.19

1 year ago

2.1.3

1 year ago

3.0.0-beta.18

2 years ago

3.0.0-beta.1

2 years ago

3.0.0-beta.3

2 years ago

3.0.0-beta.5

2 years ago

3.0.0-beta.4

2 years ago

3.0.0-beta.7

2 years ago

3.0.0-beta.6

2 years ago

3.0.0-beta.9

2 years ago

2.1.2

2 years ago

3.0.0-beta.8

2 years ago

2.1.1

2 years ago

2.1.1-beta.7

2 years ago

2.1.1-beta.8

2 years ago

3.0.0-beta.10

2 years ago

3.0.0-beta.11

2 years ago

3.0.0-beta.12

2 years ago

3.0.0-beta.13

2 years ago

3.0.0-beta.14

2 years ago

3.0.0-beta.17

2 years ago

2.1.1-beta.1

2 years ago

2.1.1-beta.2

2 years ago

2.1.1-beta.3

2 years ago

2.1.1-beta.4

2 years ago

2.1.1-beta.5

2 years ago

2.1.1-beta.6

2 years ago

2.1.1-beta.0

2 years ago

2.1.0-beta.1

2 years ago

2.1.0-beta.0

2 years ago

2.1.0-beta.3

2 years ago

2.1.0-beta.2

2 years ago

2.1.0-beta.5

2 years ago

2.1.0-beta.4

2 years ago

2.1.0-beta.7

2 years ago

2.1.0-beta.6

2 years ago

2.1.0-beta.8

2 years ago

2.0.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago