Updates for Stacks.js

Discover Stacks.js changes related to the Nakamoto upgrade.

What's new

StackingClient

Install the latest nakamoto version with npm install @stacks/stacking@latest.

The StackingClient in @stacks/stacking was updated to match the latest pox-4 contract.

  • Added StackingClient.signPoxSignature()
  • Added Pox4SignatureTopic enum
  • New stacking arguments for StackingClient.stack, StackingClient.stackExtend, StackingClient.stackIncrease, StackingClient.stackAggregationCommit, StackingClient.stackAggregationCommitIndexed, and StackingClient.stackAggregationIncrease

Nakamoto network

To test using the Nakamoto testnet, you can use the StacksTestnet network with a custom URL. The Nakamoto testnet is being hosted at https://api.testnet.hiro.so. Use this URL like this:

import { StacksTestnet } from "@stacks/network"

const network = new StacksTestnet({
  url: "https://api.testnet.hiro.so"
})

Example snippets

StackingClient.signPoxSignature

const client = StackingClient(MY_ADDRESS, new StacksTestnet())
const signature = client.signPoxSignature({
  topic: "stack-stx",
  rewardCycle: await client.getPoxInfo().reward_cycle_id,
  poxAddress: MY_BTC_ADDRESS,
  period: 2,
  maxAmount: 10_000_000_000_000,
  authId: 123n,

  signerPrivateKey: MY_SIGNER_PRIVATE_KEY
})

New arguments for e.g. StackingClient.stack

const { txid } = await client.stack({
  amountMicroStx: 10_000_000_000_000, // this can be at most the signature `maxAmount`
  poxAddress: MY_BTC_ADDRESS,
  cycles: 2, // this needs to match signature `period`
  burnBlockHeight: CURRENT_BURN_BLOCK_HEIGHT,

  // NEW ARGS
  signerKey: MY_SIGNER_PUBLIC_KEY,
  signerSignature: signature,
  maxAmount: 10_000_000_000_000,
  authId: 123n,

  privateKey: MY_STX_PRIVATE_KEY
})