cashscript_py.contract module

Contract API.

Provides loading and interaction with CashScript-contract artifacts, including constructor validation/encoding, address generation, and ABI-based unlockers.

class Contract(artifact: dict[str, Any], constructor_args: list[bool | int | str | bytes], provider: NetworkProvider, address_type: LockingBytecodeType = LockingBytecodeType.P2SH32)[source]

Bases: object

High-level interface to a CashScript contract.

A Contract is constructed from a compiled cashc JSON artifact and constructor arguments. It exposes ABI functions via the unlock mapping and provides helper methods for querying UTXOs and balances.

name

The contract name from the artifact.

address

The contract address (token-unaware).

token_address

The contract address (token-aware).

bytecode

Contract redeem script bytecode (hex).

bytesize

Size of the redeem script in bytes.

opcount

Count of non-push opcodes in the redeem script.

provider

Network provider used for blockchain operations.

address_type

Locking bytecode type (e.g., P2SH32).

unlock

Mapping of function name to unlocker factory.

async get_balance() int[source]

Return the total balance (sum of UTXO satoshis) at the contract address.

Returns:

The sum of satoshis across all UTXOs at the contract address.

async get_utxos() list[Utxo][source]

Fetch all UTXOs (confirmed/unconfirmed) for the contract address.

Returns:

A list of UTXOs spendable by this contract.