Psbt class can parse and generate a PSBT binary based off of the BIP174. There are 6 roles that this class fulfills. (Explained in BIP174)

Creator: This can be done with new Psbt()

Updater: This can be done with psbt.addInput(input), psbt.addInputs(inputs), psbt.addOutput(output), psbt.addOutputs(outputs) when you are looking to add new inputs and outputs to the PSBT, and psbt.updateGlobal(itemObject), psbt.updateInput(itemObject), psbt.updateOutput(itemObject) addInput requires hash: Buffer | string; and index: number; as attributes and can also include any attributes that are used in updateInput method. addOutput requires script: Buffer; and value: number; and likewise can include data for updateOutput. For a list of what attributes should be what types. Check the bip174 library. Also, check the integration tests for some examples of usage.

Signer: There are a few methods. signAllInputs and signAllInputsAsync, which will search all input information for your pubkey or pubkeyhash, and only sign inputs where it finds your info. Or you can explicitly sign a specific input with signInput and signInputAsync. For the async methods you can create a SignerAsync object and use something like a hardware wallet to sign with. (You must implement this)

Combiner: psbts can be combined easily with psbt.combine(psbt2, psbt3, psbt4 ...) the psbt calling combine will always have precedence when a conflict occurs. Combine checks if the internal bitcoin transaction is the same, so be sure that all sequences, version, locktime, etc. are the same before combining.

Input Finalizer: This role is fairly important. Not only does it need to construct the input scriptSigs and witnesses, but it SHOULD verify the signatures etc. Before running psbt.finalizeAllInputs() please run psbt.validateSignaturesOfAllInputs() Running any finalize method will delete any data in the input(s) that are no longer needed due to the finalized scripts containing the information.

Transaction Extractor: This role will perform some checks before returning a Transaction object. Such as fee rate not being larger than maximumFeeRate etc.

Constructors

  • Parameters

    • opts: PsbtOptsOptional = {}
    • data: Psbt = ...

    Returns Psbt

Properties

data: Psbt = ...

Accessors

  • get inputCount(): number
  • Returns number

  • get locktime(): number
  • Returns number

  • set locktime(locktime): void
  • Parameters

    • locktime: number

    Returns void

  • get version(): number
  • Returns number

  • set version(version): void
  • Parameters

    • version: number

    Returns void

Methods

  • Parameters

    • inputData: PsbtInputExtended

    Returns this

  • Parameters

    • inputDatas: PsbtInputExtended[]

    Returns this

  • Parameters

    • outputData: PsbtOutputExtended

    Returns this

  • Parameters

    • outputDatas: PsbtOutputExtended[]

    Returns this

  • Parameters

    • keyVal: KeyValue

    Returns this

  • Parameters

    • inputIndex: number
    • keyVal: KeyValue

    Returns this

  • Parameters

    • outputIndex: number
    • keyVal: KeyValue

    Returns this

  • Parameters

    • inputIndex: number

    Returns this

  • Parameters

    • Rest...those: Psbt[]

    Returns this

  • Returns this

  • Parameters

    • inputIndex: number
    • OptionalfinalScriptsFunc: FinalScriptsFunc | FinalTaprootScriptsFunc

    Returns this

  • Parameters

    • inputIndex: number
    • OptionaltapLeafHashToFinalize: Uint8Array
    • finalScriptsFunc: FinalTaprootScriptsFunc = tapScriptFinalizer

    Returns this

  • Returns number

  • Parameters

    • inputIndex: number

    Returns AllScriptType

  • Parameters

    Returns boolean

  • Parameters

    • inputIndex: number
    • pubkey: Uint8Array

    Returns boolean

  • Parameters

    Returns boolean

  • Parameters

    • outputIndex: number
    • pubkey: Uint8Array

    Returns boolean

  • Parameters

    • inputIndex: number
    • sequence: number

    Returns this

  • Parameters

    • locktime: number

    Returns this

  • Parameters

    • satoshiPerByte: number

    Returns void

  • Parameters

    • version: number

    Returns this

  • Parameters

    • keyPair: Signer
    • OptionalsighashTypes: number[]

    Returns this

  • Parameters

    Returns Promise<void>

  • Parameters

    • hdKeyPair: HDSigner
    • sighashTypes: number[] = ...

    Returns this

  • Parameters

    Returns Promise<void>

  • Parameters

    • inputIndex: number
    • keyPair: Signer
    • OptionalsighashTypes: number[]

    Returns this

  • Parameters

    Returns Promise<void>

  • Parameters

    • inputIndex: number
    • hdKeyPair: HDSigner
    • sighashTypes: number[] = ...

    Returns this

  • Parameters

    Returns Promise<void>

  • Parameters

    • inputIndex: number
    • keyPair: Signer
    • OptionaltapLeafHashToSign: Uint8Array
    • OptionalsighashTypes: number[]

    Returns this

  • Parameters

    • inputIndex: number
    • keyPair: Signer | SignerAsync
    • OptionaltapLeafHash: Uint8Array
    • OptionalsighashTypes: number[]

    Returns Promise<void>

  • Returns Uint8Array

  • Parameters

    • updateData: PsbtGlobalUpdate

    Returns this

  • Parameters

    • inputIndex: number
    • updateData: PsbtInputUpdate

    Returns this

  • Parameters

    • outputIndex: number
    • updateData: PsbtOutputUpdate

    Returns this

  • Parameters

    • validator: ValidateSigFunction

    Returns boolean

  • Parameters

    • inputIndex: number
    • validator: ValidateSigFunction
    • Optionalpubkey: Uint8Array

    Returns boolean

  • Parameters

    • data: string
    • opts: PsbtOptsOptional = {}

    Returns Psbt

  • Parameters

    • buffer: Uint8Array
    • opts: PsbtOptsOptional = {}

    Returns Psbt

  • Parameters

    • data: string
    • opts: PsbtOptsOptional = {}

    Returns Psbt