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.
schema_version
property
¶
The artifact schema version. Checked by load_artifact.
state_span
property
¶
(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
¶
The 32-byte template hash recorded in the artifact.
Recorded, not recomputed — check_consistency is what verifies it
against the bytecode.
__repr__
¶
The detailed string representation.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The ContractArtifact as a repr string.
TYPE:
|
build_sig_script
¶
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:
|
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:
|
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
The signature (unlocking) script.
TYPE:
|
| 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:
|
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
TYPE:
|
is_leader
|
Select the leader path for covenants that distinguish a leader from delegates (default: False).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
The signature (unlocking) script.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
SilverScriptError
|
If the entrypoint is unknown or an argument is invalid (wrong type, out of range, or too deeply nested). |
check_consistency
¶
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
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EntryAbi
|
The entrypoint's ABI.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
SilverScriptError
|
If the artifact declares no such entrypoint. The
message matches the one |
to_json
¶
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:
|
| RAISES | DESCRIPTION |
|---|---|
SilverScriptError
|
If the artifact cannot be serialized. |