Utils
scrypt-ts / Utils
Class: Utils
The Utils library provides a set of commonly used utility functions.
Table of contents
Constructors
Properties
Methods
- buildAddressOutput
- buildAddressScript
- buildOpreturnScript
- buildOutput
- buildPublicKeyHashOutput
- buildPublicKeyHashScript
- fromLEUnsigned
- readVarint
- toLEUnsigned
- writeVarint
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
Name | Type | Description |
---|---|---|
addr | Ripemd160 | the recipient's address |
amount | bigint | the satoshi amount |
Returns
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
Name | Type | Description |
---|---|---|
addr | Ripemd160 | the recipient's address |
Returns
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
Name | Type | Description |
---|---|---|
data | ByteString | the data payload |
Returns
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
Name | Type | Description |
---|---|---|
outputScript | ByteString | the locking script |
outputSatoshis | bigint | the satoshi amount |
Returns
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
Name | Type | Description |
---|---|---|
pubKeyHash | Ripemd160 | the recipient's public key hash |
amount | bigint | the satoshi amount |
Returns
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
Name | Type | Description |
---|---|---|
pubKeyHash | Ripemd160 | the recipient's public key hash |
Returns
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
Name | Type | Description |
---|---|---|
bytes | ByteString | the 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
Name | Type | Description |
---|---|---|
buf | ByteString | a buffer ByteString |
Returns
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
Name | Type | Description |
---|---|---|
n | bigint | the number to be converted |
l | bigint | expected length |
Returns
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
Name | Type | Description |
---|---|---|
buf | ByteString | a buffer ByteString |
Returns
return a ByteString
appended the VarInt
Defined in
dist/smart-contract/builtins/functions.d.ts:937