Stacks.js Overview
Stacks.js is an SDK for building on the Stacks blockchain. It's a collection of various JavaScript libraries allowing developers to interact with the Stacks blockchain or allow their users to.
There are two main ways developers build applications on the Stacks blockchain:
- 🔒 Without Direct Private Key Access: For example, a web app that allows users to interact with the Stacks blockchain using their Stacks wallet (browser extension or mobile). Read More in the Connect Guide
- 🔑 With Private Key Access: For example, managing funds with the Stacks.js CLI, building a backend (which can sign transactions directly).
Most users interact via their favorite Stacks wallet. Developers can build web apps, which prompt the user for an action (e.g. sign a transaction), and then the wallet will handle the rest. The wallet will act in the security, and best interest of the user, and the user will be able to review the transaction before signing.
Nevertheless, direct private key access is needed for some use cases. Developers can build simple scripts and tools intended for "offline" use. Users may use the Stacks.js CLI directly to send a transaction. Backends may need to automate signing without direct user interaction. In these cases, developers can use the same libraries used by Stacks wallets for account handling and transaction signing.
There are three main integrations used by Stacks enabled applications:
- Authentication: Register and sign users in with identities on the Stacks blockchain
- Transaction signing: Prompt users to sign and broadcast transactions to the Stacks blockchain
- Data storage: Save and retrieve data for users with Gaia
All three of these integrations can be used together to create powerful new user experiences that rival or exceed those of traditional apps while protecting your users' digital rights.
Stacks.js starters offer working templates with Stacks Connect pre-installed for a quick and easy way to get started with building Stacks enabled web apps.
References
Below is a list of all Stacks.js libraries and a few JS libraries and helpers maintained by Hiro:
Connecting Wallets
@stacks/connectConnect web application to Stacks wallet browser extensions. Github
Stacks Primitives
@stacks/transactionsConstruct, decode transactions and work with Clarity smart contracts on the Stacks blockchain. Github@stacks/wallet-sdkLibrary for building wallets, managing accounts, and handling keys for the Stacks blockchain. Github@stacks/storageStore and fetch files with Gaia, the decentralized storage system. Github@stacks/encryptionEncryption functions used by stacks.js packages. Github@stacks/authConstruct and decode authentication requests for Stacks apps. Github@stacks/profileFunctions for manipulating user profiles. Github@stacks/networkNetwork and API library for working with Stacks blockchain nodes. Github@stacks/commonCommon utilities used by stacks.js packages. Github
Native Smart Contract Interaction
@stacks/bnsLibrary for interacting with the BNS contract. Github@stacks/stackingLibrary for PoX stacking. Github
Others
@stacks/cliCommand line interface to interact with auth, storage, and Stacks transactions. Github@stacks/blockchain-api-clientAuto-generated REST and websocket API for all endpoints provided by the Stacks Blockchain API. Github@stacks/keychainDEPRECATED: replaced by@stacks/wallet-sdk.
Development
There is a main Stacks.js monorepo containing most of the packages, but a few others often also considered as a part of "Stacks.js".
Are we missing anything? Feel free to open issues in the Github repositories.