Skip to content

ContractArtifact (Class)

A portable ABI artifact: everything needed to build unlocking scripts for a contract, without its source.

Obtained from load_artifact, never constructed directly.

abi property

abi: list[EntryAbi]

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

The same order CompiledContract.abi reports. 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 the artifact.

contract_name property

contract_name: str

The contract name this artifact was loaded for.

schema_version property

schema_version: int

The artifact schema version. Checked by load_artifact.

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 CompiledContract.state_span.

template_hash property

template_hash: bytes

The 32-byte template hash recorded in the artifact.

Recorded, not recomputed — check_consistency is what verifies it against the bytecode.

__repr__

__repr__() -> str

The detailed string representation.

RETURNS DESCRIPTION
str

The ContractArtifact as a repr string.

TYPE: str

build_sig_script

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

Build the signature (unlocking) script for an entrypoint.

Identical bytes to CompiledContract.build_sig_script for the same call: both encode against this same artifact.

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).

check_consistency

check_consistency() -> None

Verify the artifact's internal consistency, raising if it fails.

Checks the recorded template hash against the bytecode, the state span against the script, and the entries' dispatch tags for collisions — across every contract in the loaded artifact, not only the selected one.

RAISES DESCRIPTION
SilverScriptError

If the artifact is inconsistent.

Note

This detects a corrupted or edited artifact. It does not prove the bytecode was compiled from any particular source, so it does not make an untrusted artifact trustworthy: use artifacts from a trusted build, or compare template_hash against a known value.

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 artifact declares no such entrypoint. The message matches the one build_sig_script raises for the same name.

to_json

to_json() -> str

Serialize the artifact back to JSON.

The canonical form upstream writes: pretty-printed, fields in the artifact's own order. That form round trips byte-for-byte, so JSON from this method or from CompiledContract.artifact_json survives load/serialize unchanged. Merely equivalent JSON — compact, with keys reordered, or carrying unknown fields — comes back canonicalized rather than verbatim.

RETURNS DESCRIPTION
str

The portable artifact as pretty-printed JSON.

TYPE: str

RAISES DESCRIPTION
SilverScriptError

If the artifact cannot be serialized.