Skip to main content

Utils

scrypt-ts / Utils

Class: Utils

The Utils library provides a set of commonly used utility functions.

Table of contents​

Constructors​

Properties​

Methods​

Constructors​

constructor​

• new Utils()

Properties​

OutputValueLen​

▪ Static Readonly OutputValueLen: bigint

number of string to denote output value

Defined in​

dist/smart-contract/builtins/functions.d.ts:910


PubKeyHashLen​

▪ Static Readonly PubKeyHashLen: bigint

number of string to denote a public key hash

Defined in​

dist/smart-contract/builtins/functions.d.ts:912

Methods​

buildAddressOutput​

▸ Static buildAddressOutput(addr, amount): ByteString

constructs a standard payment (P2PKH) output from a given address and satoshi amount

Parameters​

NameTypeDescription
addrRipemd160the recipient's address
amountbigintthe satoshi amount

Returns​

ByteString

a ByteString representing the P2PKH output

Defined in​

dist/smart-contract/builtins/functions.d.ts:970


buildAddressScript​

▸ Static buildAddressScript(addr): ByteString

constructs a standard payment (P2PKH) script from a given address

Parameters​

NameTypeDescription
addrRipemd160the recipient's address

Returns​

ByteString

a ByteString representing the P2PKH script

Defined in​

dist/smart-contract/builtins/functions.d.ts:963


buildOpreturnScript​

▸ Static buildOpreturnScript(data): ByteString

build OP_FALSE OP_RETURN script from data payload

Parameters​

NameTypeDescription
dataByteStringthe data payload

Returns​

ByteString

a ByteString contains the data payload

Defined in​

dist/smart-contract/builtins/functions.d.ts:976


buildOutput​

▸ Static buildOutput(outputScript, outputSatoshis): ByteString

build a tx output from its script and satoshi amount

Parameters​

NameTypeDescription
outputScriptByteStringthe locking script
outputSatoshisbigintthe satoshi amount

Returns​

ByteString

a ByteString that represents an output

Defined in​

dist/smart-contract/builtins/functions.d.ts:944


buildPublicKeyHashOutput​

▸ Static buildPublicKeyHashOutput(pubKeyHash, amount): ByteString

constructs a P2PKH output from a given PubKeyHash and satoshi amount

Parameters​

NameTypeDescription
pubKeyHashRipemd160the recipient's public key hash
amountbigintthe satoshi amount

Returns​

ByteString

a ByteString representing the P2PKH output

Defined in​

dist/smart-contract/builtins/functions.d.ts:957


buildPublicKeyHashScript​

▸ Static buildPublicKeyHashScript(pubKeyHash): ByteString

constructs a P2PKH script from a given PubKeyHash

Parameters​

NameTypeDescription
pubKeyHashRipemd160the recipient's public key hash

Returns​

ByteString

a ByteString representing the P2PKH script

Defined in​

dist/smart-contract/builtins/functions.d.ts:950


fromLEUnsigned​

▸ Static fromLEUnsigned(bytes): bigint

convert ByteString to unsigned integer, in sign-magnitude little endian

Parameters​

NameTypeDescription
bytesByteStringthe ByteString to be converted

Returns​

bigint

returns a number

Defined in​

dist/smart-contract/builtins/functions.d.ts:925


readVarint​

▸ Static readVarint(buf): ByteString

read a [VarInt (variable integer)][https://learnmeabitcoin.com/technical/varint](https://learnmeabitcoin.com/technical/varint) field from the beginning of 'buf'

Parameters​

NameTypeDescription
bufByteStringa buffer ByteString

Returns​

ByteString

return a ByteString of the VarInt field

Defined in​

dist/smart-contract/builtins/functions.d.ts:931


toLEUnsigned​

▸ Static toLEUnsigned(n, l): ByteString

convert signed integer n to unsigned integer of l string, in little endian

Parameters​

NameTypeDescription
nbigintthe number to be converted
lbigintexpected length

Returns​

ByteString

returns a ByteString

Defined in​

dist/smart-contract/builtins/functions.d.ts:919


writeVarint​

▸ Static writeVarint(buf): ByteString

convert 'b' to a [VarInt (variable integer)][https://learnmeabitcoin.com/technical/varint](https://learnmeabitcoin.com/technical/varint) field, including the preceding length

Parameters​

NameTypeDescription
bufByteStringa buffer ByteString

Returns​

ByteString

return a ByteString appended the VarInt

Defined in​

dist/smart-contract/builtins/functions.d.ts:937