Web3 client
Main implementation
This is an embedded implementation of maticjs_web3 library.
Classes:
Result of any writing call. |
|
Wrapper around web3 contract method ( |
|
A wrapper around web3 contract ( |
|
Implementation of web3 client. |
- class matic.web3_client.TransactionWriteResult(tx_hash: bytes | None, tx_params: matic.json_types.ITransactionRequestConfig, client: matic.web3_client.Web3Client)[source]
Bases:
matic.json_types.ITransactionWriteResult
Result of any writing call.
Methods:
Get transaction receipt.
Attributes:
Hash of performed transaction.
Hash of performed transaction.
- get_receipt(timeout: int = 120) matic.json_types.ITransactionReceipt [source]
Get transaction receipt.
- Parameters
timeout – max seconds to wait.
- Raises
AttributeError – if called on transaction that was not performed.
- property transaction_hash: bytes
Hash of performed transaction.
- Raises
AttributeError – if called on transaction that was not performed.
- property transaction_config: matic.json_types.ITransactionRequestConfig
Hash of performed transaction.
- class matic.web3_client.EthMethod(address: eth_typing.evm.HexAddress, method: web3.method.Method[Any], client: matic.web3_client.Web3Client)[source]
Bases:
matic.abstracts.BaseContractMethod
Wrapper around web3 contract method (
web3.method.Method
).Methods:
Perform a read operation.
Perform a write operation.
Estimate gas for given transaction.
Encode args according to method ABI and prepend the selector.
- read(tx: Optional[matic.json_types.ITransactionRequestConfig] = None, return_transaction: bool = False) Any [source]
Perform a read operation.
This does not sign a transaction and does not affect the chain.
- write(tx: matic.json_types.ITransactionRequestConfig, private_key: Optional[str] = None, return_transaction: bool = False) matic.web3_client.TransactionWriteResult [source]
Perform a write operation.
Transaction is signed (with given PK), affects the chain.
- estimate_gas(tx: matic.json_types.ITransactionRequestConfig) int [source]
Estimate gas for given transaction.
Warning
This method may fail if your transaction is invalid or cannot be executed.
- class matic.web3_client.Web3Contract(address: eth_typing.evm.HexAddress, contract: web3.contract.Contract, client: matic.web3_client.Web3Client)[source]
Bases:
matic.abstracts.BaseContract
A wrapper around web3 contract (
web3.contract.Contract
).Methods:
Obtain a method object by name and call arguments.
- method(method_name: str, *args: Any) matic.web3_client.EthMethod [source]
Obtain a method object by name and call arguments.
- class matic.web3_client.Web3Client(provider: web3.providers.base.BaseProvider)[source]
Bases:
matic.abstracts.BaseWeb3Client
Implementation of web3 client.
Methods:
Perform a reading (non-modifying) operation.
Perform a writing (modifying) operation.
Obtain a contract from deployment address and ABI dictionary.
Estimate gas amount for transaction.
Get amount of transactions in specified block for given address.
Obtain transaction object by hash.
Get receipt for transaction.
Get block (with raw transaction data) by hash or number.
Get block (with decoded transaction data) by hash or number.
Perform arbitrary RPC request.
Encode ABI parameters according to schema.
Decode binary data to ABI parameters according to schema.
Calculate solidity keccak hash of given values (encoded as types).
Attributes:
Current gas price.
Current chain id.
- read(config: matic.json_types.ITransactionRequestConfig, return_transaction: bool = False) Any [source]
Perform a reading (non-modifying) operation.
- write(config: matic.json_types.ITransactionRequestConfig, private_key: Optional[str] = None, return_transaction: bool = False) matic.web3_client.TransactionWriteResult [source]
Perform a writing (modifying) operation.
- get_contract(address: eth_typing.evm.HexAddress, abi: dict[str, Any]) matic.web3_client.Web3Contract [source]
Obtain a contract from deployment address and ABI dictionary.
- estimate_gas(transaction: matic.json_types.ITransactionRequestConfig) int [source]
Estimate gas amount for transaction.
- get_transaction_count(address: str, block_number: int) int [source]
Get amount of transactions in specified block for given address.
- get_transaction(transaction_hash: bytes) matic.json_types.ITransactionData [source]
Obtain transaction object by hash.
- get_transaction_receipt(transaction_hash: bytes, timeout: int = 120) matic.json_types.ITransactionReceipt [source]
Get receipt for transaction.
- get_block(block_hash_or_block_number: Union[Literal['latest', 'earliest', 'pending'], eth_typing.evm.BlockNumber, eth_typing.evm.Hash32, eth_typing.encoding.HexStr, hexbytes.main.HexBytes, int]) matic.json_types.IBlock [source]
Get block (with raw transaction data) by hash or number.
- get_block_with_transaction(block_hash_or_block_number: Union[Literal['latest', 'earliest', 'pending'], eth_typing.evm.BlockNumber, eth_typing.evm.Hash32, eth_typing.encoding.HexStr, hexbytes.main.HexBytes, int]) matic.json_types.IBlockWithTransaction [source]
Get block (with decoded transaction data) by hash or number.
- send_rpc_request(method: web3.types.RPCEndpoint, params: Iterable[Any]) web3.types.RPCResponse [source]
Perform arbitrary RPC request.
- encode_parameters(params: Sequence[Any], types: Sequence[str]) bytes [source]
Encode ABI parameters according to schema.
Web3 <–> matic data conversion
Conversion utils: web3 structures to matic.
Functions:
Transaction request: matic to web3. |
|
Transaction request: web3 to matic. |
|
Log: web3 to matic. |
|
Transaction receipt: web3 to matic. |
|
Transaction: web3 to matic. |
- matic.web3_client.utils.matic_tx_request_config_to_web3(config: Optional[matic.json_types.ITransactionRequestConfig] = None) web3.types.TxParams [source]
Transaction request: matic to web3.
- matic.web3_client.utils.web3_tx_request_config_to_matic(data: web3.types.TxParams) matic.json_types.ITransactionRequestConfig [source]
Transaction request: web3 to matic.
- matic.web3_client.utils.web3_log_to_matic_log(log: web3.types.LogReceipt) matic.json_types.ILog [source]
Log: web3 to matic.
- matic.web3_client.utils.web3_receipt_to_matic_receipt(receipt: web3.types.TxReceipt) matic.json_types.ITransactionReceipt [source]
Transaction receipt: web3 to matic.
- matic.web3_client.utils.web3_tx_to_matic_tx(tx: web3.types.TxData) matic.json_types.ITransactionData [source]
Transaction: web3 to matic.