SmartContracts

SmartContracts

class SmartContracts(**kwargs)

Implements the smartcontracts api endpoints.

code(address: Union[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: Union[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: Union[Address, str], storage_key: str, data_type: int, **kwargs) Union[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: Union[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: Union[Money, int, float, decimal.Decimal], password: str, contract_code: Union[hexstr, str], gas_price: int, gas_limit: int, sender: Union[Address, str], amount: Union[Money, int, float, decimal.Decimal], outpoints: Optional[List[Outpoint]] = None, account_name: str = 'account 0', parameters: Optional[List[Union[str, SmartContractParameter]]] = 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: Union[Money, int, float, decimal.Decimal], password: str, contract_address: Union[Address, str], method_name: str, gas_price: int, gas_limit: int, sender: Union[Address, str], amount: Optional[Union[Money, int, float, decimal.Decimal]] = None, outpoints: Optional[List[Outpoint]] = None, account_name: str = 'account 0', parameters: Optional[List[Union[str, SmartContractParameter]]] = 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: Union[Address, str], password: str, wallet_name: str, recipients: List[Recipient], op_return_data: Optional[str] = None, outpoints: Optional[List[Outpoint]] = None, op_return_amount: Optional[Union[Money, int, float, decimal.Decimal]] = None, fee_type: Optional[str] = None, allow_unconfirmed: bool = False, shuffle_outputs: bool = False, change_address: Optional[Union[Address, str]] = None, account_name: str = 'account 0', segwit_change_address: bool = False, fee_amount: Optional[Union[Money, int, float, decimal.Decimal]] = 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: Union[Address, str], wallet_name: str, recipients: List[Recipient], fee_type: str, outpoints: Optional[List[Outpoint]] = None, allow_unconfirmed: bool = False, shuffle_outputs: bool = False, op_return_data: Optional[str] = None, op_return_amount: Optional[Union[Money, int, float, decimal.Decimal]] = None, account_name: str = 'account 0', change_address: Optional[Union[Address, str]] = 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: Union[Money, int, float, decimal.Decimal], password: str, contract_code: Union[hexstr, str], gas_price: int, gas_limit: int, sender: Union[Address, str], amount: Optional[Union[Money, int, float, decimal.Decimal]] = None, outpoints: Optional[List[Outpoint]] = None, account_name: str = 'account 0', parameters: Optional[List[Union[str, SmartContractParameter]]] = 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: Union[Money, int, float, decimal.Decimal], password: str, contract_address: Union[Address, str], method_name: str, gas_price: int, gas_limit: int, sender: Union[Address, str], amount: Optional[Union[Money, int, float, decimal.Decimal]] = None, outpoints: Optional[List[Outpoint]] = None, account_name: str = 'account 0', parameters: Optional[List[Union[str, SmartContractParameter]]] = 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: Union[Address, str], method_name: str, amount: Union[Money, int, float, decimal.Decimal], gas_price: int, gas_limit: int, sender: Union[Address, str], block_height: Optional[int] = None, parameters: Optional[List[Union[str, SmartContractParameter]]] = 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: Optional[str]

The build transaction message.

success: Optional[bool]

True if build was successful.

transaction_id: Optional[uint256]

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: Optional[str]

The build transaction message.

success: Optional[bool]

True if build was successful.

transaction_id: Optional[uint256]

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: Optional[str]

A message from response.

LocalExecutionResultModel

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

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

internal_transfers: Optional[List[TransferInfoModel]]

A list of internal transfers.

gas_consumed: int

The amount of gas consumed by the call.

revert: Optional[bool]

If true, call was not successful.

error_message: Optional[str]

An error message, if thrown.

return_obj: Optional[Any]

An optional return object.

logs: Optional[List[LogModel]]

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: Optional[Address]

The smart contact address.

topics: Optional[List[str]]

A list of topics.

data: Optional[str]

Log data.

log: Optional[dict]

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: 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: Optional[uint256]

The smart contact state after execution.

gas_used: Optional[int]

The amount of gas used.

from_address: Optional[Address]

Sending address, if applicable.

to_address: Optional[Address]

Receiving address, if applicable.

new_contract_address: Optional[Address]

A new contract address, if creation transaction.

success: bool

True if transaction successful.

return_value: Optional[str]

Transaction return value, if applicable.

bloom: Optional[hexstr]

The bloom filter.

error: Optional[str]

Error message, if present.

logs: Optional[List[LogModel]]

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.