> For the complete documentation index, see [llms.txt](https://docs.stacks.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stacks.co/reference/stacks.js/stacks-bitcoin-staking/script/buildunlockscript.md).

# buildUnlockScript

Builds the default staker unlock subscript, `<pubkey> OP_CHECKSIG`, from a compressed public key. Pure computation: no network call.

***

### Usage

```ts
import { buildUnlockScript } from '@stacks/bitcoin-staking';

const unlockBytes = buildUnlockScript(
  '0316e35d38b52d4886e40065e4952a49535ce914e02294be58e252d1998f129b19'
);
// 35 bytes: 0x21 (push 33 bytes), the key, 0xac (OP_CHECKSIG)
```

#### Notes

* Throws an `Error` if the key is not 33 bytes, does not start with `0x02` or `0x03`, or is not a point on secp256k1. The on-curve check matters because an off-curve key still yields a fundable lockup address whose `OP_CHECKSIG` can never pass.
* Pass the result as `unlockBytes` to [buildLockScript](/reference/stacks.js/stacks-bitcoin-staking/script/buildlockscript.md), [buildLockOutputScript](/reference/stacks.js/stacks-bitcoin-staking/script/buildlockoutputscript.md) or [buildLockAddress](/reference/stacks.js/stacks-bitcoin-staking/script/buildlockaddress.md), and as `lockup.unlockBytes` to [buildRegisterForBond](/reference/stacks.js/stacks-bitcoin-staking/build/buildregisterforbond.md). [buildRegisterMetadata](/reference/stacks.js/stacks-bitcoin-staking/script/buildregistermetadata.md) calls it for you.
* pox-5 splices these bytes raw at the end of the lockup script, so they run in both spend branches ([construct-lockup-script](https://github.com/stacks-network/stacks-core/blob/10474cdec9f9c0bdf05841b58cffc89cdad87a9b/stackslib/src/chainstate/stacks/boot/pox-5.clar#L3711-L3731)). `register-for-bond` takes them as `staker-unlock-bytes`, capped at 683 bytes ([L664](https://github.com/stacks-network/stacks-core/blob/10474cdec9f9c0bdf05841b58cffc89cdad87a9b/stackslib/src/chainstate/stacks/boot/pox-5.clar#L664-L664)).
* [finalizeReclaim](/reference/stacks.js/stacks-bitcoin-staking/reclaim/finalizereclaim.md) expects exactly one staker public key in this subscript, which this format provides.

[**Reference Link**](https://github.com/stx-labs/stacks.js/blob/6101c99efe5a9616ce7e16cef68e28fd10676e7e/packages/bitcoin-staking/src/script.ts#L35-L64)

***

### Signature

```ts
function buildUnlockScript(publicKey: Uint8Array | string): Uint8Array;
```

***

### Returns

`Uint8Array`

The encoded subscript: a 33-byte push of the key followed by `OP_CHECKSIG`.

***

### Parameters

#### publicKey (required)

* **Type**: `Uint8Array | string`

The staker's 33-byte compressed secp256k1 public key, as bytes or hex. This is the key that signs the lockup reclaim.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stacks.co/reference/stacks.js/stacks-bitcoin-staking/script/buildunlockscript.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
