@bitgo/unspents
Version:
Defines the chain codes used for different unspent types and methods to calculate bitcoin transaction sizes
59 lines (41 loc) • 1.79 kB
Markdown
# /unspents
The package provides a `Dimensions` class with methods to calculate bitcoin transaction sizes
## Installation
```
npm install --save /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
`/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.