SmartContracts

SmartContracts

class SmartContracts(**kwargs)

Implements the smartcontracts api endpoints.

address_balances(wallet_name: str, **kwargs) → List[pystratis.api.smartcontracts.responsemodels.addressbalancemodel.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.

balance(address: Union[pystratis.core.types.address.Address, str], **kwargs) → pystratis.core.types.money.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.

build_and_send_call(wallet_name: str, fee_amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal], password: str, contract_address: Union[pystratis.core.types.address.Address, str], method_name: str, gas_price: int, gas_limit: int, sender: Union[pystratis.core.types.address.Address, str], amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal] = None, outpoints: List[pystratis.core.outpoint.Outpoint] = None, account_name: str = 'account 0', parameters: List[Union[str, pystratis.core.smartcontractparameter.SmartContractParameter]] = None, **kwargs) → pystratis.api.global_responsemodels.buildcontracttransactionmodel.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.

build_and_send_create(wallet_name: str, fee_amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal], password: str, contract_code: Union[pystratis.core.types.hexstr.hexstr, str], gas_price: int, gas_limit: int, sender: Union[pystratis.core.types.address.Address, str], amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal] = None, outpoints: List[pystratis.core.outpoint.Outpoint] = None, account_name: str = 'account 0', parameters: List[Union[str, pystratis.core.smartcontractparameter.SmartContractParameter]] = None, **kwargs) → pystratis.api.global_responsemodels.buildcreatecontracttransactionmodel.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_call(wallet_name: str, fee_amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal], password: str, contract_address: Union[pystratis.core.types.address.Address, str], method_name: str, gas_price: int, gas_limit: int, sender: Union[pystratis.core.types.address.Address, str], amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal] = None, outpoints: List[pystratis.core.outpoint.Outpoint] = None, account_name: str = 'account 0', parameters: List[Union[str, pystratis.core.smartcontractparameter.SmartContractParameter]] = None, **kwargs) → pystratis.api.global_responsemodels.buildcontracttransactionmodel.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_create(wallet_name: str, fee_amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal], password: str, contract_code: Union[pystratis.core.types.hexstr.hexstr, str], gas_price: int, gas_limit: int, sender: Union[pystratis.core.types.address.Address, str], amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal], outpoints: List[pystratis.core.outpoint.Outpoint] = None, account_name: str = 'account 0', parameters: List[Union[str, pystratis.core.smartcontractparameter.SmartContractParameter]] = None, **kwargs) → pystratis.api.global_responsemodels.buildcreatecontracttransactionmodel.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_transaction(sender: Union[pystratis.core.types.address.Address, str], password: str, wallet_name: str, recipients: List[pystratis.core.recipient.Recipient], op_return_data: str = None, outpoints: List[pystratis.core.outpoint.Outpoint] = None, op_return_amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal] = None, fee_type: str = None, allow_unconfirmed: bool = False, shuffle_outputs: bool = False, change_address: Union[pystratis.core.types.address.Address, str] = None, account_name: str = 'account 0', segwit_change_address: bool = False, fee_amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal] = None, **kwargs) → pystratis.api.global_responsemodels.buildcontracttransactionmodel.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.

code(address: Union[pystratis.core.types.address.Address, str], **kwargs) → pystratis.api.smartcontracts.responsemodels.getcodemodel.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.

estimate_fee(sender: Union[pystratis.core.types.address.Address, str], wallet_name: str, recipients: List[pystratis.core.recipient.Recipient], fee_type: str, outpoints: List[pystratis.core.outpoint.Outpoint] = None, allow_unconfirmed: bool = False, shuffle_outputs: bool = False, op_return_data: str = None, op_return_amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal] = None, account_name: str = 'account 0', change_address: Union[pystratis.core.types.address.Address, str] = None, **kwargs) → pystratis.core.types.money.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.

local_call(contract_address: Union[pystratis.core.types.address.Address, str], method_name: str, amount: Union[pystratis.core.types.money.Money, int, float, decimal.Decimal], gas_price: int, gas_limit: int, sender: Union[pystratis.core.types.address.Address, str], parameters: List[Union[str, pystratis.core.smartcontractparameter.SmartContractParameter]] = None, **kwargs) → pystratis.api.smartcontracts.responsemodels.localexecutionresultmodel.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.
  • 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.

receipt(tx_hash: Union[pystratis.core.types.uint256.uint256, str], **kwargs) → pystratis.api.smartcontracts.responsemodels.receiptmodel.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) – 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.

storage(contract_address: Union[pystratis.core.types.address.Address, str], storage_key: str, data_type: int, **kwargs) → Union[bool, bytes, str, pystratis.core.types.uint32.uint32, pystratis.core.types.uint64.uint64, pystratis.core.types.int32.int32, pystratis.core.types.int64.int64, pystratis.core.types.address.Address, bytearray, pystratis.core.types.uint128.uint128, pystratis.core.types.uint256.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

AddressBalanceModel

class AddressBalanceModel

A pydantic model for an address balance.

BuildContractTransactionModel

class BuildContractTransactionModel

A pydantic model for building a smart contact transaction.

BuildCreateContractTransactionModel

class BuildCreateContractTransactionModel

A pydantic model for a create smart contact transaction.

GetCodeModel

class GetCodeModel

A pydantic model for the smart contact code request.

LocalExecutionResultModel

class LocalExecutionResultModel

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

LogModel

class LogModel

A pydantic model of a smart contact log.

ReceiptModel

class ReceiptModel

A pydantic model of a smart contact receipt.

TransferInfoModel

class TransferInfoModel

A pydantic model of a smart contact transfer.