POS bridge

Read Getting started for more info.

Note

Just in case you wanna do it: you can adjust used client implementations.

from matic import utils
from myimpl import MyOtherWeb3ClientClass

utils.Web3Client = MyOtherWeb3ClientClass

This client must conform with existing BaseWeb3Client (and use implementations of other abstracts from that file).

Note

You can also adjust ABI url used by this library. You can do it in any of two ways:

  • Set environmental variable (export MATIC_ABI_STORE=... or via .env file, if you load it);

  • Set value in python code directly:

    from matic import services
    services.DEFAULT_ABI_STORE_URL = '...'
    # See .env.example for one of possible URLs
    

Warning

In order to use methods of withdraw_exit_faster family, you need to set default proof API URI. You can do it in any of two ways:

  • Set environmental variable (export MATIC_PROOF_API=... or via .env file, if you load it);

  • Set value in python code directly:

    from matic import services
    services.DEFAULT_PROOF_API_URL = '...'
    # See .env.example for one of possible URLs
    

Bridge client

Classes:

POSClient

POS bridge client.

ERC20

Arbitrary ERC-20-compliant token.

ERC721

Arbitrary ERC-721-compliant token.

ERC1155

Arbitrary ERC-1155-compliant token.

class matic.pos.POSClient(config: matic.json_types.IPOSClientConfig)[source]

Bases: matic.utils.bridge_client.BridgeClient[matic.json_types.IPOSClientConfig]

POS bridge client.

Used to manage instantiation of matic.pos.erc_20.ERC20, matic.pos.erc_721.ERC721 and matic.pos.erc_1155.ERC1155 classes and perform some common operations.

Attributes:

root_chain_manager

Root chain manager.

Methods:

erc_20

Instantiate ERC20 for token address.

erc_721

Instantiate ERC721 for token address.

erc_1155

Instantiate ERC1155 for token address.

deposit_ether

Deposit given amount of ether to polygon chain.

root_chain_manager: RootChainManager

Root chain manager.

exit_util: ExitUtil[_C]

Helper class for exit data building.

Should be set after instantiation to prevent cycles.

erc_20(token_address: eth_typing.evm.HexAddress, is_parent: bool = False) matic.pos.erc_20.ERC20[source]

Instantiate ERC20 for token address.

Parameters
  • token_address – address where token contract is deployed.

  • is_parent – Whether this belongs to parent or child chain.

erc_721(token_address: eth_typing.evm.HexAddress, is_parent: bool = False) matic.pos.erc_721.ERC721[source]

Instantiate ERC721 for token address.

Parameters
  • token_address – address where token contract is deployed.

  • is_parent – Whether this belongs to parent or child chain.

erc_1155(token_address: eth_typing.evm.HexAddress, is_parent: bool = False) matic.pos.erc_1155.ERC1155[source]

Instantiate ERC1155 for token address.

Parameters
  • token_address – address where token contract is deployed.

  • is_parent – Whether this belongs to parent or child chain.

