> 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/buildregistermetadata.md).

# buildRegisterMetadata

Derives the lockup address, witness script, output script, staker subscript and unlock height for a paired-BTC `register-for-bond` in one call. Combines [computeBondUnlockHeight](/reference/stacks.js/stacks-bitcoin-staking/script/computebondunlockheight.md), [buildUnlockScript](/reference/stacks.js/stacks-bitcoin-staking/script/buildunlockscript.md) and [buildLockScript](/reference/stacks.js/stacks-bitcoin-staking/script/buildlockscript.md). Pure computation: no network call.

***

### Usage

```ts
import { buildRegisterMetadata, 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 meta = buildRegisterMetadata({
  bondIndex,
  poxInfo,
  bitcoinPublicKey: '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc',
  stxAddress: 'SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7',
  earlyUnlockBytes: bond.earlyUnlockBytes,
  network: 'mainnet',
});

meta.lockAddress; // send the sats to lock here
meta.unlockHeight; // 994700 for mainnet bond 2
```

#### Notes

* The unlock height is the bond's minimum, from [computeBondUnlockHeight](/reference/stacks.js/stacks-bitcoin-staking/script/computebondunlockheight.md). To commit to a later height, build the pieces with [buildUnlockScript](/reference/stacks.js/stacks-bitcoin-staking/script/buildunlockscript.md), [buildLockScript](/reference/stacks.js/stacks-bitcoin-staking/script/buildlockscript.md) and [buildLockAddress](/reference/stacks.js/stacks-bitcoin-staking/script/buildlockaddress.md).
* Throws in the same cases as [computeBondUnlockHeight](/reference/stacks.js/stacks-bitcoin-staking/script/computebondunlockheight.md), [buildUnlockScript](/reference/stacks.js/stacks-bitcoin-staking/script/buildunlockscript.md) and [buildLockScript](/reference/stacks.js/stacks-bitcoin-staking/script/buildlockscript.md).
* After the funding transaction confirms, pass `meta.lockScript` and `meta.unlockHeight` to [buildLockProof](/reference/stacks.js/stacks-bitcoin-staking/proof/buildlockproof.md) or [buildLockProofFromBlock](/reference/stacks.js/stacks-bitcoin-staking/proof/buildlockprooffromblock.md), then pass the proof and `meta.unlockBytes` to [buildRegisterForBond](/reference/stacks.js/stacks-bitcoin-staking/build/buildregisterforbond.md) as `lockup: { kind: 'btc', outputs: [proof], unlockBytes: meta.unlockBytes }`.
* Store `meta.lockScript`. [buildReclaim](/reference/stacks.js/stacks-bitcoin-staking/reclaim/buildreclaim.md) needs it to spend the lockup.
* The address encoding follows `network`: `bc` on `'mainnet'`, `tb` on `'testnet'`, `bcrt` on `'devnet'` and `'mocknet'`.

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

***

### Signature

```ts
function buildRegisterMetadata(opts: {
  bondIndex: number;
  poxInfo: PoxInfo;
  bitcoinPublicKey: Uint8Array | string;
  stxAddress: string;
  earlyUnlockBytes: Uint8Array | string;
  network: StacksNetworkName | StacksNetwork;
  validateEarlyUnlockBytes?: boolean;
}): RegisterMetadata;
```

***

### Returns

`RegisterMetadata`

A [RegisterMetadata](/reference/stacks.js/stacks-bitcoin-staking/script/registermetadata.md).

***

### Parameters

#### opts.bondIndex (required)

* **Type**: `number`

The bond period index to register for.

#### opts.poxInfo (required)

* **Type**: `PoxInfo`

The result of [fetchPoxInfo](/reference/stacks.js/stacks-bitcoin-staking/fetch/fetchpoxinfo.md), used to compute the unlock height.

#### opts.bitcoinPublicKey (required)

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

The staker's 33-byte compressed public key, as bytes or hex. It signs the reclaim of the lockup.

#### opts.stxAddress (required)

* **Type**: `string`

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

#### opts.earlyUnlockBytes (required)

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

The bond's early-unlock subscript, as bytes or hex. Read it from [fetchBond](/reference/stacks.js/stacks-bitcoin-staking/fetch/fetchbond.md).

#### opts.network (required)

* **Type**: `StacksNetworkName | StacksNetwork`

The network whose Bitcoin address encoding to use: a name such as `'mainnet'` or `'testnet'`, or a [StacksNetwork](/reference/stacks.js/stacks-network/network/stacksnetwork.md) object.

#### opts.validateEarlyUnlockBytes (optional)

* **Type**: `boolean`

Set to `false` to skip the shape check on `earlyUnlockBytes`. The structural check still runs. Defaults to `true`.


---

# 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/buildregistermetadata.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.
