Provider

class ape_starknet.provider.StarknetDevnetProvider(*, name: str, network: NetworkAPI, provider_settings: dict, data_folder: Path, request_header: dict, cached_chain_id: Optional[int] = None, block_page_size: int = 100, concurrency: int = 4, client: Optional[GatewayClient] = None, cached_code: Dict[int, ContractCode] = {}, local_nonce_cache: Dict[int, int] = {}, process: Optional[Popen] = None, is_stopping: bool = False, stdout_queue: Optional[JoinableQueue] = None, stderr_queue: Optional[JoinableQueue] = None, PROCESS_WAIT_TIMEOUT: int = 15)

A subprocess provider for the starknet-devnet process.

build_command() List[str]

Get the command as a list of str. Subclasses should override and add command arguments if needed.

Returns:

The command to pass to subprocess.Popen.

Return type:

List[str]

connect()

Start the process and connect to it. Subclasses handle the connection-related tasks.

mine(num_blocks: int = 1)

Mine a number of blocks.

Parameters:

num_blocks (int) – The number of blocks to mine.

property process_name: str

The name of the process, such as Hardhat node.

set_balance(account: ChecksumAddress, amount: Union[int, float, str, bytes])

Mint the difference between the account’s current balance and the desired balance and give it to the account.

Parameters:
  • account (AddressType) – The contract account.

  • amount (Union[int, float, str, bytes]) – The amount of tokens to mint and add to the account.

set_timestamp(new_timestamp: int)

Set timestamp to devnet client.

Parameters:

new_timestamp (int) – The value to change the timestamp to in the devnet client.

class ape_starknet.provider.StarknetProvider(*, name: str, network: NetworkAPI, provider_settings: dict, data_folder: Path, request_header: dict, cached_chain_id: Optional[int] = None, block_page_size: int = 100, concurrency: int = 4, client: Optional[GatewayClient] = None, cached_code: Dict[int, ContractCode] = {}, local_nonce_cache: Dict[int, int] = {})

A Starknet provider.

property chain_id: int

The blockchain ID. See ChainList for a comprehensive list of IDs.

connect()

Connect a to a provider, such as start-up a process or create an HTTP connection.

property connected_client: GatewayClient

Connect to client or raises a ProviderNotConnectedError otherwise.

disconnect()

Disconnect from a provider, such as tear-down a process or quit an HTTP session.

estimate_gas_cost(**kwargs)

Estimate the cost of gas for a transaction.

Parameters:

txn (TransactionAPI) – The transaction to estimate the gas for.

Returns:

The estimated cost of gas to execute the transaction reported in the fee-currency’s smallest unit, e.g. Wei.

Return type:

int

property gas_price: int

Currently, the gas price is fixed to always be 100 gwei.

Type:

NOTE

get_balance(**kwargs)

Get the balance of an account.

Parameters:

address (AddressType) – The address of the account.

Returns:

The account balance.

Return type:

int

get_block(**kwargs)

Get a block.

Parameters:

block_id (BlockID) – The ID of the block to get. Can be "latest", "earliest", "pending", a block hash or a block number.

Raises:

BlockNotFoundError – Likely the exception raised when a block is not found (depends on implementation).

Returns:

The block for the given ID.

Return type:

BlockID

get_class_hash(address: ChecksumAddress) int

Get class hash of an address.

Parameters:

address (AddressType) – The address of the account.

get_code(**kwargs)

Get the bytes a contract.

Parameters:

address (AddressType) – The address of the contract.

Returns:

The contract bytecode.

Return type:

ContractCode

get_code_and_abi(address: Union[str, ChecksumAddress, int]) ContractCode

Get the contract code and the ABI of an address.

Parameters:

address (Union[str, AddressType, int]) – The address of the account.

Returns:

ContractCode

get_contract_logs(**kwargs)

Get logs from contracts.

Parameters:

log_filter (LogFilter) – A mapping of event ABIs to topic filters. Defaults to getting all events.

Returns:

Iterator[ContractLog]

get_nonce(**kwargs)

Get the number of times an account has transacted.

Parameters:

address (AddressType) – The address of the account.

Returns:

int

get_receipt(**kwargs)

Get the information about a transaction from a transaction hash.

Parameters:
  • txn_hash (str) – The hash of the transaction to retrieve.

  • kwargs – Any other kwargs that other providers might allow when fetching a receipt.

Returns:

The receipt of the transaction with the given hash.

Return type:

ReceiptAPI

get_transactions_by_block(block_id: Union[int, HexStr, HexBytes, Literal['earliest', 'latest', 'pending']]) Iterator[TransactionAPI]

Get the information about a set of transactions from a block.

Parameters:

block_id (BlockID) – The ID of the block.

Returns:

class: ~ape.api.transactions.TransactionAPI]

Return type:

Iterator[

get_virtual_machine_error(exception: Exception, **kwargs: Any) VirtualMachineError

Get a virtual machine error from an error returned from your RPC.

Parameters:

exception (Exception) – The error returned from your RPC client.

Returns:

An error representing what

went wrong in the call.

Return type:

VirtualMachineError

property is_connected: bool

True if currently connected to the provider. False otherwise.

property plugin_config: StarknetConfig

Returns network configurations

prepare_transaction(txn: TransactionAPI) TransactionAPI

Set default values on the transaction.

Raises:

TransactionError – When given negative required confirmations.

Parameters:

txn (TransactionAPI) – The transaction to prepare.

Returns:

TransactionAPI

send_call(**kwargs)

Execute a new transaction call immediately without creating a transaction on the blockchain.

Parameters:

txn (TransactionAPI) – The transaction to send as a call.

Returns:

The result of the transaction call.

Return type:

str

send_transaction(**kwargs)

Send a transaction to the network.

Parameters:

txn (TransactionAPI) – The transaction to send.

Returns:

ReceiptAPI

property starknet_client: GatewayClient

An HTTP client for Starknet.

update_settings(new_settings: dict)

Change a provider’s setting, such as configure a new port to run on. May require a reconnect.

Parameters:

new_settings (dict) – The new provider settings.

property uri: str

Network uri or local port