Skip to main content

TxUtils

bitcoinjs-lib v0.2.9-beta.16


bitcoinjs-lib / TxUtils

Class: TxUtils

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:39

Library for parsing and constructing transactions

Onchain​

Extends​

Constructors​

new TxUtils()​

new TxUtils(...args): TxUtils

Defined in: packages/scrypt-ts-btc/src/smart-contract/smartContractLib.ts:29

Parameters​

args​

...SupportedParamType[]

Returns​

TxUtils

Inherited from​

SmartContractLib.constructor

Properties​

args​

args: any[] = []

Defined in: packages/scrypt-ts-btc/src/smart-contract/smartContractLib.ts:28

Inherited from​

SmartContractLib.args


artifact​

static artifact: Artifact

Defined in: packages/scrypt-ts-btc/src/smart-contract/smartContractLib.ts:15

Inherited from​

SmartContractLib.artifact


NON_STATES_HASH_ROOT​

readonly static NON_STATES_HASH_ROOT: ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:54

the state hash root value for all non-state inputs, same as hash160(hash160('') + hash160('') + hash160('') + hash160('') + hash160(''))


STATE_HASH_ROOT_SCRIPT_PREFIX​

readonly static STATE_HASH_ROOT_SCRIPT_PREFIX: ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:47

op_return + op_push24 + "cat" (0x636174) + version (0x01)


stateType?​

static optional stateType: string

Defined in: packages/scrypt-ts-btc/src/smart-contract/smartContractLib.ts:16

Inherited from​

SmartContractLib.stateType


ZERO_SATS​

readonly static ZERO_SATS: ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:43

if a output satoshi value is zero

Methods​

buildChangeOutput()​

static buildChangeOutput(change): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:209

Build serialized change output

Parameters​

change​

TxOut

change output to build

Returns​

ByteString

serialized change output in format ByteString


buildOpReturnOutput()​

static buildOpReturnOutput(data): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:238

build OP_RETURN script from data payload

Parameters​

data​

ByteString

the data payload

Returns​

ByteString

a ByteString contains the data payload


buildOutput()​

static buildOutput(script, satoshis): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:175

Build serialized tx output

Parameters​

script​

ByteString

serialized locking script of the output

satoshis​

ByteString

serialized satoshis of the output

Returns​

ByteString

serialized tx output in format ByteString


buildP2PKHOutput()​

static buildP2PKHOutput(addr, amount): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:267

constructs a P2PKH output from a given PubKeyHash and satoshi amount

Parameters​

addr​

Ripemd160

the recipient's public key hash

amount​

ByteString

the satoshi amount

Returns​

ByteString

a ByteString representing the P2PKH output


buildP2PKHScript()​

static buildP2PKHScript(addr): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:249

constructs a P2PKH script from a given PubKeyHash

Parameters​

addr​

Ripemd160

Returns​

ByteString

a ByteString representing the P2PKH script


buildP2TROutput()​

static buildP2TROutput(xpubkey, amount): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:309

constructs a p2tr output from a given PubKeyHash and satoshi amount

Parameters​

xpubkey​

XOnlyPubKey

the recipient's x-only public key

amount​

ByteString

the satoshi amount

Returns​

ByteString

a ByteString representing the P2PKH output


buildP2TRScript()​

static buildP2TRScript(xpubkey): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:298

Parameters​

xpubkey​

XOnlyPubKey

Returns​

ByteString


buildP2WPKHOutput()​

static buildP2WPKHOutput(addr, amount): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:288

constructs a P2WPKH output from a given PubKeyHash and satoshi amount

Parameters​

addr​

Ripemd160

the recipient's public key hash

amount​

ByteString

the satoshi amount

Returns​

ByteString

a ByteString representing the P2PKH output


buildP2WPKHScript()​

static buildP2WPKHScript(addr): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:277

Parameters​

addr​

Ripemd160

Returns​

ByteString


buildStateHashRootOutput()​

static buildStateHashRootOutput(hashRoot): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:188

Build serialized state hash root output

Parameters​

hashRoot​

ByteString

state hash root

Returns​

ByteString

serialized state hash root output in format ByteString


buildStateHashRootScript()​

static buildStateHashRootScript(hashRoot): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:198

Build locking script of state output from state hash root

Parameters​

hashRoot​

ByteString

state hash root

Returns​

ByteString

locking script of state hash root output


checkIndex()​

static checkIndex(indexVal, indexBytes): void

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:164

Check if the index value and bytes are matched

Parameters​

indexVal​

Int32

value of the input index or output index

indexBytes​

ByteString

ByteString of the input index or output index

Returns​

void


indexValueToBytes()​

static indexValueToBytes(indexVal): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:149

Convert tx input index or output index from value to bytes

Parameters​

indexVal​

Int32

value of the input index or output index

Returns​

ByteString

ByteString of the input index or output index


loadArtifact()​

static loadArtifact(artifact): typeof SmartContractLib

Defined in: packages/scrypt-ts-btc/src/smart-contract/smartContractLib.ts:18

Parameters​

artifact​

Artifact

Returns​

typeof SmartContractLib

Inherited from​

SmartContractLib.loadArtifact


mergeInput()​

static mergeInput(txInput): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:221

Merge tx input into a ByteString

Parameters​

txInput​

TxIn

tx input, must be a segwit input

Returns​

ByteString

serialized tx input


mergePrevouts()​

static mergePrevouts(prevouts): MergePrevoutsResponse

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:64

Merge prevout list into a single ByteString

Parameters​

prevouts​

Prevouts

prevout list to merge

Returns​

MergePrevoutsResponse

merged prevouts and number of tx inputs


mergeSpentAmounts()​

static mergeSpentAmounts(amounts, t_inputCount): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:131

Merge spent amount list into a single ByteString

Parameters​

amounts​

SpentAmounts

spent amount list to merge

t_inputCount​

bigint

the number of tx inputs, must be verified and trusable

Returns​

ByteString

merged spent amounts


mergeSpentScripts()​

static mergeSpentScripts(scripts, t_inputCount): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:107

Merge spent script list into a single ByteString

Parameters​

scripts​

SpentScripts

spent script list to merge

t_inputCount​

bigint

the number of tx inputs, must be verified and trusable

Returns​

ByteString

merged spent scripts


toSatoshis()​

static toSatoshis(n): ByteString

Defined in: packages/scrypt-ts-btc/src/smart-contract/builtin-libs/txUtils.ts:319

convert a Int32 number to 8 bytes in little-end order.

Parameters​

n​

Int32

the satoshi amount

Returns​

ByteString

a ByteString