deposit_ether(amount: int, user_address: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit given amount of ether to polygon chain.

client: Web3SideChainClient[_C]

Actual connecting client.

class matic.pos.ERC20(token_address: eth_typing.evm.HexAddress, is_parent: bool, client: matic.utils.web3_side_chain_client.Web3SideChainClient[matic.json_types.IPOSClientConfig], get_pos_contracts: Callable[[], matic.json_types.IPOSContracts])[source]

Bases: matic.pos.pos_token.POSToken

Arbitrary ERC-20-compliant token.

Attributes:

CONTRACT_NAME

Name of a contract.

BURN_EVENT_SIGNATURE

used for exit methods.

Methods:

get_balance

Get balance of a user for supplied token.

get_allowance

Get allowance of user.

approve

Approve specified amount to contract.

approve_max

Approve max possible amount of token to contract.

deposit

Deposit given amount of token for user.

withdraw_start

Initiate withdraw by burning provided amount.

transfer

Transfer specified amount to another user.

CONTRACT_NAME: str = 'ChildERC20'

Name of a contract.

BURN_EVENT_SIGNATURE: bytes = b'\xdd\xf2R\xad\x1b\xe2\xc8\x9bi\xc2\xb0h\xfc7\x8d\xaa\x95+\xa7\xf1c\xc4\xa1\x16(\xf5ZM\xf5#\xb3\xef'

used for exit methods.

Type

Burn event signature

get_balance(user_address: eth_typing.evm.HexAddress, option: Optional[matic.json_types.ITransactionOption] = None) int[source]

Get balance of a user for supplied token.

get_allowance(user_address: eth_typing.evm.HexAddress, option: Optional[matic.json_types.IAllowanceTransactionOption] = None)[source]

Get allowance of user.

approve(amount: int, private_key: Optional[str] = None, option: Optional[matic.json_types.IAllowanceTransactionOption] = None)[source]

Approve specified amount to contract.

approve_max(private_key: str, option: Optional[matic.json_types.IAllowanceTransactionOption] = None)[source]

Approve max possible amount of token to contract.

deposit(amount: int, user_address: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit given amount of token for user.

withdraw_start(amount: int, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Initiate withdraw by burning provided amount.

transfer(amount: int, to: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Transfer specified amount to another user.

class matic.pos.ERC721(token_address: eth_typing.evm.HexAddress, is_parent: bool, client: matic.utils.web3_side_chain_client.Web3SideChainClient[matic.json_types.IPOSClientConfig], get_pos_contracts: Callable[[], matic.json_types.IPOSContracts])[source]

Bases: matic.pos.pos_token.TokenWithApproveAll

Arbitrary ERC-721-compliant token.

Attributes:

CONTRACT_NAME

Name of a contract.

BURN_EVENT_SIGNATURE

used for exit methods.

Methods:

get_tokens_count

Get tokens count for the user.

get_token_id_at_index_for_user

Get token id on supplied index for user.

get_all_tokens

Get all tokens for user.

is_approved

Check if given token is approved for contract.

approve

Approve token with given id to contract (root chain).

deposit

Deposit given token from root chain to child.

deposit_many

Deposit given tokens from root chain to child.

withdraw_start

Begin withdrawal to root chain (on child chain).

withdraw_start_with_metadata

Begin withdrawal to root chain with writing of metadata (on child chain).

withdraw_start_many

Begin withdrawal of multiple tokens to root chain (on child chain).

withdraw_exit_on_index

Complete withdraw process for token on given index.

is_withdraw_exited_many

Check if batch withdrawal is already exited for given transaction.

is_withdraw_exited_on_index

Check if withdrawal is already exited for given transaction on index.

transfer

Transfer to another user.

CONTRACT_NAME: str = 'ChildERC721'

Name of a contract.

BURN_EVENT_SIGNATURE: bytes = b'\xdd\xf2R\xad\x1b\xe2\xc8\x9bi\xc2\xb0h\xfc7\x8d\xaa\x95+\xa7\xf1c\xc4\xa1\x16(\xf5ZM\xf5#\xb3\xef'

used for exit methods.

Type

Burn event signature

get_tokens_count(user_address: eth_typing.evm.HexAddress, options: Optional[matic.json_types.ITransactionOption] = None) int[source]

Get tokens count for the user.

get_token_id_at_index_for_user(index: int, user_address: eth_typing.evm.HexAddress, options: Optional[matic.json_types.ITransactionOption] = None) int[source]

Get token id on supplied index for user.

get_all_tokens(user_address: eth_typing.evm.HexAddress, limit: Optional[int] = None) list[int][source]

Get all tokens for user.

is_approved(token_id: int, option: Optional[matic.json_types.ITransactionOption] = None) bool[source]

Check if given token is approved for contract.

approve(token_id: int, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Approve token with given id to contract (root chain).

deposit(token_id: int, user_address: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit given token from root chain to child.

deposit_many(token_ids: Sequence[int], user_address: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit given tokens from root chain to child.

withdraw_start(token_id: int, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Begin withdrawal to root chain (on child chain).

withdraw_start_with_metadata(token_id: int, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Begin withdrawal to root chain with writing of metadata (on child chain).

withdraw_start_many(token_ids: Sequence[int], private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Begin withdrawal of multiple tokens to root chain (on child chain).

withdraw_exit_on_index(burn_transaction_hash: bytes, index: int, private_key: Optional[str] = None, option: Optional[matic.json_types.IExitTransactionOption] = None)[source]

Complete withdraw process for token on given index.

This function should be called after checkpoint has been submitted for the block containing burn tx.

This function uses API to fetch proof data.

is_withdraw_exited_many(tx_hash: bytes) bool[source]

Check if batch withdrawal is already exited for given transaction.

is_withdraw_exited_on_index(tx_hash: bytes, index: int) bool[source]

Check if withdrawal is already exited for given transaction on index.

transfer(token_id: int, from_: eth_typing.evm.HexAddress, to: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Transfer to another user.

class matic.pos.ERC1155(token_address: eth_typing.evm.HexAddress, is_parent: bool, client: matic.utils.web3_side_chain_client.Web3SideChainClient[matic.json_types.IPOSClientConfig], get_pos_contracts: Callable[[], matic.json_types.IPOSContracts])[source]

Bases: matic.pos.pos_token.TokenWithApproveAll

Arbitrary ERC-1155-compliant token.

Attributes:

CONTRACT_NAME

Name of a contract.

BURN_EVENT_SIGNATURE

used for exit methods.

mintable_predicate_address

Address of mintable predicate for this token.

Methods:

get_balance

Get balance of a user for supplied token.

approve_all_for_mintable

Approve all tokens for mintable token.

deposit

Deposit supplied amount of token for a user.

deposit_many

Deposit supplied amount of multiple token for user.

withdraw_start

Start withdraw process by burning the required amount for a token.

withdraw_start_many

Start the withdraw process by burning multiple tokens at a time.

withdraw_exit_many

Exit the multiple withdraw process.

withdraw_exit_faster_many

Exit the multiple withdraw process.

is_withdraw_exited_many

Check if batch exit has been completed for a transaction hash.

transfer

Transfer the required amount of a token to another user.

CONTRACT_NAME: str = 'ChildERC1155'

Name of a contract.

BURN_EVENT_SIGNATURE: bytes = b'\xc3\xd5\x81h\xc5\xaes\x97s\x1d\x06=[\xbf=exTBsC\xf4\xc0\x83$\x0fz\xac\xaa-\x0fb'

used for exit methods.

Type

Burn event signature

property mintable_predicate_address: Optional[eth_typing.evm.HexAddress]

Address of mintable predicate for this token.

get_balance(user_address: eth_typing.evm.HexAddress, token_id: int, option: Optional[matic.json_types.ITransactionOption] = None) int[source]

Get balance of a user for supplied token.

approve_all_for_mintable(private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Approve all tokens for mintable token.

deposit(amount: int, token_id: int, user_address: eth_typing.evm.HexAddress, data: Optional[bytes] = None, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit supplied amount of token for a user.

deposit_many(amounts: Iterable[int], token_ids: Iterable[int], user_address: eth_typing.evm.HexAddress, data: Optional[bytes] = None, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit supplied amount of multiple token for user.

withdraw_start(token_id: int, amount: int, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Start withdraw process by burning the required amount for a token.

withdraw_start_many(token_ids: Sequence[int], amounts: Sequence[int], private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Start the withdraw process by burning multiple tokens at a time.

withdraw_exit_many(burn_transaction_hash: bytes, private_key: Optional[str] = None, option: Optional[matic.json_types.IExitTransactionOption] = None)[source]

Exit the multiple withdraw process.

Exit the withdraw process for many burned transaction and get the burned amount on root chain.

This function fetches blocks and builds a proof manually.

withdraw_exit_faster_many(burn_transaction_hash: bytes, private_key: Optional[str] = None, option: Optional[matic.json_types.IExitTransactionOption] = None)[source]

Exit the multiple withdraw process.

Exit the withdraw process for many burned transaction and get the burned amount on root chain.

This function uses API to get proof faster.

is_withdraw_exited_many(tx_hash: bytes) bool[source]

Check if batch exit has been completed for a transaction hash.

transfer(from_: eth_typing.evm.HexAddress, to: eth_typing.evm.HexAddress, amount: int, token_id: int, data: bytes | None = b'', private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Transfer the required amount of a token to another user.

ERC 20

Classes:

ERC20

Arbitrary ERC-20-compliant token.

class matic.pos.erc_20.ERC20(token_address: eth_typing.evm.HexAddress, is_parent: bool, client: matic.utils.web3_side_chain_client.Web3SideChainClient[matic.json_types.IPOSClientConfig], get_pos_contracts: Callable[[], matic.json_types.IPOSContracts])[source]

Bases: matic.pos.pos_token.POSToken

Arbitrary ERC-20-compliant token.

Attributes:

CONTRACT_NAME

Name of a contract.

BURN_EVENT_SIGNATURE

used for exit methods.

Methods:

get_balance

Get balance of a user for supplied token.

get_allowance

Get allowance of user.

approve

Approve specified amount to contract.

approve_max

Approve max possible amount of token to contract.

deposit

Deposit given amount of token for user.

withdraw_start

Initiate withdraw by burning provided amount.

transfer

Transfer specified amount to another user.

CONTRACT_NAME: str = 'ChildERC20'

Name of a contract.

BURN_EVENT_SIGNATURE: bytes = b'\xdd\xf2R\xad\x1b\xe2\xc8\x9bi\xc2\xb0h\xfc7\x8d\xaa\x95+\xa7\xf1c\xc4\xa1\x16(\xf5ZM\xf5#\xb3\xef'

used for exit methods.

Type

Burn event signature

get_balance(user_address: eth_typing.evm.HexAddress, option: Optional[matic.json_types.ITransactionOption] = None) int[source]

Get balance of a user for supplied token.

get_allowance(user_address: eth_typing.evm.HexAddress, option: Optional[matic.json_types.IAllowanceTransactionOption] = None)[source]

Get allowance of user.

approve(amount: int, private_key: Optional[str] = None, option: Optional[matic.json_types.IAllowanceTransactionOption] = None)[source]

Approve specified amount to contract.

approve_max(private_key: str, option: Optional[matic.json_types.IAllowanceTransactionOption] = None)[source]

Approve max possible amount of token to contract.

deposit(amount: int, user_address: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit given amount of token for user.

withdraw_start(amount: int, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Initiate withdraw by burning provided amount.

transfer(amount: int, to: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Transfer specified amount to another user.

ERC 721

Classes:

ERC721

Arbitrary ERC-721-compliant token.

class matic.pos.erc_721.ERC721(token_address: eth_typing.evm.HexAddress, is_parent: bool, client: matic.utils.web3_side_chain_client.Web3SideChainClient[matic.json_types.IPOSClientConfig], get_pos_contracts: Callable[[], matic.json_types.IPOSContracts])[source]

Bases: matic.pos.pos_token.TokenWithApproveAll

Arbitrary ERC-721-compliant token.

Attributes:

CONTRACT_NAME

Name of a contract.

BURN_EVENT_SIGNATURE

used for exit methods.

Methods:

get_tokens_count

Get tokens count for the user.

get_token_id_at_index_for_user

Get token id on supplied index for user.

get_all_tokens

Get all tokens for user.

is_approved

Check if given token is approved for contract.

approve

Approve token with given id to contract (root chain).

deposit

Deposit given token from root chain to child.

deposit_many

Deposit given tokens from root chain to child.

withdraw_start

Begin withdrawal to root chain (on child chain).

withdraw_start_with_metadata

Begin withdrawal to root chain with writing of metadata (on child chain).

withdraw_start_many

Begin withdrawal of multiple tokens to root chain (on child chain).

withdraw_exit_on_index

Complete withdraw process for token on given index.

is_withdraw_exited_many

Check if batch withdrawal is already exited for given transaction.

is_withdraw_exited_on_index

Check if withdrawal is already exited for given transaction on index.

transfer

Transfer to another user.

CONTRACT_NAME: str = 'ChildERC721'

Name of a contract.

BURN_EVENT_SIGNATURE: bytes = b'\xdd\xf2R\xad\x1b\xe2\xc8\x9bi\xc2\xb0h\xfc7\x8d\xaa\x95+\xa7\xf1c\xc4\xa1\x16(\xf5ZM\xf5#\xb3\xef'

used for exit methods.

Type

Burn event signature

get_tokens_count(user_address: eth_typing.evm.HexAddress, options: Optional[matic.json_types.ITransactionOption] = None) int[source]

Get tokens count for the user.

get_token_id_at_index_for_user(index: int, user_address: eth_typing.evm.HexAddress, options: Optional[matic.json_types.ITransactionOption] = None) int[source]

Get token id on supplied index for user.

get_all_tokens(user_address: eth_typing.evm.HexAddress, limit: Optional[int] = None) list[int][source]

Get all tokens for user.

is_approved(token_id: int, option: Optional[matic.json_types.ITransactionOption] = None) bool[source]

Check if given token is approved for contract.

approve(token_id: int, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Approve token with given id to contract (root chain).

deposit(token_id: int, user_address: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit given token from root chain to child.

deposit_many(token_ids: Sequence[int], user_address: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit given tokens from root chain to child.

withdraw_start(token_id: int, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Begin withdrawal to root chain (on child chain).

withdraw_start_with_metadata(token_id: int, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Begin withdrawal to root chain with writing of metadata (on child chain).

withdraw_start_many(token_ids: Sequence[int], private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Begin withdrawal of multiple tokens to root chain (on child chain).

withdraw_exit_on_index(burn_transaction_hash: bytes, index: int, private_key: Optional[str] = None, option: Optional[matic.json_types.IExitTransactionOption] = None)[source]

Complete withdraw process for token on given index.

This function should be called after checkpoint has been submitted for the block containing burn tx.

This function uses API to fetch proof data.

is_withdraw_exited_many(tx_hash: bytes) bool[source]

Check if batch withdrawal is already exited for given transaction.

is_withdraw_exited_on_index(tx_hash: bytes, index: int) bool[source]

Check if withdrawal is already exited for given transaction on index.

transfer(token_id: int, from_: eth_typing.evm.HexAddress, to: eth_typing.evm.HexAddress, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Transfer to another user.

ERC 1155

Classes:

ERC1155

Arbitrary ERC-1155-compliant token.

class matic.pos.erc_1155.ERC1155(token_address: eth_typing.evm.HexAddress, is_parent: bool, client: matic.utils.web3_side_chain_client.Web3SideChainClient[matic.json_types.IPOSClientConfig], get_pos_contracts: Callable[[], matic.json_types.IPOSContracts])[source]

Bases: matic.pos.pos_token.TokenWithApproveAll

Arbitrary ERC-1155-compliant token.

Attributes:

CONTRACT_NAME

Name of a contract.

BURN_EVENT_SIGNATURE

used for exit methods.

mintable_predicate_address

Address of mintable predicate for this token.

Methods:

get_balance

Get balance of a user for supplied token.

approve_all_for_mintable

Approve all tokens for mintable token.

deposit

Deposit supplied amount of token for a user.

deposit_many

Deposit supplied amount of multiple token for user.

withdraw_start

Start withdraw process by burning the required amount for a token.

withdraw_start_many

Start the withdraw process by burning multiple tokens at a time.

withdraw_exit_many

Exit the multiple withdraw process.

withdraw_exit_faster_many

Exit the multiple withdraw process.

is_withdraw_exited_many

Check if batch exit has been completed for a transaction hash.

transfer

Transfer the required amount of a token to another user.

CONTRACT_NAME: str = 'ChildERC1155'

Name of a contract.

BURN_EVENT_SIGNATURE: bytes = b'\xc3\xd5\x81h\xc5\xaes\x97s\x1d\x06=[\xbf=exTBsC\xf4\xc0\x83$\x0fz\xac\xaa-\x0fb'

used for exit methods.

Type

Burn event signature

property mintable_predicate_address: Optional[eth_typing.evm.HexAddress]

Address of mintable predicate for this token.

get_balance(user_address: eth_typing.evm.HexAddress, token_id: int, option: Optional[matic.json_types.ITransactionOption] = None) int[source]

Get balance of a user for supplied token.

approve_all_for_mintable(private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Approve all tokens for mintable token.

deposit(amount: int, token_id: int, user_address: eth_typing.evm.HexAddress, data: Optional[bytes] = None, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit supplied amount of token for a user.

deposit_many(amounts: Iterable[int], token_ids: Iterable[int], user_address: eth_typing.evm.HexAddress, data: Optional[bytes] = None, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Deposit supplied amount of multiple token for user.

withdraw_start(token_id: int, amount: int, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Start withdraw process by burning the required amount for a token.

withdraw_start_many(token_ids: Sequence[int], amounts: Sequence[int], private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Start the withdraw process by burning multiple tokens at a time.

withdraw_exit_many(burn_transaction_hash: bytes, private_key: Optional[str] = None, option: Optional[matic.json_types.IExitTransactionOption] = None)[source]

Exit the multiple withdraw process.

Exit the withdraw process for many burned transaction and get the burned amount on root chain.

This function fetches blocks and builds a proof manually.

withdraw_exit_faster_many(burn_transaction_hash: bytes, private_key: Optional[str] = None, option: Optional[matic.json_types.IExitTransactionOption] = None)[source]

Exit the multiple withdraw process.

Exit the withdraw process for many burned transaction and get the burned amount on root chain.

This function uses API to get proof faster.

is_withdraw_exited_many(tx_hash: bytes) bool[source]

Check if batch exit has been completed for a transaction hash.

transfer(from_: eth_typing.evm.HexAddress, to: eth_typing.evm.HexAddress, amount: int, token_id: int, data: bytes | None = b'', private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Transfer the required amount of a token to another user.

Root chain manager

Classes:

RootChainManager

Root chain manager handles common operations related to POS bridge withdrawal.

class matic.pos.root_chain_manager.RootChainManager(client: matic.utils.web3_side_chain_client.Web3SideChainClient[matic.json_types.IPOSClientConfig], address: eth_typing.evm.HexAddress)[source]

Bases: matic.utils.base_token.BaseToken[matic.json_types.IPOSClientConfig]

Root chain manager handles common operations related to POS bridge withdrawal.

Methods:

deposit

Finish deposit operation.

exit

Finish exit operation.

is_exit_processed

Check if exit was already processed for given transaction.

deposit(user_address: eth_typing.evm.HexAddress, token_address: eth_typing.evm.HexAddress, deposit_data: bytes, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Finish deposit operation.

When token is approved, this is used to process “conversion”. It may take 5-10 minutes after this call to receive funds.

Parameters
  • user_address – Receiving user address

  • token_address – Address of contract defining token

  • deposit_data – Pre-built binary data to send

  • private_key – Receiving user PK

  • option – Standard transaction option.

exit(exit_payload: bytes, private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Finish exit operation.

Parameters
  • exit_payload – Pre-built binary data to send

  • private_key – Sender PK

  • option – Standard transaction option.

is_exit_processed(exit_hash: bytes) bool[source]

Check if exit was already processed for given transaction.

Base POS token

Classes:

POSToken

Base class for all tokens based on POS bridge protocol.

TokenWithApproveAll

This is a general token with common methods for ERC721 and ERC1155.

class matic.pos.pos_token.POSToken(token_address: eth_typing.evm.HexAddress, is_parent: bool, client: matic.utils.web3_side_chain_client.Web3SideChainClient[matic.json_types.IPOSClientConfig], get_pos_contracts: Callable[[], matic.json_types.IPOSContracts])[source]

Bases: matic.utils.base_token.BaseToken[matic.json_types.IPOSClientConfig]

Base class for all tokens based on POS bridge protocol.

Attributes:

CONTRACT_NAME

Name of a contract.

BURN_EVENT_SIGNATURE

used for exit methods.

root_chain_manager

Get RootChainManager instance.

exit_util

Get ExitUtil instance.

predicate_address

Memoise and get predicate address from root chain manager.

Methods:

is_withdrawn

Check if transaction withdrawal was completed.

is_withdrawn_on_index

Check if transaction withdrawal was completed on index.

withdraw_exit_pos

Base POS exit method, called by more specific implementations.

withdraw_exit

Complete withdraw process.

withdraw_exit_faster

Complete withdraw process.

is_withdraw_exited

Check if exit has been completed for a transaction hash.

CONTRACT_NAME: str

Name of a contract.

BURN_EVENT_SIGNATURE: bytes

used for exit methods.

Type

Burn event signature

property root_chain_manager: matic.pos.root_chain_manager.RootChainManager

Get RootChainManager instance.

property exit_util: matic.utils.exit_util.ExitUtil[matic.json_types.IPOSClientConfig]

Get ExitUtil instance.

property predicate_address: eth_typing.evm.HexAddress

Memoise and get predicate address from root chain manager.

is_withdrawn(tx_hash: bytes, event_signature: bytes) bool[source]

Check if transaction withdrawal was completed.

is_withdrawn_on_index(tx_hash: bytes, index: int, event_signature: bytes) bool[source]

Check if transaction withdrawal was completed on index.

withdraw_exit_pos(burn_tx_hash: bytes, event_signature: bytes, private_key: Optional[str] = None, is_fast: bool = True, index: int = 0, *, option: Optional[matic.json_types.IExitTransactionOption] = None) None[source]

Base POS exit method, called by more specific implementations.

withdraw_exit(burn_transaction_hash: bytes, private_key: Optional[str] = None, option: Optional[matic.json_types.IExitTransactionOption] = None)[source]

Complete withdraw process.

This function should be called after checkpoint has been submitted for the block containing burn tx.

This function fetches required blocks and builds proof using them.

withdraw_exit_faster(burn_transaction_hash: bytes, private_key: Optional[str] = None, option: Optional[matic.json_types.IExitTransactionOption] = None)[source]

Complete withdraw process.

This function should be called after checkpoint has been submitted for the block containing burn tx.

This function uses API to fetch proof data.

is_withdraw_exited(tx_hash: bytes) bool[source]

Check if exit has been completed for a transaction hash.

class matic.pos.pos_token.TokenWithApproveAll(token_address: eth_typing.evm.HexAddress, is_parent: bool, client: matic.utils.web3_side_chain_client.Web3SideChainClient[matic.json_types.IPOSClientConfig], get_pos_contracts: Callable[[], matic.json_types.IPOSContracts])[source]

Bases: matic.pos.pos_token.POSToken

This is a general token with common methods for ERC721 and ERC1155.

Methods:

is_approved_all

Check if a user is approved for all tokens.

approve_all

Approve all tokens.

is_approved_all(user_address: eth_typing.evm.HexAddress, option: Optional[matic.json_types.ITransactionOption] = None) bool[source]

Check if a user is approved for all tokens.

approve_all(private_key: Optional[str] = None, option: Optional[matic.json_types.ITransactionOption] = None)[source]

Approve all tokens.