# @bitgo/unspents

> Defines the chain codes used for different unspent types and methods to calculate bitcoin transaction sizes

Latest version **0.51.12** (published 2026-11-17) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @bitgo/unspents
pnpm add @bitgo/unspents
yarn add @bitgo/unspents
bun add @bitgo/unspents
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.51.12 |
| Published | 2026-11-17 |
| First published | 2019-03-09 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 472.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 398 |
| Author | BitGo SDK Team |
| Maintainers | louib-bitgo, bitgobot |
| Keywords | bitcoin, utxo |

## Links

- npm: https://www.npmjs.com/package/@bitgo/unspents
- Repository: https://github.com/BitGo/BitGoJS
- Homepage: https://github.com/BitGo/BitGoJS/tree/master/modules/unspents#bitgounspents
- Issues: https://github.com/BitGo/BitGoJS/issues
- npm.io page: https://npm.io/package/@bitgo/unspents

## Dependencies (4)

- [tcomb](https://npm.io/package/tcomb.md) ~3.2.29
- [lodash](https://npm.io/package/lodash.md) ^4.18.0
- [@bitgo/utxo-lib](https://npm.io/package/@bitgo/utxo-lib.md) ^11.25.1
- [varuint-bitcoin](https://npm.io/package/varuint-bitcoin.md) ~1.1.2

## Recent versions

- 0.51.12 (latest) — 2026-11-17
- 0.9.0-rc.6 (rc) — 2022-09-29
- 0.8.5-hotfix.1 (hotfix) — 2022-08-11
- 0.11.0-dev.0 (dev) — 2022-06-18
- 0.8.0-hotfix.1 (cr406-hf) — 2022-06-01
- 0.8.0-hotfix.0 (cr604-hf) — 2022-05-31
- 0.51.11 — 2026-10-22
- 0.51.10 — 2026-09-01
- 0.51.9 — 2026-08-27
- 0.51.8 — 2026-07-28
- 0.51.7 — 2026-07-22
- 0.51.6 — 2026-06-03
- 0.51.5 — 2026-06-02
- 0.51.4 — 2026-05-05
- 0.51.3 — 2026-04-08
- … 169 more at https://npm.io/package/@bitgo/unspents/versions

## README

# @bitgo/unspents

The package provides a `Dimensions` class with methods to calculate bitcoin transaction sizes

## Installation

```
npm install --save @bitgo/unspents
```

## Dimensions, Virtual Size Estimation

The transaction vSize is critical to calculating the proper transaction fee.

The class `unspents.Dimensions` provides a class that helps work with the components required
to calculate an accurate estimate of a transaction vSize.

### Examples

```typescript
import { Codes, Dimensions } from '@bitgo/unspents';
// using raw attributes
new Dimensions({
  nP2shInputs: 1,
  nP2shP2wshInputs: 1,
  nP2wshInputs: 1,
  outputs: { count: 1, size: 32 },
});

// calculate from unspents that have `chain` property (see Chain Codes)
Dimensions.fromUnspents(unspent[0]);
Dimensions.fromUnspents(unspents);

// Signed inputs work too
Dimensions.fromInput(inputs[0]);
Dimensions.fromInputs(inputs);

// Transaction outputs
Dimensions.fromOutputs(outputs[0]);
Dimensions.fromOutputs(outputs);
Dimensions.fromOutputOnChain(Codes.p2sh.internal);
Dimensions.fromOutputScriptLength(31);

// Combining dimensions and estimating their vSize
Dimensions.fromUnspents({ unspents })
  .plus(Dimensions.fromOutputOnChain(Codes.p2shP2wsh.internal).times(nOutputs))
  .getVSize();
```

## Continuous Integration

`@bitgo/unspents` uses github actions for continuous integration, which is configured by the `.github/workflows/ci.yml` file in the project root. All changes to the CI process should be done by modifying the `.github/workflows/ci.yml` file.

## `Codes`

The exported `Codes` module is now deprecated.

Please use [`utxo-lib/src/bitgo/wallet/chains`](https://github.com/BitGo/BitGoJS/blob/0439a0d4ffe4a15a9932ed70f98cc5745cc6526f/modules/utxo-lib/src/bitgo/wallet/chains.ts) instead.

---
_Source: https://npm.io/package/@bitgo/unspents · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
