For the complete documentation index, see llms.txt. This page is also available as Markdown.

buildLockOutputScript

Builds the 34-byte P2WSH scriptPubKey that a lockup funding output must carry, as pox-5's construct-lockup-output-script builds it. Pure computation: no network call.


Usage

import {
  buildLockOutputScript,
  buildUnlockScript,
  computeBondUnlockHeight,
  fetchBond,
  fetchPoxInfo,
} from '@stacks/bitcoin-staking';

const bondIndex = 2;
const poxInfo = await fetchPoxInfo({ network: 'mainnet' });
const bond = await fetchBond({ bondIndex, network: 'mainnet' });
if (!bond) throw new Error(`bond ${bondIndex} is not set up`);

const outputScript = buildLockOutputScript({
  stxAddress: 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7',
  unlockHeight: computeBondUnlockHeight({ bondIndex, poxInfo }),
  unlockBytes: buildUnlockScript(
    '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc'
  ),
  earlyUnlockBytes: bond.earlyUnlockBytes,
});
// 0x00 0x20 followed by sha256(lockScript)

Notes

Reference Link


Signature


Returns

Uint8Array

The 34-byte P2WSH scriptPubKey.


Parameters

opts.stxAddress (required)

  • Type: string

The staker's Stacks principal, standard or contract. It must be the address that sends register-for-bond.

opts.unlockHeight (required)

  • Type: IntegerType

The Bitcoin block height at which the OP_CHECKLOCKTIMEVERIFY branch becomes spendable. A number, bigint or numeric string.

opts.unlockBytes (required)

  • Type: Uint8Array | string

The staker subscript, as bytes or hex. Usually the output of buildUnlockScript.

opts.earlyUnlockBytes (required)

  • Type: Uint8Array | string

The bond's early-unlock subscript, as bytes or hex. Read it from fetchBond.

Was this helpful?