Stacking using the Stacks CLI
Introduction
In this tutorial, you'll learn how to use the Stacks CLI to participate in Stacking. The CLI is a great way to quickly try out Stacking on testnet. To integrate Stacking into your application, see the Stacking integration guide.
Prerequisites
First, you'll need to understand the Stacking mechanism.
You'll also need NodeJS 12.10.0
or higher to complete this tutorial. You can verify your installation by opening up your terminal and run the following command:
node --version
You will also need to install the Stacks CLI from NPM:
npm install @stacks/cli -g
Generate An Account
stx make_keychain -t
{
"mnemonic": "turn food juice small swing junior trip crouch slot wood nephew own tourist hazard tomato follow trust just project traffic spirit oil diary blue",
"keyInfo": {
"privateKey": "dca82f838f6e5a893cffc8efe861196252373a5b8b62c0b55ba3a0a7a28795d301",
"address": "ST1P3HXR80TKT48TKM2VTKCDBS4ET9396W0W2S3K8",
"btcAddress": "mqPBWmSGJhrA9x5XJC6qJtFsHnudqZ2XJU",
"index": 0
}
}
We'll be using this testnet key pair to perform Stacking. But first we'll need to get some testnet tokens.
If you're Stacking on mainnet, make sure you have an account with sufficient number of Stacks tokens to participate.
Get Testnet Tokens Using The Faucet
Use the following curl
command to request tokens from the testnet node's faucet endpoint.
We use the address generated above as a parameter.
curl -X POST https://api.testnet.hiro.so/extended/v1/faucets/stx?address=ST1P3HXR80TKT48TKM2VTKCDBS4ET9396W0W2S3K8&stacking=true
Check Balance
Confirm that the faucet transaction has completed by checking the balance of your address. The -t
flag is used to indicate testnet. See the CLI reference for usage of flags.
stx balance ST1P3HXR80TKT48TKM2VTKCDBS4ET9396W0W2S3K8 -t
{
"balance": "90000000000000",
"locked": "0",
"unlock_height": 0,
"nonce": 0
}
Check Stacking Eligibility
Before we send the Stacking transaction, we will need to check if we're eligible for Stacking.
This check ensures that we meet the minimum threshold amount of STX required in order to participate in Stacking.
The arguments required for the can_stack
command are:
Parameter | Description | Value |
---|---|---|
Amount | Amount to stack in microstacks, we'll use the entire balance in our account | 90000000000000 |
Reward cycles | Number of reward cycles to lock up your tokens for Stacking | 10 |
BTC Address | BTC address to receive Stacking rewards. We can use any valid BTC address | mqkccNX5h7Xy1YUku3X2fCFCC54x6HEiHk |
STX Address | The address that we will be Stacking with. We'll use the address generated previously | ST1P3HXR80TKT48TKM2VTKCDBS4ET9396W0W2S3K8 |
stx can_stack 90000000000000 10 mqkccNX5h7Xy1YUku3X2fCFCC54x6HEiHk ST1P3HXR80TKT48TKM2VTKCDBS4ET9396W0W2S3K8 -t
{ eligible: true }
If we meet the conditions to participate in Stacking, the command will return true.