Options
All
  • Public
  • Public/Protected
  • All
Menu

Stacks.js 1.4.1 Library Reference

stacks.js Test Action

This repo is home to the Stacks.js libraries which provide everything you need to work with the Stacks blockchain.

See README in each package directory for installation instructions and usage.

Importing & Polyfills

Most of the stacks.js packages are released in multiple different forms. These typically include:

  • commonjs under /dist

  • esm under /dist/esm

  • umd (with all dependencies bundled and polyfilled for the browser) under /dist/umd

  • an additional esm bundle (with external dependecies bundled and polyfilled for the browser) under /dist/polyfill

Build systems try to be smart and auto-detect the correct type. But you can specify which type to import as follows:

import { generateSecretKey } from '@stacks/wallet-sdk'; // auto-detect
import { generateSecretKey } from '@stacks/wallet-sdk/dist/polyfill'; // esm bundle
const walletSdk = require('@stacks/wallet-sdk'); // auto-detect
const walletSdk = require('@stacks/wallet-sdk/dist/umd'); // umd bundle
// ...

The following package types have been observed to work well out-of-the-box with common frameworks.

Framework Import Type
React /dist/umd
Next.js auto-detect
Vue /dist/umd
Svelte /dist/polyfill

For production builds it is recommended to configure the respective build system to optimize further. For more fine-grained control, import using esm and configure your build system to polyfill any necessary dependencies. You could also alias the packages to their /dist/<TYPE> alternative. E.g., if you are already polyfilling in webpack, add a resolve.alias section like this.

We are currently working to get rid of many dependencies to remove the need for complex configuration. For now, if you are seeing problems, try the /dist/umd import. Otherwise, open a new issue with details on your build setup.

We're currently seeing some problems with the /dist/polyfill of the @stacks/encryption package — use the /dist/umd imports here instead.

Migrating from blockstack.js

To migrate your app from blockstack.js to stacks.js follow the steps in the migration guide.

Development: environment setup

To setup the development environment for this repository, follow these steps:

  1. Clone this package.
  2. Run npm install to install dependencies
  3. Run npm run bootstrap to bootstrap project
  4. Run npm run build to build packages
  5. Run npm run test to run tests

Development: adding dependencies

This repo uses Lerna hoisting for package dependencies.

In order to install a new dependency to a package, the lerna add command must be used, rather than npm install <package>.

For example, the following command installs lodash as a dependency to the @stacks/storage package:

# Run within the root directory
npm run lerna -- add lodash --scope @stacks/storage

Add --dev to install as a development dependency:

npm run lerna -- add lodash --scope @stacks/storage --dev

Documentation

Documentation for the Stacks.js packages is located here.

Contributing

Github issues marked help-wanted are great places to start. Please ask in a github issue or discord before embarking on larger issues that aren't labeled as help wanted or adding additional functionality so that we can make sure your contribution can be included!

Generated using TypeDoc