Helios API/ API Reference/ Classes/

UplcProgram

Result of program.compile(). Contains the Untyped Plutus-Core AST, along with a code-mapping to the original source.

Index

Constructors

constructor

new UplcProgram(expr, properties?, version?)

Parameters

NameType
exprUplcTerm
properties?ProgramProperties
version?UplcInt[]

Accessors

expr

get expr(): UplcTerm

Returns

UplcTerm

mintingPolicyHash

get mintingPolicyHash(): MintingPolicyHash

Returns the MintingPolicyHash of the script. Throws an error if this isn't a minting policy.

Returns

MintingPolicyHash

properties

get properties(): ProgramProperties

Returns

ProgramProperties

site

get site(): Site

Returns

Site

src

get src(): string

Returns the IR source

Returns

string

stakingValidatorHash

get stakingValidatorHash(): StakingValidatorHash

Returns the StakingValidatorHash of the script. Throws an error if this isn't a staking validator script.

Returns

StakingValidatorHash

validatorHash

get validatorHash(): ValidatorHash

Returns the ValidatorHash of the script. Throws an error if this isn't a spending validator script.

Returns

ValidatorHash

versionString

get versionString(): string

Returns version of Plutus-core (!== Plutus script version!)

Returns

string

transferUplcAst

Static get transferUplcAst(): TransferUplcAst

Returns

TransferUplcAst

Methods

apply

apply(args): UplcProgram

Wrap the top-level term with consecutive UplcCall (not exported) terms.

Returns a new UplcProgram instance, leaving the original untouched.

Parameters

NameType
argsUplcValue[]

Returns

UplcProgram

  • a new UplcProgram instance

calcSize

calcSize(): number

Calculates the on chain size of the program (number of bytes).

Returns

number

hash

hash(): number[]

Returns

number[]

  • 28 byte hash

plutusScriptVersion

plutusScriptVersion(): string

Returns

string

profile

profile(args, networkParams): Promise<Profile>

Runs and profiles a UplcProgram. Needs the NetworkParams in order to calculate the execution budget.

Parameters

NameType
argsUplcValue[]
networkParamsNetworkParams

Returns

Promise<Profile>

The returned profile contains a breakdown of the execution cost per Uplc term type and per Uplc builtin function type.

run

run(args, callbacks?, networkParams?): Promise<RuntimeError | UplcValue>

Parameters

NameTypeDescription
argsnull | UplcValue[]if null the top-level term is returned as a value
callbacks?UplcRTECallbacks
networkParams?null | NetworkParams

Returns

Promise<RuntimeError | UplcValue>

runWithPrint

runWithPrint(args): Promise<[RuntimeError | UplcValue, string[]]>

Run a UplcProgram. The printed messages are part of the return value.

Parameters

NameType
argsnull | UplcValue[]

Returns

Promise<[RuntimeError | UplcValue, string[]]>

serialize

serialize(): string

Returns the JSON representation of the serialized program (needed by cardano-cli).

Returns

string

serializeBytes

serializeBytes(): number[]

Returns flat bytes of serialized script

Returns

number[]

toCbor

toCbor(): number[]

Returns the Cbor encoding of a script (flat bytes wrapped twice in Cbor bytearray).

Returns

number[]

toString

toString(): string

Returns

string

transfer

transfer<TInstance>(other): TInstance

Transfers a UplcProgram from an old version of Helios to a new version of Helios, keeping the script hash the same.

The main benefit for calling this method instead of serializing/deserializing is that the code mapping is maintained.

Type parameters

Name
TInstance

Parameters

NameType
otherTransferableUplcProgram<TInstance>

Returns

TInstance

versionTag

versionTag(): number

Returns 1 for PlutusScriptV1, 2 for PlutusScriptV2

Returns

number

fromCbor

Static fromCbor(bytes, properties?): UplcProgram

Parameters

NameType
bytesstring | number[]
properties?ProgramProperties

Returns

UplcProgram

fromFlat

Static fromFlat(bytes, properties?): UplcProgram

Parameters

NameType
bytesnumber[]
properties?ProgramProperties

Returns

UplcProgram

transferUplcProgram

Static transferUplcProgram(expr, properties, version): UplcProgram

Intended for transfer only

Parameters

NameType
exprany
propertiesProgramProperties
versionany[]

Returns

UplcProgram