Skip to content

[Stacks 2.1] Support Stacks 2.1 in @stacks/stacking (PoX-2) #1347

@zone117x

Description

@zone117x

A PoX-2 contract will be deployed after the Stacks 2.1 hardfork goes live. Several new functions will be available:

It probably makes sense to create a new set of sister function calls for PoX-2, and detect if the new functions should be used via an RPC call to determine if PoX-2 is live. The library needs to detect if Period 3 has activated -- this is after the 2.1 fork, and after PoX cycle (N+1), see https://github.com/stacksgov/sips/blob/c0fb33e0fc2b62e8e6d4ed85fb4b4aa289bb6042/sips/sip-015/sip-015-network-upgrade.md#specification

It may be possible to detect if PoX-2 is ready by checking if GET /v2/pox returns {"contract_id":"ST000000000000000000002AMW42H.pox-2"}, but that appears to be unimplemented as of opening this issue: stacks-network/stacks-core#3262

In the meantime, something like this should work:

async function isPoX2Ready(): Promise<boolean> {
  const req = await fetch(`/v2/data_var/ST000000000000000000002AMW42H/pox-2/configured?proof=0`);
  const body = await req.text();
  if (req.ok) {
    return JSON.parse(body)['data'] === '0x03'; // Clarity boolean-true
  } else if (req.status === 404 && body === 'Data var not found') {
    return false;
  } else {
    throw new Error(`Unexpected response: ${req.status} - ${body}`);
  }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions