Common objects and functions
Abstract classes
Classes:
Web3 client reference implementation. |
|
Reference implementation of class defining smart contract method. |
|
Reference implementation of class defining smart contract. |
- class matic.abstracts.BaseWeb3Client(provider: Any)[source]
Bases:
abc.ABC
Web3 client reference implementation.
Methods:
Obtain a contract from deployment address and ABI dictionary.
Perform a reading (non-modifying) operation.
Perform a writing (modifying) operation.
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.
Get root hash for two blocks.
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.
- abstract get_contract(address: eth_typing.evm.HexAddress, abi: Any) matic.abstracts.BaseContract [source]
Obtain a contract from deployment address and ABI dictionary.
- abstract read(config: matic.json_types.ITransactionRequestConfig, return_transaction: bool = False) Any [source]
Perform a reading (non-modifying) operation.
- abstract write(config: matic.json_types.ITransactionRequestConfig, private_key: Optional[str] = None, return_transaction: bool = False) matic.json_types.ITransactionWriteResult [source]
Perform a writing (modifying) operation.
- abstract estimate_gas(config: matic.json_types.ITransactionRequestConfig) int [source]
Estimate gas amount for transaction.
- abstract get_transaction_count(address: eth_typing.evm.HexAddress, block_number: Any) int [source]
Get amount of transactions in specified block for given address.
- abstract get_transaction(transaction_hash: bytes) matic.json_types.ITransactionData [source]
Obtain transaction object by hash.
- abstract get_transaction_receipt(transaction_hash: bytes) matic.json_types.ITransactionReceipt [source]
Get receipt for transaction.
- abstract 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.
- abstract 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.
- abstract send_rpc_request(method: web3.types.RPCEndpoint, params: Iterable[Any]) web3.types.RPCResponse [source]
Perform arbitrary RPC request.
- abstract encode_parameters(params: Sequence[Any], types: Sequence[str]) bytes [source]
Encode ABI parameters according to schema.
- class matic.abstracts.BaseContractMethod(address: eth_typing.evm.HexAddress, method: Any)[source]
Bases:
abc.ABC
Reference implementation of class defining smart contract 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.
- abstract 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.
- abstract write(tx: matic.json_types.ITransactionRequestConfig, private_key: Optional[str] = None, return_transaction: bool = False) matic.json_types.ITransactionWriteResult [source]
Perform a write operation.
Transaction is signed (with given PK), affects the chain.
- abstract 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.abstracts.BaseContract(address: eth_typing.evm.HexAddress)[source]
Bases:
abc.ABC
Reference implementation of class defining smart contract.
Methods:
Obtain a method object by name and call arguments.
- abstract method(method_name: str, *args: Any) matic.abstracts.BaseContractMethod [source]
Obtain a method object by name and call arguments.
Constants
Data:
Max transaction amount. |
|
MATIC token address on polygon network. |
Classes:
Signatures of different transfer kinds for POS bridge. |
|
Signatures of different withdrawal kinds for plasma bridge. |
- matic.constants.MAX_AMOUNT: Final = 115792089237316195423570985008687907853269984665640564039457584007913129639935
Max transaction amount.
- matic.constants.MATIC_TOKEN_ADDRESS_ON_POLYGON: Final = '0x0000000000000000000000000000000000001010'
MATIC token address on polygon network.
- final class matic.constants.POSLogEventSignature[source]
Bases:
object
Signatures of different transfer kinds for POS bridge.
Attributes:
Transfer of ERC-20 token.
Transfer of ERC-721 token.
Transfer of ERC-1155 token.
Batch transfer of ERC-721 token.
Batch transfer of ERC-1155 token.
Transfer of ERC-721 token with metadata.
StateSynced event signature.
- ERC_20_TRANSFER: Final = b'\xdd\xf2R\xad\x1b\xe2\xc8\x9bi\xc2\xb0h\xfc7\x8d\xaa\x95+\xa7\xf1c\xc4\xa1\x16(\xf5ZM\xf5#\xb3\xef'
Transfer of ERC-20 token.
- ERC_721_TRANSFER: Final = b'\xdd\xf2R\xad\x1b\xe2\xc8\x9bi\xc2\xb0h\xfc7\x8d\xaa\x95+\xa7\xf1c\xc4\xa1\x16(\xf5ZM\xf5#\xb3\xef'
Transfer of ERC-721 token.
- ERC_1155_TRANSFER: Final = b'\xc3\xd5\x81h\xc5\xaes\x97s\x1d\x06=[\xbf=exTBsC\xf4\xc0\x83$\x0fz\xac\xaa-\x0fb'
Transfer of ERC-1155 token.
- ERC_721_BATCH_TRANSFER: Final = b'\xf8q\x89k\x17\xe9\xcbzd\x94\x1cb\xc1\x88\xa4\xf5\xc6!\xb8h\x00\xe3\xd1TR\xec\xe0\x1c\xe5`s\xdf'
Batch transfer of ERC-721 token.
- ERC_1155_BATCH_TRANSFER: Final = b'J9\xdc\x06\xd4\xc0\xdb\xc6Kp\xaf\x90\xfdi\x8a#:Q\x8a\xa5\xd0~Y]\x98;\x8c\x05&\xc8\xf7\xfb'
Batch transfer of ERC-1155 token.
- ERC_721_TRANSFER_WITH_METADATA: Final = b'\xf9I\x15\xc6\xd1\xfdR\x1c\xee\x855\x929"t\x80\xc7\xe8wm|\xaf\x1f\xc3\xba\xca\xd5\xc2i\xb6j\x14'
Transfer of ERC-721 token with metadata.
- STATE_SYNCED_EVENT: Final = b'\x10?\xed\x9d\xb6^\xac\x19\xc4\xd8p\xf4\x9a\xb7R\x0f\xe0;\x99\xf1\x83\x8eY\x96\xca\xf4~\x9eC0\x83\x92'
StateSynced event signature.
- final class matic.constants.PlasmaLogEventSignature[source]
Bases:
object
Signatures of different withdrawal kinds for plasma bridge.
Attributes:
Withdrawal of ERC-20 token event signature.
Withdrawal of ERC-721 token event signature.
- ERC_20_WITHDRAW_EVENT_SIG = b'\xeb\xff&\x02\xb3\xf4h%\x9e\x1e\x99\xf6\x13\xfe\xd6i\x1f:e&\xef\xfen\xf3\xe7h\xbaz\xe7\xa3lO'
Withdrawal of ERC-20 token event signature.
- ERC_721_WITHDRAW_EVENT_SIG = b'\x9b\x1b\xfa\x7f\xa9\xeeB\n\x16\xe1$\xf7\x94\xc3Z\xc9\xf9\x04r\xac\xc9\x91@\xeb/dG\xc7\x14\xca\xd8\xeb'
Withdrawal of ERC-721 token event signature.
Exceptions
Exceptions:
Base exception class for this library. |
|
The action is allowed only on root token. |
|
The action is allowed only on child token. |
|
Proof api is not set. |
|
Burn transaction has not been checkpointed as yet. |
|
The chain doesn't support EIP-1559. |
|
Please provide spender address. |
- exception matic.exceptions.MaticException[source]
Bases:
Exception
Base exception class for this library.
- exception matic.exceptions.AllowedOnRootException[source]
Bases:
matic.exceptions.MaticException
The action is allowed only on root token.
- exception matic.exceptions.AllowedOnChildException[source]
Bases:
matic.exceptions.MaticException
The action is allowed only on child token.
- exception matic.exceptions.ProofAPINotSetException[source]
Bases:
matic.exceptions.MaticException
Proof api is not set.
- exception matic.exceptions.BurnTxNotCheckPointedException[source]
Bases:
matic.exceptions.MaticException
Burn transaction has not been checkpointed as yet.
- exception matic.exceptions.EIP1559NotSupportedException[source]
Bases:
matic.exceptions.MaticException
The chain doesn’t support EIP-1559.
- exception matic.exceptions.NullSpenderAddressException[source]
Bases:
matic.exceptions.MaticException
Please provide spender address.
TypedDict
s and dataclass
es
Classes:
Configuration dictionary with (not required) key "from" (type str) and any other keys. |
|
Transaction config - an actual configuration used to interact with chain. |
|
Transaction config: this can be passed as option to almost all methods. |
|
Transaction config for approve/allowance methods. |
|
Transaction config for |
|
Transaction parameters that can be obtained from blockchain. |
|
Configuration for parent/child of |
|
Configuration for |
|
Configuration for POS client. |
|
Configuration for plasma bridge client. |
|
Base block parameters. |
|
Block with raw transactions (bytes). |
|
Block with decoded transactions. |
|
Return type of |
|
Return type of |
|
Root block info (used in proofs). |
|
Interface for result of |
|
Log data. |
|
Event logs (can occur in transaction receipts). |
|
Transaction receipt format used internally. |
|
Block info obtained from API to construct a proof. |
|
Receipt proof. |
- class matic.json_types.ConfigWithFrom
-
Configuration dictionary with (not required) key “from” (type str) and any other keys.
- from: typing_extensions.NotRequired[eth_typing.evm.HexAddress]
- class matic.json_types.ITransactionRequestConfig[source]
Bases:
matic.json_types.ConfigWithFrom
Transaction config - an actual configuration used to interact with chain.
- to: eth_typing.evm.HexAddress
Transaction recipient.
- type: Optional[eth_typing.encoding.HexStr]
Transaction type.
- from: typing_extensions.NotRequired[eth_typing.evm.HexAddress]
- class matic.json_types.ITransactionOption[source]
Bases:
matic.json_types.ITransactionRequestConfig
Transaction config: this can be passed as option to almost all methods.
- return_transaction: typing_extensions.NotRequired[bool]
Skip writing step and return prepared transaction.
- from: typing_extensions.NotRequired[eth_typing.evm.HexAddress]
- to: eth_typing.evm.HexAddress
Transaction recipient.
- type: Optional[eth_typing.encoding.HexStr]
Transaction type.
- class matic.json_types.IAllowanceTransactionOption[source]
Bases:
matic.json_types.ITransactionOption
,matic.json_types.ITransactionRequestConfig
Transaction config for approve/allowance methods.
- spender_address: typing_extensions.NotRequired[eth_typing.evm.HexAddress]
Address of spender.
spender - third-party user or a smart contract which can transfer your token on your behalf.
- from: typing_extensions.NotRequired[eth_typing.evm.HexAddress]
- to: eth_typing.evm.HexAddress
Transaction recipient.
- type: Optional[eth_typing.encoding.HexStr]
Transaction type.
- class matic.json_types.IExitTransactionOption[source]
Bases:
matic.json_types.ITransactionOption
,matic.json_types.ITransactionRequestConfig
Transaction config for
withdraw_exit_*
operations.- burn_event_signature: typing_extensions.NotRequired[bytes]
Signature in case you need to adjust default used.
- from: typing_extensions.NotRequired[eth_typing.evm.HexAddress]
- to: eth_typing.evm.HexAddress
Transaction recipient.
- type: Optional[eth_typing.encoding.HexStr]
Transaction type.
- class matic.json_types.ITransactionData(transaction_hash: bytes, nonce: int, block_hash: bytes | None, block_number: int | None, transaction_index: int | None, from_: eth_typing.evm.HexAddress, to: Optional[eth_typing.evm.HexAddress], value: int, gas_price: int, gas: int, input: eth_typing.encoding.HexStr)[source]
Bases:
object
Transaction parameters that can be obtained from blockchain.
- from_: eth_typing.evm.HexAddress
Sender.
- to: Optional[eth_typing.evm.HexAddress]
Recipient.
- input: eth_typing.encoding.HexStr
Input data.
- class matic.json_types.NeighbourClientConfig[source]
-
Configuration for parent/child of
Web3SideChainClient
.- provider: Any
Web3 provider to use.
- default_config: matic.json_types.ConfigWithFrom
Any required configuration (must include “from” key).
- class matic.json_types.IBaseClientConfig[source]
-
Configuration for
Web3SideChainClient
.- parent: typing_extensions.NotRequired[matic.json_types.NeighbourClientConfig]
Parent chain configuration.
- child: typing_extensions.NotRequired[matic.json_types.NeighbourClientConfig]
Child chain configuration.
- class matic.json_types.IPOSClientConfig[source]
Bases:
matic.json_types.IBaseClientConfig
Configuration for POS client.
- root_chain_manager: typing_extensions.NotRequired[eth_typing.evm.HexAddress]
Root chain manager address.
- root_chain: typing_extensions.NotRequired[eth_typing.evm.HexAddress]
Root chain address.
- erc_1155_mintable_predicate: typing_extensions.NotRequired[eth_typing.evm.HexAddress]
Mintable predicate for ERC-1155 token address.
- parent: typing_extensions.NotRequired[matic.json_types.NeighbourClientConfig]
Parent chain configuration.
- child: typing_extensions.NotRequired[matic.json_types.NeighbourClientConfig]
Child chain configuration.
- class matic.json_types.IPlasmaClientConfig[source]
Bases:
matic.json_types.IBaseClientConfig
Configuration for plasma bridge client.
- deposit_manager: typing_extensions.NotRequired[Optional[eth_typing.evm.HexAddress]]
Deposit manager address.
- withdraw_manager: typing_extensions.NotRequired[Optional[eth_typing.evm.HexAddress]]
Withdraw manager address.
- registry: typing_extensions.NotRequired[Optional[eth_typing.evm.HexAddress]]
Registry address.
- root_chain: typing_extensions.NotRequired[Optional[eth_typing.evm.HexAddress]]
Root chain address.
- erc_20_predicate: typing_extensions.NotRequired[Optional[eth_typing.evm.HexAddress]]
Predicate address for ERC-20 tokens.
- erc_721_predicate: typing_extensions.NotRequired[Optional[eth_typing.evm.HexAddress]]
Predicate address for ERC-721 tokens.
- parent: typing_extensions.NotRequired[matic.json_types.NeighbourClientConfig]
Parent chain configuration.
- child: typing_extensions.NotRequired[matic.json_types.NeighbourClientConfig]
Child chain configuration.
- class matic.json_types.IBaseBlock(size: int, difficulty: int, total_difficulty: int, number: int, hash: bytes, parent_hash: bytes, nonce: int, gas_limit: int, gas_used: int, timestamp: int, logs_bloom: bytes, transactions_root: bytes, state_root: bytes, receipts_root: bytes, miner: bytes, extra_data: bytes, uncles: Sequence[bytes], sha3_uncles: bytes, base_fee_per_gas: Optional[int] = None)[source]
Bases:
object
Base block parameters.
- class matic.json_types.IBlock(size: int, difficulty: int, total_difficulty: int, number: int, hash: bytes, parent_hash: bytes, nonce: int, gas_limit: int, gas_used: int, timestamp: int, logs_bloom: bytes, transactions_root: bytes, state_root: bytes, receipts_root: bytes, miner: bytes, extra_data: bytes, uncles: typing.Sequence[bytes], sha3_uncles: bytes, base_fee_per_gas: typing.Optional[int] = None, transactions: typing.Sequence[bytes] = <factory>)[source]
Bases:
matic.json_types.IBaseBlock
Block with raw transactions (bytes).
- class matic.json_types.IBlockWithTransaction(size: int, difficulty: int, total_difficulty: int, number: int, hash: bytes, parent_hash: bytes, nonce: int, gas_limit: int, gas_used: int, timestamp: int, logs_bloom: bytes, transactions_root: bytes, state_root: bytes, receipts_root: bytes, miner: bytes, extra_data: bytes, uncles: typing.Sequence[bytes], sha3_uncles: bytes, base_fee_per_gas: typing.Optional[int] = None, transactions: typing.Sequence[matic.json_types.ITransactionData] = <factory>)[source]
Bases:
matic.json_types.IBaseBlock
Block with decoded transactions.
- transactions: Sequence[matic.json_types.ITransactionData]
Decoded (dict-formatted) transactions data.
- class matic.json_types.IPOSContracts(root_chain_manager: RootChainManager, exit_util: ExitUtil[IPOSClientConfig])[source]
Bases:
object
Return type of
get_pos_contracts
parameter ofmatic.pos.pos_token.POSToken
.- root_chain_manager: RootChainManager
Root chain manager.
- exit_util: ExitUtil[IPOSClientConfig]
Helper class instance for building exit data.
- class matic.json_types.IPlasmaContracts(deposit_manager: DepositManager, registry: RegistryContract, exit_util: ExitUtil[IPlasmaClientConfig], withdraw_manager: WithdrawManager)[source]
Bases:
object
Return type of
get_helper_contracts
parameter ofmatic.plasma.plasma_token.PlasmaToken
.- deposit_manager: DepositManager
Deposit manager instance.
- registry: RegistryContract
Registry contract instance.
- exit_util: ExitUtil[IPlasmaClientConfig]
Helper class instance for building exit data.
- withdraw_manager: WithdrawManager
Withdraw manager instance.
- class matic.json_types.IRootBlockInfo(start: int, end: int, header_block_number: int)[source]
Bases:
object
Root block info (used in proofs).
- class matic.json_types.ITransactionWriteResult[source]
Bases:
abc.ABC
Interface for result of
process_write
method.- abstract property transaction_config: matic.json_types.ITransactionRequestConfig
Get transaction parameters.
- property receipt: matic.json_types.ITransactionReceipt
Property for convenient access to receipt.
- abstract get_receipt(timeout: int = Ellipsis) matic.json_types.ITransactionReceipt [source]
Get receipt (wait max
timeout
seconds).
- class matic.json_types.ILog(address: eth_typing.evm.HexAddress, data: str, topics: Sequence[bytes], log_index: int, transaction_hash: bytes, transaction_index: int, block_hash: bytes, block_number: int, removed: bool)[source]
Bases:
object
Log data.
- address: eth_typing.evm.HexAddress
Log address.
- class matic.json_types.IEventLog(event: str, address: bytes, return_values: Any, log_index: int, transaction_hash: bytes, transaction_index: int, block_hash: bytes, block_number: int, raw: Optional[matic.json_types._RawLogData] = None)[source]
Bases:
object
Event logs (can occur in transaction receipts).
- return_values: Any
Event return values.
- class matic.json_types.ITransactionReceipt(transaction_hash: bytes, transaction_index: int, block_hash: bytes, block_number: int, from_: eth_typing.encoding.HexStr, to: eth_typing.encoding.HexStr, contract_address: typing.Optional[eth_typing.evm.ChecksumAddress], cumulative_gas_used: int, gas_used: int, logs_bloom: bytes, root: typing.Optional[eth_typing.encoding.HexStr], type: eth_typing.encoding.HexStr, status: typing.Optional[bool] = None, logs: typing.Sequence[matic.json_types.ILog] = <factory>, events: dict[str, matic.json_types.IEventLog] = <factory>)[source]
Bases:
object
Transaction receipt format used internally.
- from_: eth_typing.encoding.HexStr
Sender address.
- to: eth_typing.encoding.HexStr
Recipient address.
- contract_address: Optional[eth_typing.evm.ChecksumAddress]
Address of the contract transaction interacts with.
- root: Optional[eth_typing.encoding.HexStr]
Transaction root (hex string).
- type: eth_typing.encoding.HexStr
0x).
- Type
Transaction type (hex string
- logs: Sequence[matic.json_types.ILog]
Logs data.
- events: dict[str, matic.json_types.IEventLog]
Events data.
- class matic.json_types.CheckpointedBlock(start: int, end: int, header_block_number: int, block_number: int, proposer: eth_typing.encoding.HexStr, root: eth_typing.encoding.HexStr, created_at: int, message: str)[source]
Bases:
matic.json_types.IRootBlockInfo
Block info obtained from API to construct a proof.
- proposer: eth_typing.encoding.HexStr
Block proposer address.
- root: eth_typing.encoding.HexStr
Block root.
Services
Data:
Default url of ABI store. |
|
Default url of proof API. |
Functions:
Get ABI dict for contract. |
|
Fetch dictionary with addresses of contracts deployed on network. |
|
Get block information by number. |
|
Get proof from API. |
- matic.services.DEFAULT_ABI_STORE_URL: str = 'https://static.matic.network/network'
Default url of ABI store. Can be altered if needed.
- matic.services.DEFAULT_PROOF_API_URL: str = ''
Default url of proof API. Must be set to use fast proofs.
- matic.services.get_abi(network: str, version: str, bridge_type: str, contract_name: str, base_url: Optional[str] = None) dict[str, Any] [source]
Get ABI dict for contract.
- matic.services.get_address(network: str, version: str, base_url: Optional[str] = None) dict[str, Any] [source]
Fetch dictionary with addresses of contracts deployed on network.