Reference implementation of the Stacks blockchain in Rust.
Stacks 2.0 is a layer-1 blockchain that connects to Bitcoin for security and enables decentralized apps and predictable smart contracts. Stacks 2.0 implements Proof of Transfer (PoX) mining that anchors to Bitcoin security. Leader election happens at the Bitcoin blockchain and Stacks (STX) miners write new blocks on the separate Stacks blockchain. With PoX there is no need to modify Bitcoin to enable smart contracts and apps around it. See this page for more details and resources.
|Blockstack Topic/Tech||Where to learn more more|
|Stacks 2.0||master branch|
|Stacks 1.0||legacy branch|
|Use the package||our core docs|
|Develop a Blockstack App||our developer docs|
|Use a Blockstack App||our browser docs|
|Blockstack PBC the company||our website|
Release Schedule and Hotfixes
Normal releases in this repository that add features such as improved RPC endpoints, improved boot-up time, new event
observer fields or event types, etc., are released on a monthly schedule. The currently staged changes for such releases
are in the develop branch. It is generally safe to run
stacks-node from that branch, though it has received less rigorous testing than release tags. If bugs are found in
develop branch, please do report them as issues on this repository.
For fixes that impact the correct functioning or liveness of the network, hotfixes may be issued. These are patches to the main branch which are backported to the develop branch after merging. These hotfixes are categorized by priority according to the following rubric:
- High Priority. Any fix for an issue that could deny service to the network as a whole, e.g., an issue where a particular kind of invalid transaction would cause nodes to stop processing requests or shut down unintentionally. Any fix for an issue that could cause honest miners to produce invalid blocks.
- Medium Priority. Any fix for an issue that could cause miners to waste funds.
- Low Priority. Any fix for an issue that could deny service to individual nodes.
This repository uses a 5 part version number.
For example, a node operator running version
22.214.171.124.0 would not need to wipe and refresh their chainstate
to upgrade to
126.96.36.199.1. However, upgrading to
188.8.131.52.0 would require a new chainstate.
- SIP 001: Burn Election
- SIP 002: Clarity, a language for predictable smart contracts
- SIP 003: Peer Network
- SIP 004: Cryptographic Committment to Materialized Views
- SIP 005: Blocks, Transactions, and Accounts
- SIP 006: Clarity Execution Cost Assessment
- SIP 007: Stacking Consensus
- SIP 008: Clarity Parsing and Analysis Cost Assessment
Stacks improvement proposals (SIPs) are aimed at describing the implementation of the Stacks blockchain, as well as proposing improvements. They should contain concise technical specifications of features or standards and the rationale behind it. SIPs are intended to be the primary medium for proposing new features, for collecting community input on a system-wide issue, and for documenting design decisions.
See SIP 000 for more details.
The SIPs are now located in the stacksgov/sips repository as part of the Stacks Community Governance organization.
Krypton is a Stacks 2 testnet with a fixed, two-minute block time, called
regtest. Regtest is generally unstable for regular use, and is reset often. See the regtest documentation for more information on using regtest.
Xenon is the Stacks 2 public testnet, which runs PoX against the Bitcoin testnet. It is the full implementation of the Stacks 2 blockchain, and should be considered a stable testnet for developing Clarity smart contracts. See the testnet documentation for more information on the public testnet.
Mainnet is the fully functional Stacks 2 blockchain, see the Stacks overview for information on running a Stacks node, mining, stacking, and writing Clarity smart contracts.
Download and build stacks-blockchain
The first step is to ensure that you have Rust and the support software installed.
For building on Windows, follow the rustup installer instructions at https://rustup.rs/
From there, you can clone this repository:
Then build the project:
Run the tests:
Encode and sign transactions
Here, we have generated a keypair that will be used for signing the upcoming transactions:
This keypair is already registered in the
testnet-follower-conf.toml file, so it can be used as presented here.
We will interact with the following simple contract
kv-store. In our examples, we will assume this contract is saved to
We want to publish this contract on chain, then issue some transactions that interact with it by setting some keys and getting some values, so we can observe read and writes.
Our first step is to generate and sign, using your private key, the transaction that will publish the contract
To do that, we will use the subcommand:
With the following arguments:
515 is the transaction fee, denominated in microSTX. Right now, the
testnet requires one microSTX per byte minimum, and this transaction should be
less than 515 bytes.
The third argument
0 is a nonce, that must be increased monotonically with each new transaction.
This command will output the binary format of the transaction. In our case, we want to pipe this output and dump it to a file that will be used later in this tutorial.
Run the testnet
You can observe the state machine in action locally by running:
testnet-follower-conf.toml is a configuration file that you can use for setting genesis balances or configuring Event observers. You can grant an address an initial account balance by adding the following entries:
address field is the Stacks testnet address, and the
amount field is the
number of microSTX to grant to it in the genesis block. The addresses of the
private keys used in the tutorial below are already added.
Publish your contract
Assuming that the testnet is running, we can publish our
In another terminal (or file explorer), you can move the
tx1.bin generated earlier, to the mempool:
In the terminal window running the testnet, you can observe the state machine's reactions.
Reading from / Writing to the contract
Now that our contract has been published on chain, let's try to submit some read / write transactions.
We will start by trying to read the value associated with the key
To do that, we will use the subcommand:
With the following arguments:
contract-call generates and signs a contract-call transaction.
We can submit the transaction by moving it to the mempool path:
Similarly, we can generate a transaction that would be setting the key
foo to the value
And submit it by moving it to the mempool path:
Finally, we can issue a third transaction, reading the key
foo again, for ensuring that the previous transaction has successfully updated the state machine:
And submit this last transaction by moving it to the mempool path:
Congratulations, you can now write your own smart contracts with Clarity.
Officially supported platforms:
Platforms with second-tier status (builds are provided but not tested):
MacOS Apple Silicon (ARM64),
For help cross-compiling on memory-constrained devices, please see the community supported documentation here: Cross Compiling.
Beyond this Github project, Blockstack maintains a public forum and an opened Discord channel. In addition, the project maintains a mailing list which sends out community announcements.
The greater Blockstack community regularly hosts in-person meetups. The project's YouTube channel includes videos from some of these meetups, as well as video tutorials to help new users get started and help developers wrap their heads around the system's design.
You can learn more by visiting the Blockstack Website and checking out the documentation:
- Blockstack docs
You can also read the technical papers:
- "PoX: Proof of Transfer Mining with Bitcoin", May 2020
- "Stacks 2.0: Apps and Smart Contracts for Bitcoin", Dec 2020
If you have high-level questions about Blockstack, try searching our forum and start a new question if your question is not answered there.
Tests and Coverage
PRs must include test coverage. However, if your PR includes large tests or tests which cannot run in parallel
(which is the default operation of the
cargo test command), these tests should be decorated with
If you add
#[ignore] tests, you should add your branch to the filters for the
all_tests job in our circle.yml
(or if you are working on net code or marf code, your branch should be named such that it matches the existing
A test should be marked
- It does not always pass
cargo testin a vanilla environment (i.e., it does not need to run with
- Or, it runs for over a minute via a normal
cargo testexecution (the
cargo testcommand will warn if this is not the case).
This repository uses the default rustfmt formatting style. PRs will be checked against
rustfmt and will fail if not
You can check the formatting locally via:
You can automatically reformat your commit via:
Stacks tokens (STX) are mined by transferring BTC via PoX. To run as a miner, you should make sure to add the following config fields to your config file:
You can verify that your node is operating as a miner by checking its log output to verify that it was able to find its Bitcoin UTXOs:
Configuring Cost and Fee Estimation
Fee and cost estimators can be configure via the config section
Fee and cost estimators observe transactions on the network and use the
observed costs of those transactions to build estimates for viable fee rates
and expected execution costs for transactions. Estimators and metrics can be
selected using the configuration fields above, though the default values are
the only options currently.
log_error controls whether or not the INFO logger
will display information about the cost estimator accuracy as new costs are
enabled = false turns off the cost estimators. Cost estimators
are not consensus-critical components, but rather can be used by miners to
rank transactions in the mempool or client to determine appropriate fee rates
for transactions before broadcasting them.
fuzzed_weighted_median_fee_rate uses a
median estimate from a window of the fees paid in the last
Estimates are then randomly "fuzzed" using uniform random fuzz of size up to
fee_rate_fuzzer_fraction of the base estimate.
Non-Consensus Breaking Release Process
For non-consensus breaking releases, this project uses the following release process:
The release must be timed so that it does not interfere with a prepare phase. The timing of the next Stacking cycle can be found here. A release to
mainnetshould happen at least 24 hours before the start of a new cycle, to avoid interfering with the prepare phase. So, start by being aware of when the release can happen.
Before creating the release, the release manager must determine the version number for this release. The factors that determine the version number are discussed in Versioning. We assume, in this section, that the change is not consensus-breaking. So, the release manager must first determine whether there are any "non-consensus-breaking changes that require a fresh chainstate". This means, in other words, that the database schema has changed, but an automatic migration was not implemented. Then, the release manager should determine whether this is a feature release, as opposed to a hot fix or a patch. Given the answers to these questions, the version number can be computed.
The release manager enumerates the PRs or issues that would block the release. A label should be applied to each such issue/PR as
2.0.x.y.z-blocker. The release manager should ping these issue/PR owners for updates on whether or not those issues/PRs have any blockers or are waiting on feedback.
The release manager should open a
develop -> masterPR. This can be done before all the blocker PRs have merged, as it is helpful for the manager and others to see the staged changes.
The release manager must update the
CHANGELOG.mdfile with summaries what was
Fixed. The pull requests merged into
developcan be found here. Note, however, that GitHub apparently does not allow sorting by merge time, so, when sorting by some proxy criterion, some care should be used to understand which PR's were merged after the last
develop -> masterrelease PR. This
CHANGELOG.mdshould also be used as the description of the
develop -> masterso that it acts as release notes when the branch is tagged.
Once the blocker PRs have merged, the release manager will create a new tag by manually triggering the
stacks-blockchainGithub Actions workflow against the
developbranch, inputting the release candidate tag,
2.0.x.y.z-rc0, in the Action's input textbox.
Once the release candidate has been built, and docker images, etc. are available, the release manager will notify various ecosystem participants to test the release candidate on various staging infrastructure:
- Stacks Foundation staging environments.
- Hiro PBC testnet network.
- Hiro PBC mainnet mock miner.
The release candidate should be announced in the
#stacks-core-devschannel in the Stacks Discord. For coordinating rollouts on specific infrastructure, the release manager should contact the above participants directly either through e-mail or Discord DM. The release manager should also confirm that the built release on the Github releases page is marked as
The release manager will test that the release candidate successfully syncs with the current chain from genesis both in testnet and mainnet. This requires starting the release candidate with an empty chainstate and confirming that it synchronizes with the current chain tip.
If bugs or issues emerge from the rollout on staging infrastructure, the release will be delayed until those regressions are resolved. As regressions are resolved, additional release candidates should be tagged. The release manager is responsible for updating the
develop -> masterPR with information about the discovered issues, even if other community members and developers may be addressing the discovered issues.
Once the final release candidate has rolled out successfully without issue on the above staging infrastructure, the release manager tags 2 additional
stacks-blockchainteam members to review the
develop -> masterPR. If there is a merge conflict in this PR, this is the protocol: open a branch off of develop, merge master into that branch, and then open a PR from this side branch to develop. The merge conflicts will be resolved.
Once reviewed and approved, the release manager merges the PR, and tags the release via the
stacks-blockchainGithub action by clicking "Run workflow" and providing the release version as the tag (e.g.,
184.108.40.206.0) This creates a release and release images. Once the release has been created, the release manager should update the Github release text with the
CHANGELOG.md"top-matter" for the release.
Copyright and License
The code and documentation copyright are attributed to blockstack.org for the year of 2020.
This code is released under the GPL v3 license, and the docs are released under the Creative Commons license.