Skip to content

CompiledContract (Class)

A compiled SilverScript contract: the locking script plus the metadata needed to build unlocking (signature) scripts for its entrypoints.

abi property

abi: list[EntryAbi]

The contract ABI: one entry per callable entrypoint, ordered alphabetically by name.

The same order a ContractArtifact reports, so an entrypoint keeps the same position either way. To reach one entry, prefer entry(name) over indexing.

bytecode property

bytecode: bytes

The compiled locking script (redeem script) bytes.

compiler_version property

compiler_version: str

The compiler version that produced this contract.

contract_name property

contract_name: str

The contract name from the SilverScript source.

state_span property

state_span: tuple[int, int]

(offset, len): byte offset and length of the contract state within the script.

The same two numbers, under the same name, as the artifact's compiled.state_span in artifact_json().

template_hash property

template_hash: bytes

The canonical length-bound template hash: a 32-byte digest over the script's template parts (the prefix before and suffix after the state region). Matches the SilverScript templateHash(prefix, suffix) builtin, so contracts can commit to this value and later reconstruct it on-chain.

__repr__

__repr__() -> str

The detailed string representation.

RETURNS DESCRIPTION
str

The CompiledContract as a repr string.

TYPE: str

artifact_json

artifact_json() -> str

Serialize the contract's portable ABI artifact as JSON.

The artifact is built once by compile and is what build_sig_script encodes against. For the same source and constructor arguments this is identical to what the upstream silverc compiler writes, so artifacts are interchangeable between the two.

RETURNS DESCRIPTION
str

The portable artifact as pretty-printed JSON. Pass it to json.loads for a dict.

TYPE: str

RAISES DESCRIPTION
SilverScriptError

If the artifact cannot be serialized.

build_sig_script

build_sig_script(function_name: str, args: Optional[Any] = None) -> bytes

Build the signature (unlocking) script for an entrypoint.

PARAMETER DESCRIPTION
function_name

The entrypoint to call.

TYPE: str

args

Native Python values (int, bool, str, bytes, list/tuple, or dict) matching the entrypoint's ABI input types. Omit or pass None for an entrypoint that takes no arguments.

TYPE: Optional[Any] DEFAULT: None

RETURNS DESCRIPTION
bytes

The signature (unlocking) script.

TYPE: bytes

RAISES DESCRIPTION
SilverScriptError

If the entrypoint is unknown or an argument is invalid (wrong type, out of range, or too deeply nested).

build_sig_script_for_covenant_decl

build_sig_script_for_covenant_decl(function_name: str, args: Optional[Any] = None, *, is_leader: bool = False) -> bytes

Build the signature (unlocking) script for a covenant declaration entrypoint.

PARAMETER DESCRIPTION
function_name

The covenant entrypoint to call.

TYPE: str

args

Native Python values matching the ABI input types of the entry this call resolves to — the declaration's leader entry, or the contract's shared delegate entry when is_leader is False. A #[covenant.delegate] body gives the delegate entry its own parameters, so the two paths take different arguments. Omit or pass None for an entry that takes no arguments.

TYPE: Optional[Any] DEFAULT: None

is_leader

Select the leader path for covenants that distinguish a leader from delegates (default: False).

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
bytes

The signature (unlocking) script.

TYPE: bytes

RAISES DESCRIPTION
SilverScriptError

If the entrypoint is unknown or an argument is invalid (wrong type, out of range, or too deeply nested).

entry

entry(name: str) -> EntryAbi

Look up one entrypoint's ABI by name.

PARAMETER DESCRIPTION
name

The entrypoint name, as it appears in abi.

TYPE: str

RETURNS DESCRIPTION
EntryAbi

The entrypoint's ABI.

TYPE: EntryAbi

RAISES DESCRIPTION
SilverScriptError

If the contract declares no such entrypoint. The message matches the one build_sig_script raises for the same name.