Transaction
bitcoinjs-lib / Transaction
Class: Transaction
Defined in: ts_src/transaction.ts:83
Represents a Bitcoin transaction.
Constructors
new Transaction()
new Transaction():
Transaction
Returns
Properties
ins
ins:
TxInput
[] =[]
Defined in: ts_src/transaction.ts:166
locktime
locktime:
number
=0
Defined in: ts_src/transaction.ts:165
outs
outs:
TxOutput
[] =[]
Defined in: ts_src/transaction.ts:167
version
version:
number
=1
Defined in: ts_src/transaction.ts:164
ADVANCED_TRANSACTION_FLAG
readonly
static
ADVANCED_TRANSACTION_FLAG:1
=0x01
Defined in: ts_src/transaction.ts:93
ADVANCED_TRANSACTION_MARKER
readonly
static
ADVANCED_TRANSACTION_MARKER:0
=0x00
Defined in: ts_src/transaction.ts:92
DEFAULT_SEQUENCE
readonly
static
DEFAULT_SEQUENCE:4294967295
=0xffffffff
Defined in: ts_src/transaction.ts:84
SIGHASH_ALL
readonly
static
SIGHASH_ALL:1
=0x01
Defined in: ts_src/transaction.ts:86
SIGHASH_ANYONECANPAY
readonly
static
SIGHASH_ANYONECANPAY:128
=0x80
Defined in: ts_src/transaction.ts:89
SIGHASH_DEFAULT
readonly
static
SIGHASH_DEFAULT:0
=0x00
Defined in: ts_src/transaction.ts:85
SIGHASH_INPUT_MASK
readonly
static
SIGHASH_INPUT_MASK:128
=0x80
Defined in: ts_src/transaction.ts:91
SIGHASH_NONE
readonly
static
SIGHASH_NONE:2
=0x02
Defined in: ts_src/transaction.ts:87
SIGHASH_OUTPUT_MASK
readonly
static
SIGHASH_OUTPUT_MASK:3
=0x03
Defined in: ts_src/transaction.ts:90
SIGHASH_SINGLE
readonly
static
SIGHASH_SINGLE:3
=0x03
Defined in: ts_src/transaction.ts:88
Methods
addInput()
addInput(
hash
,index
,sequence
?,scriptSig
?):number
Defined in: ts_src/transaction.ts:175
Parameters
hash
Uint8Array
index
number
sequence?
number
scriptSig?
Uint8Array
Returns
number
addOutput()
addOutput(
scriptPubKey
,value
):number
Defined in: ts_src/transaction.ts:207
Parameters
scriptPubKey
Uint8Array
value
bigint
Returns
number
byteLength()
byteLength(
_ALLOW_WITNESS
):number
Defined in: ts_src/transaction.ts:238
Parameters
_ALLOW_WITNESS
boolean
= true
Returns
number
clone()
clone():
Transaction
Defined in: ts_src/transaction.ts:259
Returns
getHash()
getHash(
forWitness
?):Uint8Array
Defined in: ts_src/transaction.ts:647
Parameters
forWitness?
boolean
Returns
Uint8Array
getId()
getId():
string
Defined in: ts_src/transaction.ts:653
Returns
string
hashForSignature()
hashForSignature(
inIndex
,prevOutScript
,hashType
):Uint8Array
Defined in: ts_src/transaction.ts:292
Hash transaction for signing a specific input.
Bitcoin uses a different hash for each signed transaction input. This method copies the transaction, makes the necessary changes based on the hashType, and then hashes the result. This hash can then be used to sign the provided transaction input.
Parameters
inIndex
number
prevOutScript
Uint8Array
hashType
number
Returns
Uint8Array
hashForWitnessV0()
hashForWitnessV0(
inIndex
,prevOutScript
,value
,hashType
):Uint8Array
Defined in: ts_src/transaction.ts:548
Parameters
inIndex
number
prevOutScript
Uint8Array
value
bigint
hashType
number
Returns
Uint8Array
hashForWitnessV1()
hashForWitnessV1(
inIndex
,prevOutScripts
,values
,hashType
,leafHash
?,annex
?,codeseparatorPos
?):Uint8Array
Defined in: ts_src/transaction.ts:369
Parameters
inIndex
number
prevOutScripts
Uint8Array
[]
values
bigint
[]
hashType
number
leafHash?
Uint8Array
annex?
Uint8Array
codeseparatorPos?
number
Returns
Uint8Array
hasWitnesses()
hasWitnesses():
boolean
Defined in: ts_src/transaction.ts:222
Returns
boolean
isCoinbase()
isCoinbase():
boolean
Defined in: ts_src/transaction.ts:169
Returns
boolean
setInputScript()
setInputScript(
index
,scriptSig
):void
Defined in: ts_src/transaction.ts:666
Parameters
index
number
scriptSig
Uint8Array
Returns
void
setWitness()
setWitness(
index
,witness
):void
Defined in: ts_src/transaction.ts:672
Parameters
index
number
witness
Uint8Array
[]
Returns
void
shPreimageForWitnessV1()
shPreimageForWitnessV1(
inIndex
,prevOutScripts
,values
,hashType
,leafHash
?,annex
?,codeseparatorPos
?):Uint8Array
Defined in: ts_src/transaction.ts:390
Parameters
inIndex
number
prevOutScripts
Uint8Array
[]
values
bigint
[]
hashType
number
leafHash?
Uint8Array
annex?
Uint8Array
codeseparatorPos?
number
Returns
Uint8Array
toBuffer()
toBuffer(
buffer
?,initialOffset
?):Uint8Array
Defined in: ts_src/transaction.ts:658
Parameters
buffer?
Uint8Array
initialOffset?
number
Returns
Uint8Array
toHex()
toHex():
string
Defined in: ts_src/transaction.ts:662
Returns
string
verify()
verify():
string
|true
Defined in: ts_src/transaction.ts:739
Check that a transaction passes basic sanity tests. If not, return a string describing the error. This function contains the same logic as CheckTransaction in bitcoin core.
Returns
string
| true
virtualSize()
virtualSize():
number
Defined in: ts_src/transaction.ts:234
Returns
number
weight()
weight():
number
Defined in: ts_src/transaction.ts:228
Returns
number
fromBuffer()
static
fromBuffer(buffer
,_NO_STRICT
?):Transaction
Defined in: ts_src/transaction.ts:95
Parameters
buffer
Uint8Array
_NO_STRICT?
boolean
Returns
fromHex()
static
fromHex(hex
):Transaction
Defined in: ts_src/transaction.ts:152
Parameters
hex
string
Returns
isCoinbaseHash()
static
isCoinbaseHash(buffer
):boolean
Defined in: ts_src/transaction.ts:156
Parameters
buffer
Uint8Array
Returns
boolean