SignerOrProvider¶
- class arbitrum_py.data_entities.signer_or_provider.SignerOrProvider(account=None, provider=None)[source]¶
Bases:
objectA combined signer and provider for Ethereum transactions.
This class provides a unified interface for both signing transactions and interacting with an Ethereum network. It combines the functionality of eth_account’s LocalAccount (signer) and Web3 (provider).
In the TypeScript SDK, this was represented as a union type (Signer | Provider). In Python, we implement it as a class that can optionally contain both components.
- Variables:
account (Optional[LocalAccount]) – The account that can sign transactions
provider (Optional[Web3]) – The Web3 instance for sending transactions
Example
>>> from eth_account import Account >>> from web3 import Web3 >>> >>> # Create with both signer and provider >>> account = Account.create() >>> w3 = Web3(Web3.HTTPProvider('http://localhost:8545')) >>> signer_provider = SignerOrProvider(account=account, provider=w3) >>> >>> # Get current balance >>> balance = signer_provider.get_balance() >>> >>> # Sign and send a transaction >>> tx = {'to': '0x...', 'value': 1000000000000000000} >>> signed = signer_provider.sign_transaction(tx) >>> tx_hash = signer_provider.provider.eth.send_raw_transaction(signed)
- __init__(account=None, provider=None)[source]¶
Initialize a new SignerOrProvider instance.
- Parameters:
account (
Optional[LocalAccount]) – A LocalAccount that can sign messages and transactionsprovider (
Optional[Web3]) – A Web3 instance connected to an Ethereum network
- get_address()[source]¶
Get the address of the signer account.
- Return type:
NewType()(HexStr,str)- Returns:
The checksummed address of the signer account
- Raises:
AttributeError – If no account is set
- property address: HexStr¶
The checksummed address of the signer account.
- Returns:
The account’s address
- Raises:
AttributeError – If no account is set
- sign_message(message)[source]¶
Sign a message using the signer account.
- Parameters:
message (
bytes) – The message to sign- Return type:
bytes- Returns:
The signature bytes
- Raises:
AttributeError – If no account is set
- sign_transaction(transaction)[source]¶
Sign a transaction using the signer account.
- Parameters:
transaction (
TxParams) – The transaction parameters to sign- Return type:
bytes- Returns:
The signed transaction bytes ready for sending
- Raises:
AttributeError – If no account is set
- get_chain_id()[source]¶
Get the chain ID of the connected network.
- Return type:
int- Returns:
The chain ID
- Raises:
AttributeError – If no provider is set
- property chain_id: int¶
The chain ID of the connected network.
- Returns:
The chain ID
- Raises:
AttributeError – If no provider is set
- get_balance(block_identifier=None)[source]¶
Get the balance of the signer account.
- Parameters:
block_identifier (
Union[NewType()(BlockNumber,int),str,None]) – The block number or block tag to get balance at. Defaults to ‘latest’- Return type:
NewType()(Wei,int)- Returns:
The balance in wei
- Raises:
AttributeError – If no provider is set or no account is set
- property balance: Wei¶
The current balance of the signer account.
- Returns:
The balance in wei
- Raises:
AttributeError – If no provider is set or no account is set
- get_nonce(block_identifier=None)[source]¶
Get the nonce of the signer account. :type block_identifier:
Union[NewType()(BlockNumber,int),str,None] :param block_identifier: The block identifier to get the nonce at a specific block. :rtype:int:return: The nonce of the signer account.
- property nonce: int¶
Get the nonce of the signer account. :return: The nonce of the signer account.
- get_gas_price()[source]¶
Get the gas price of the provider. :rtype:
int:return: The gas price of the provider.
- estimate_gas(transaction, block_identifier=None)[source]¶
Estimate the gas for a transaction. :type transaction:
TxParams:param transaction: The transaction to estimate the gas for. :rtype:int:return: The estimated gas for the transaction.
- get_block_number()[source]¶
Get the block number of the provider. :rtype:
int:return: The block number of the provider.
- get_block(block_identifier=None)[source]¶
Get the block information. :type block_identifier:
Union[NewType()(BlockNumber,int),str,None] :param block_identifier: The block identifier to get the block information. :rtype:BlockData:return: The block information.
- get_transaction(transaction_hash)[source]¶
Get the transaction information. :type transaction_hash:
NewType()(Hash32,bytes) :param transaction_hash: The transaction hash to get the transaction information. :rtype:TxData:return: The transaction information.
- get_transaction_receipt(transaction_hash)[source]¶
Get the transaction receipt. :type transaction_hash:
NewType()(Hash32,bytes) :param transaction_hash: The transaction hash to get the transaction receipt. :rtype:TxReceipt:return: The transaction receipt.
- send_transaction(transaction)[source]¶
Send a transaction. :type transaction:
TxParams:param transaction: The transaction to send. :rtype:NewType()(Hash32,bytes) :return: The transaction hash.
- call(transaction, block_identifier=None)[source]¶
Call a transaction. :type transaction:
TxParams:param transaction: The transaction to call. :rtype:bytes:return: The result of the call.
- class arbitrum_py.data_entities.signer_or_provider.SignerProviderUtils[source]¶
Bases:
objectUtility functions for handling signer and provider objects.
This class provides static methods for working with SignerOrProvider instances and their components. It helps determine what capabilities are available and ensures proper provider/signer access.
The methods in this class mirror the functionality of the TypeScript SDK’s SignerProviderUtils, but adapted for Python’s type system and web3.py conventions.
- static is_signer(signer_or_provider)[source]¶
Check if an object is a signer.
In TypeScript, signers are detected by checking for the signMessage method. In Python, we check for LocalAccount/Account or SignerOrProvider with an account.
- Parameters:
signer_or_provider (
Union[SignerOrProvider,LocalAccount,Account,Web3]) – Object to check - could be a Web3 provider, a local signer, or a SignerOrProvider instance- Return type:
bool- Returns:
True if the object can sign transactions, False otherwise
Example
>>> account = Account.create() >>> SignerProviderUtils.is_signer(account) # True >>> w3 = Web3(Web3.HTTPProvider('...')) >>> SignerProviderUtils.is_signer(w3) # False
- static get_signer(signer_or_provider)[source]¶
Get the signer from a signer/provider object if available.
- Parameters:
signer_or_provider (
Union[SignerOrProvider,LocalAccount,Account,Web3]) – Object that might contain a signer- Return type:
Optional[LocalAccount]- Returns:
The LocalAccount signer if available, None otherwise
- static get_signer_or_throw(signer_or_provider)[source]¶
Get the signer from an object or raise an error.
- Parameters:
signer_or_provider (
Union[SignerOrProvider,LocalAccount,Account,Web3]) – Object that should contain a signer- Return type:
LocalAccount- Returns:
The LocalAccount signer
- Raises:
MissingProviderArbSdkError – If no signer is found
- static get_provider(signer_or_provider)[source]¶
Get the provider from a signer/provider object if available.
- Parameters:
signer_or_provider (
Union[SignerOrProvider,LocalAccount,Account,Web3]) – Object that might contain a provider- Return type:
Optional[Web3]- Returns:
The Web3 provider if available, None otherwise
- static get_provider_or_throw(signer_or_provider)[source]¶
Get the provider from an object or raise an error.
- Parameters:
signer_or_provider (
Union[SignerOrProvider,LocalAccount,Account,Web3]) – Object that should contain a provider- Return type:
Web3- Returns:
The Web3 provider
- Raises:
MissingProviderArbSdkError – If no provider is found
- static signer_has_provider(signer)[source]¶
Check if a signer object also has an associated provider.
- Parameters:
signer (
Union[LocalAccount,SignerOrProvider]) – A signer object to check- Return type:
bool- Returns:
True if the signer has an associated provider, False otherwise
- static check_network_matches(signer_or_provider, chain_id)[source]¶
Check if a provider is connected to the expected network.
Verifies that the provider’s network matches the expected chain ID. This is important for ensuring transactions are sent to the correct network.
- Parameters:
signer_or_provider (
Union[SignerOrProvider,LocalAccount,Account,Web3]) – Object containing a provider to checkchain_id (
int) – The expected chain ID
- Raises:
MissingProviderArbSdkError – If no provider is found
ArbSdkError – If the chain ID doesn’t match
- Return type:
None
Example
>>> w3 = Web3(Web3.HTTPProvider('http://localhost:8545')) >>> # Check we're on mainnet (chain_id=1) >>> SignerProviderUtils.check_network_matches(w3, 1)