SmartContracts

SmartContracts

class SmartContracts(**kwargs)

Implements the smartcontracts api endpoints.

code(address: Address | str, **kwargs) GetCodeModel

Gets the bytecode for a smart contract as a hexadecimal string.

Parameters:
  • address (Address, str) – The smart contract address containing the contract bytecode.

  • **kwargs – Extra keyword arguments.

Returns:

The smart contract code.

Return type:

GetCodeModel

Raises:

APIError – Error thrown by node API. See message for details.

balance(address: Address | str, **kwargs) Money

Gets the balance of a smart contract in strax or sidechain coin.

Parameters:
  • address (Address, str) – The smart contract address.

  • **kwargs – Extra keyword arguments.

Returns:

The smart contract balance.

Return type:

Money

Raises:

APIError – Error thrown by node API. See message for details.

storage(contract_address: Address | str, storage_key: str, data_type: int, **kwargs) bool | bytes | str | uint32 | uint64 | int32 | int64 | Address | bytearray | uint128 | uint256

Gets a single piece of smart contract data. Returns a serialized string, if exists.

Parameters:
  • contract_address (Address, str) – The smart contract address being called.

  • storage_key (str) – The key in the key-value store.

  • data_type – The data type. Allowed values: [1,12]

  • **kwargs – Extra keyword arguments.

Returns:

The smart contract information retrieved from storage.

Return type:

Union[bool, bytes, str, uint32, uint64, int32, int64, Address, bytearray, uint128, uint256]

Raises:
  • APIError – Error thrown by node API. See message for details.

  • RuntimeError

receipt(tx_hash: uint256 | str, **kwargs) ReceiptModel

Gets a smart contract transaction receipt.

Parameters:
  • tx_hash (uint256, str) – The transaction hash of the smart contract receipt.

  • **kwargs – Extra keyword arguments.

Returns:

The smart contract transaction receipt.

Return type:

ReceiptModel

Raises:

APIError – Error thrown by node API. See message for details.

Searches a smart contract’s receipts for those which match a specific event.

Parameters:
  • contract_address (Address, str) – The address for the smart contract.

  • event_name (str, optional) – The event to search for.

  • topics (List[str], optional) – A list of topics to search for.

  • from_block (int) – Block to start search from.

  • to_block (int, optional) – Block to search up to.

  • **kwargs – Extra keyword arguments.

Returns:

A list of receipts.

Return type:

List[ReceiptModel]

Raises:

APIError – Error thrown by node API. See message for details.

build_create(wallet_name: str, fee_amount: Money | int | float | Decimal, password: str, contract_code: hexstr | str, gas_price: int, gas_limit: int, sender: Address | str, amount: Money | int | float | Decimal, outpoints: List[Outpoint] | None = None, account_name: str = 'account 0', parameters: List[str | SmartContractParameter] | None = None, **kwargs) BuildCreateContractTransactionModel

Builds a transaction to create a smart contract.

Parameters:
  • wallet_name (str) – The wallet name.

  • account_name (str, optional) – The wallet name. Default=’account 0’

  • outpoints (List[Outpoint], optional) – A list of the outpoints used to construct the transactation.

  • amount (Money, int, float, Decimal, optional) – The amount being sent.

  • fee_amount (Money, int, float, Decimal) – The fee amount.

  • password (SecretStr) – The password.

  • contract_code (hexstr, str) – The smart contract code hexstring.

  • gas_price (int) – The amount of gas being used in satoshis.

  • gas_limit (int) – The maximum amount of gas that can be used in satoshis.

  • sender (Address, str) – The address of the sending address.

  • parameters (List[Union[SmartContractParameter, str], optional) – A list of parameters for the smart contract.

  • **kwargs – Extra keyword arguments.

Returns:

A built create smart contract transaction.

Return type:

BuildCreateContractTransactionModel

Raises:

APIError – Error thrown by node API. See message for details.

build_call(wallet_name: str, fee_amount: Money | int | float | Decimal, password: str, contract_address: Address | str, method_name: str, gas_price: int, gas_limit: int, sender: Address | str, amount: Money | int | float | Decimal | None = None, outpoints: List[Outpoint] | None = None, account_name: str = 'account 0', parameters: List[str | SmartContractParameter] | None = None, **kwargs) BuildContractTransactionModel

Builds a transaction to call a smart contract method.

Parameters:
  • wallet_name (str) – The wallet name.

  • account_name (str, optional) – The wallet name. Default=’account 0’

  • outpoints (List[Outpoint], optional) – A list of the outpoints used to construct the transactation.

  • contract_address (Address, str) – The smart contract address being called.

  • method_name (str) – The method name being called.

  • amount (Money, int, float, Decimal, optional) – The amount being sent.

  • fee_amount (Money, int, float, Decimal) – The fee amount.

  • password (SecretStr) – The password.

  • gas_price (int) – The amount of gas being used in satoshis.

  • gas_limit (int) – The maximum amount of gas that can be used in satoshis.

  • sender (Address, str) – The address of the sending address.

  • parameters (List[Union[SmartContractParameter, str]], optional) – A list of parameters for the smart contract.

  • **kwargs – Extra keyword arguments.

Returns:

A built smart contract transaction.

Return type:

BuildContractTransactionModel

Raises:

APIError – Error thrown by node API. See message for details.

build_transaction(sender: Address | str, password: str, wallet_name: str, recipients: List[Recipient], op_return_data: str | None = None, outpoints: List[Outpoint] | None = None, op_return_amount: Money | int | float | Decimal | None = None, fee_type: str | None = None, allow_unconfirmed: bool = False, shuffle_outputs: bool = False, change_address: Address | str | None = None, account_name: str = 'account 0', segwit_change_address: bool = False, fee_amount: Money | int | float | Decimal | None = None, **kwargs) BuildContractTransactionModel

Build a transaction to transfer funds on a smart contract network.

Parameters:
  • sender (Address) – The sender address.

  • fee_amount (Money, int, float, Decimal, optional) – The fee amount.

  • password (SecretStr) – The password.

  • segwit_change_address (bool, optional) – If the change address is a segwit address. Default=False.

  • wallet_name (str) – The wallet name.

  • account_name (str, optional) – The account name. Default=’account 0’.

  • outpoints (List[Outpoint]) – A list of the outpoints used to construct the transactation.

  • recipients (List[Recipient]) – A list of the recipients, including amounts, for the transaction.

  • op_return_data (str, optional) – OP_RETURN data to include with the transaction.

  • op_return_amount (Money, int, float, Decimal, optional) – Amount to burn in the OP_RETURN transaction.

  • fee_type (str, optional) – low, medium, or high.

  • allow_unconfirmed (bool, optional) – If True, allow unconfirmed transactions in the estimation. Default=False

  • shuffle_outputs (bool, optional) – If True, shuffles outputs. Default=False.

  • change_address (Address, optional) – Sends output sum less amount sent to recipients to this designated change address, if provided.

  • **kwargs – Extra keyword arguments.

Returns:

A built smart contract transaction.

Return type:

BuildContractTransactionModel

Raises:

APIError – Error thrown by node API. See message for details.

estimate_fee(sender: Address | str, wallet_name: str, recipients: List[Recipient], fee_type: str, outpoints: List[Outpoint] | None = None, allow_unconfirmed: bool = False, shuffle_outputs: bool = False, op_return_data: str | None = None, op_return_amount: Money | int | float | Decimal | None = None, account_name: str = 'account 0', change_address: Address | str | None = None, **kwargs) Money

Gets a fee estimate for a specific smart contract account-based transfer transaction.

Parameters:
  • sender (Address, str) – The sender address.

  • wallet_name (str) – The wallet name.

  • account_name (str, optional) – The account name. Default=’account 0’.

  • outpoints (List[Outpoint], optional) – A list of the outpoints used to construct the transactation.

  • recipients (List[Recipient]) – A list of the recipients, including amounts, for the transaction.

  • op_return_data (str, optional) – OP_RETURN data to include with the transaction.

  • op_return_amount (Money, int, float, Decimal, optional) – Amount to burn in the OP_RETURN transaction.

  • fee_type (str, optional) – low, medium, or high.

  • allow_unconfirmed (bool, optional) – If True, allow unconfirmed transactions in the estimation. Default=False

  • shuffle_outputs (bool, optional) – If True, shuffles outputs. Default=False.

  • change_address (Address, str, optional) – Sends output sum less amount sent to recipients to this designated change address, if provided.

  • **kwargs – Extra keyword arguments.

Returns:

The fee estimate.

Return type:

Money

Raises:

APIError – Error thrown by node API. See message for details.

build_and_send_create(wallet_name: str, fee_amount: Money | int | float | Decimal, password: str, contract_code: hexstr | str, gas_price: int, gas_limit: int, sender: Address | str, amount: Money | int | float | Decimal | None = None, outpoints: List[Outpoint] | None = None, account_name: str = 'account 0', parameters: List[str | SmartContractParameter] | None = None, **kwargs) BuildCreateContractTransactionModel

Builds a transaction to create a smart contract and then broadcasts.

Parameters:
  • wallet_name (str) – The wallet name.

  • account_name (str, optional) – The wallet name. Default=’account 0’

  • outpoints (List[Outpoint], optional) – A list of the outpoints used to construct the transactation.

  • amount (Money, int, float, Decimal, optional) – The amount being sent.

  • fee_amount (Money, int, float, Decimal) – The fee amount.

  • password (SecretStr) – The password.

  • contract_code (hexstr, str) – The smart contract code hexstring.

  • gas_price (int) – The amount of gas being used in satoshis.

  • gas_limit (int) – The maximum amount of gas that can be used in satoshis.

  • sender (Address, str) – The address of the sending address.

  • parameters (List[Union[SmartContractParameter, str]], optional) – A list of parameters for the smart contract.

  • **kwargs – Extra keyword arguments.

Returns:

A built create smart contract transaction.

Return type:

BuildCreateContractTransactionModel

Raises:

APIError – Error thrown by node API. See message for details.

build_and_send_call(wallet_name: str, fee_amount: Money | int | float | Decimal, password: str, contract_address: Address | str, method_name: str, gas_price: int, gas_limit: int, sender: Address | str, amount: Money | int | float | Decimal | None = None, outpoints: List[Outpoint] | None = None, account_name: str = 'account 0', parameters: List[str | SmartContractParameter] | None = None, **kwargs) BuildContractTransactionModel

Builds a transaction to call a smart contract method and then broadcasts.

Parameters:
  • wallet_name (str) – The wallet name.

  • account_name (str, optional) – The wallet name. Default=’account 0’

  • outpoints (List[Outpoint], optional) – A list of the outpoints used to construct the transactation.

  • contract_address (Address, str) – The smart contract address being called.

  • method_name (str) – The method name being called.

  • amount (Money, int, float, Decimal, optional) – The amount being sent.

  • fee_amount (Money, int, float, Decimal) – The fee amount.

  • password (SecretStr) – The password.

  • gas_price (int) – The amount of gas being used in satoshis.

  • gas_limit (int) – The maximum amount of gas that can be used in satoshis.

  • sender (Address, str) – The address of the sending address.

  • parameters (List[Union[SmartContractParameter, str]], optional) – A list of parameters for the smart contract.

  • **kwargs – Extra keyword arguments.

Returns:

A built smart contract transaction.

Return type:

BuildContractTransactionModel

Raises:

APIError – Error thrown by node API. See message for details.

local_call(contract_address: Address | str, method_name: str, amount: Money | int | float | Decimal, gas_price: int, gas_limit: int, sender: Address | str, block_height: int | None = None, parameters: List[str | SmartContractParameter] | None = None, **kwargs) LocalExecutionResultModel

Makes a local call to a method on a smart contract that has been successfully deployed. The purpose is to query and test methods.

Parameters:
  • contract_address (Address, str) – The smart contract address being called.

  • method_name (str) – The smart contract method being called.

  • amount (Money, int, float, Decimal) – The amount being sent.

  • gas_price (int) – The amount of gas being used in satoshis.

  • gas_limit (int) – The maximum amount of gas that can be used in satoshis.

  • sender (Address, str) – The address of the sending address.

  • block_height (int, optional) – The height at which to query the contract’s state. If unset, will default to the current chain tip.

  • parameters (List[Union[SmartContractParameter, str]], optional) – A list of parameters for the smart contract.

  • **kwargs – Extra keyword arguments.

Returns:

The results of a local contract execution.

Return type:

LocalExecutionResultModel

Raises:

APIError – Error thrown by node API. See message for details.

address_balances(wallet_name: str, **kwargs) List[AddressBalanceModel]

Gets all addresses owned by a wallet which have a balance associated with them.

Parameters:
  • wallet_name (str) – The wallet name.

  • **kwargs – Extra keyword arguments.

Returns:

A list of addresses with balance information.

Return type:

List[AddressBalanceModel]

Raises:

APIError – Error thrown by node API. See message for details.

AddressBalanceModel

class AddressBalanceModel(*, address: Address, sum: Money)

A pydantic model for an address balance.

address: Address

The address.

sum: Money

The amount present at the address.

BuildContractTransactionModel

class BuildContractTransactionModel(*, fee: Money, hex: hexstr, message: str = None, success: bool = None, transactionId: uint256 = None)

A pydantic model for building a smart contact transaction.

fee: Money

The transaction fee.

hex: hexstr

The hex serialized transaction.

message: str | None

The build transaction message.

success: bool | None

True if build was successful.

transaction_id: uint256 | None

The transaction hash, if build successful.

BuildCreateContractTransactionModel

class BuildCreateContractTransactionModel(*, fee: Money, hex: hexstr, message: str = None, success: bool = None, transactionId: uint256 = None, newContractAddress: Address)

A pydantic model for a create smart contact transaction.

new_contract_address: Address

The new address associated with the smart contract.

fee: Money

The transaction fee.

hex: hexstr

The hex serialized transaction.

message: str | None

The build transaction message.

success: bool | None

True if build was successful.

transaction_id: uint256 | None

The transaction hash, if build successful.

GetCodeModel

class GetCodeModel(*, type: str, bytecode: str, csharp: str, message: str = None)

A pydantic model for the smart contact code request.

type: str

The code type.

bytecode: str

The contract bytecode.

csharp: str

The csharp code.

message: str | None

A message from response.

LocalExecutionResultModel

class LocalExecutionResultModel(*, internalTransfers: ~typing.List[~pystratis.api.smartcontracts.responsemodels.transferinfomodel.TransferInfoModel] = None, gasConsumed: int, revert: bool = None, errorMessage: str = None, return: ~typing.Any = None, logs: ~typing.List[~pystratis.api.smartcontracts.responsemodels.logmodel.LogModel] = None)

A pydantic model representing the result of a local smart contact execution call.

internal_transfers: List[TransferInfoModel] | None

A list of internal transfers.

gas_consumed: int

The amount of gas consumed by the call.

revert: bool | None

If true, call was not successful.

error_message: str | None

An error message, if thrown.

return_obj: Any | None

An optional return object.

logs: List[LogModel] | None

An optional list of logs returned.

LogModel

class LogModel(*, address: Address = None, topics: List[str] = None, data: str = None, log: dict = None)

A pydantic model of a smart contact log.

address: Address | None

The smart contact address.

topics: List[str] | None

A list of topics.

data: str | None

Log data.

log: dict | None

Log dict object response.

ReceiptModel

class ReceiptModel(*, transactionHash: ~pystratis.core.types.uint256.uint256, blockHash: ~pystratis.core.types.uint256.uint256, postState: ~pystratis.core.types.uint256.uint256 = None, gasUsed: int = None, from: ~pystratis.core.types.address.Address = None, to: ~pystratis.core.types.address.Address = None, newContractAddress: ~pystratis.core.types.address.Address = None, success: bool, returnValue: str = None, bloom: ~pystratis.core.types.hexstr.hexstr = None, error: str = None, logs: ~typing.List[~pystratis.api.smartcontracts.responsemodels.logmodel.LogModel] = None, blockNumber: int)

A pydantic model of a smart contact receipt.

transaction_hash: uint256

The transaction hash.

block_hash: uint256

The hash of the block containing the transaction.

post_state: uint256 | None

The smart contact state after execution.

gas_used: int | None

The amount of gas used.

from_address: Address | None

Sending address, if applicable.

to_address: Address | None

Receiving address, if applicable.

new_contract_address: Address | None

A new contract address, if creation transaction.

success: bool

True if transaction successful.

return_value: str | None

Transaction return value, if applicable.

bloom: hexstr | None

The bloom filter.

error: str | None

Error message, if present.

logs: List[LogModel] | None

Smart contact log model data, if present.

block_number: int

The block number.

TransferInfoModel

class TransferInfoModel(*, from: ~pystratis.core.types.address.Address, to: ~pystratis.core.types.address.Address, value: ~pystratis.core.types.money.Money)

A pydantic model of a smart contact transfer.

from_address: Address

The sending address.

to_address: Address

The receiving address.

value: Money

The amount sent.