Documentation / @cashconnect-js/core / primitives/script
Script
Defined in: cashconnect-js/packages/core/src/primitives/script.ts:31
Script Entity.
Example
// Import our primitives
import { Script } from '@libcash/primitives';
// Create a script from ASM.
const script = Script.fromASM('OP_RETURN <0xbeef>');
// Output as in hexadecimal representation.
console.log(script.toHex());
// Output as bytecode.
console.log(script);Methods
from()
static from(script): Script;Defined in: cashconnect-js/packages/core/src/primitives/script.ts:52
Instantiates a Script from either Bytes or Hex.
Parameters
| Parameter | Type | Description |
|---|---|---|
script | string | Bytes | Uint8Array<ArrayBufferLike> | The script as either Bytes or Hex. |
Returns
The created Script Primitive.
Throws
If the script cannot be decoded.
fromBytes()
static fromBytes(bytes): Script;Defined in: cashconnect-js/packages/core/src/primitives/script.ts:67
Create a Script Entity from bytes.
Parameters
| Parameter | Type | Description |
|---|---|---|
bytes | Bytes | Uint8Array<ArrayBufferLike> | {string} Script Bytecode |
Returns
The created Script Entity.
Throws
If script cannot be decoded.
fromASM()
static fromASM(asm, disallowUnknown): Script;Defined in: cashconnect-js/packages/core/src/primitives/script.ts:84
Create a Script Entity from the given Assembly String.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
asm | string | undefined | {string} String of assembly code. |
disallowUnknown | boolean | true | - |
Returns
The created Script Entity.
Throws
If script cannot be decoded.
fromCashASM()
static fromCashASM(cashASM, data?): Script;Defined in: cashconnect-js/packages/core/src/primitives/script.ts:129
Create a Script Entity from the given CashASM String.
Parameters
| Parameter | Type | Description |
|---|---|---|
cashASM | string | String of CashASM to compile. |
data? | Record<string, Uint8Array<ArrayBufferLike>> | AddressData to pass to the CashASM compiler |
Returns
The created Script Entity.
Throws
If script cannot be decoded.
fromHex()
static fromHex(hex): Script;Defined in: cashconnect-js/packages/core/src/primitives/script.ts:179
Create a Script Entity from the given bytes (as hexadecimal string).
Parameters
| Parameter | Type | Description |
|---|---|---|
hex | string | {string} Raw script bytes encoded as hexadecimal. |
Returns
The created Script Entity.
Throws
If script cannot be decoded.
fromRaw()
static fromRaw(bytes): Script;Defined in: cashconnect-js/packages/core/src/primitives/script.ts:193
Creates an instance from serialized data.
Parameters
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array | Serialized Primitive Data |
Returns
A new instance of this primitive.
Remarks
This method is UNSAFE and MUST only be used where input is already verified or trusted.
toASM()
toASM(joinWith): string;Defined in: cashconnect-js/packages/core/src/primitives/script.ts:202
Convert this script to a human-readable string of assembly.
Parameters
| Parameter | Type | Default value |
|---|---|---|
joinWith | string | '\n' |
Returns
string
Human-readable assembly.
toBytes()
toBytes(): Bytes;Defined in: cashconnect-js/packages/core/src/primitives/script.ts:217
Get the raw bytecode for this script.
Returns
The compiled bytes.
toHex()
toHex(): string;Defined in: cashconnect-js/packages/core/src/primitives/script.ts:226
Get the raw bytecode for this script as a hex string.
Returns
string
The compiled bytes as a hex string.
toRaw()
toRaw(): Bytes;Defined in: cashconnect-js/packages/core/src/primitives/script.ts:235
Converts this primitive to a serializable raw object representation.
Returns
Serialzied primitive data.