Initialize a StackingClient to interact with the Stacking contract.
Note: the StackingClient sets its transactions AnchorMode to Any.
import { getNonce } from'@stacks/transactions';import { StacksTestnet, StacksMainnet } from'@stacks/network';import { StackingClient } from'@stacks/stacking';importBNfrom'bn.js';constnetwork = newStacksTestnet();// for mainnet: const network = new StacksMainnet();constclient = newStackingClient(address, network);// the stacks STX addressconstaddress = 'ST3XKKN4RPV69NN1PHFDNX3TYKXT7XPC4N8KC1ARH';// a BTC address for reward payoutsconstpoxAddress = 'mvuYDknzDtPgGqm2GnbAbmGMLwiyW3AwFP';// number cycles to stackconstcycles = 3;// how much to stack, in microSTXconstamountMicroStx = newBN(100000000000);// private key for transaction signingconstprivateKey = 'd48f215481c16cbe6426f8e557df9b78895661971d71735126545abddcd5377001';// block height at which to stackconstburnBlockHeight = 2000;
// STX address of the delegatorconstdelegateTo = 'ST2MCYPWTFMD2MGR5YY695EJG0G1R4J2BTJPRGM7H';// burn height at which the delegation relationship should be revoked (optional)constuntilBurnBlockHeight = 5000;constdelegetateResponse = awaitclient.delegateStx({amountMicroStx,delegateTo,untilBurnBlockHeight, // optionalprivateKey,});// {// txid: '0xf6e9dbf6a26c1b73a14738606cb2232375d1b440246e6bbc14a45b3a66618481',// }
// note that the parameter here is not JSONconstrevokeResponse = awaitclient.revokeDelegateStx(privateKey);// {// txid: '0xf6e9dbf6a26c1b73a14738606cb2232375d1b440246e6bbc14a45b3a66618481',// }
// delegators would initiate a different clientconstdelegatorAddress = 'ST22X605P0QX2BJC3NXEENXDPFCNJPHE02DTX5V74';// delegator private key for transaction signingconstdelegatorPrivateKey = 'd48f215481c16cbe6426f8e557df9b78895661971d71735126545abddcd5377001';// the BTC address for reward payoutsconstdelegatorBtcAddress = 'msiYwJCvXEzjgq6hDwD9ueBka6MTfN962Z';// if you call this method multiple times in the same block, you need to increase the nonce manuallyletnonce = getNonce(delegatorAddress, network);nonce = nonce.add(newBN(1));constdelegatorClient = newStackingClient(delegatorAddress, network);constdelegetateStackResponses = awaitdelegatorClient.delegateStackStx({stacker:address,amountMicroStx,poxAddress:delegatorBtcAddress,burnBlockHeight,cycles,privateKey:delegatorPrivateKey,nonce, // optional});// {// txid: '0xf6e9dbf6a26c1b73a14738606cb2232375d1b440246e6bbc14a45b3a66618481',// }
@stacks/stacking
Library for PoX Stacking.
Installation
Initialization
Initialize a
StackingClient
to interact with the Stacking contract.Note: the
StackingClient
sets its transactionsAnchorMode
toAny
.Check stacking eligibility
Stack STX
Will Stacking be executed in the next cycle?
How long (in seconds) is a Stacking cycle?
How much time is left (in seconds) until the next cycle begins?
Get PoX info
Get Stacks node info
Get account balance
Does account have sufficient STX to meet minimum threshold?
Get account stacking status
Delegation
There are four methods available for delegation, two for the delegators and two for the delegatee.
Delegatee
If you are the account owner ("stacker"), you can delegate or revoke delegation rights.
Delegate STX
Revoke delegation
Delegator
If you are the delegator, you can stack ("lock up") tokens for your users and commit to stacking participation for upcoming reward cycles.
Stack delegated STX
Commit to stacking