{"id":22983367,"url":"https://github.com/sterliakov/pymatic","last_synced_at":"2025-04-02T10:24:05.943Z","repository":{"id":54472369,"uuid":"512914517","full_name":"sterliakov/pymatic","owner":"sterliakov","description":"Python port of matic.js Polygon developer toolkit","archived":false,"fork":false,"pushed_at":"2022-08-22T19:45:20.000Z","size":220,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-08T07:53:02.353Z","etag":null,"topics":["blockchain","matic","polygon","web3","web3py"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sterliakov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-11T21:33:04.000Z","updated_at":"2024-02-23T11:08:05.000Z","dependencies_parsed_at":"2022-08-13T16:50:31.616Z","dependency_job_id":null,"html_url":"https://github.com/sterliakov/pymatic","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sterliakov%2Fpymatic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sterliakov%2Fpymatic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sterliakov%2Fpymatic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sterliakov%2Fpymatic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sterliakov","download_url":"https://codeload.github.com/sterliakov/pymatic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246795060,"owners_count":20835126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","matic","polygon","web3","web3py"],"created_at":"2024-12-15T02:38:29.823Z","updated_at":"2025-04-02T10:24:05.913Z","avatar_url":"https://github.com/sterliakov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PyPi Version](https://img.shields.io/pypi/v/matic.svg)](https://pypi.python.org/pypi/matic/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/matic.svg)](https://pypi.python.org/pypi/matic/)\n[![Read the Docs](https://readthedocs.org/projects/pymatic/badge/?version=latest)](https://pymatic.readthedocs.io/en/latest/?badge=latest)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white)](https://github.com/pre-commit/pre-commit)\n[![Code style: black](https://img.shields.io/badge/code%20style-blue-blue.svg)](https://blue.readthedocs.io/)\n\n\n# Matic - Python SDK to assist developers on Polygon blockchain.\n\n**Disclaimer: this package is not officialy maintained by Polygon affiliates.**\n\nRead our [documentation](https://readthedocs.org/projects/pymatic/badge/?version=latest) on ReadTheDocs.\n\nThis project is a direct python port of [matic.js](https://github.com/maticnetwork/matic.js/) library. It includes also [maticjs-web3](https://github.com/maticnetwork/maticjs-web3/) port.\n\nThis library is very new, so documentation improvement is currently in progress. Please refer to official js SDK [docs](https://docs.polygon.technology/docs/develop/) for more comprehensive tutorials.\n\n\n# Installation\n\nInstall with pip:\n\n```bash\npip install -U matic\n```\n\nInstall from source:\n\n```bash\ngit clone https://github.com/sterliakov/pymatic/\ncd pymatic\npip install .\n```\n\nSupported extras:\n\n- `test`: install test and development dependencies (`pip install matic[test]`)\n- `docs`: dependencies for building documentation (`pip install matic[docs]`)\n\n\n# Obtaining tokens: initial setup\n\nTo proceed woth testing, you'll need environment configuration based on the following template:\n\n```bash\nUSER1_FROM=  # 0x...\nUSER1_PRIVATE_KEY=  # Without prefix\nUSER2_FROM=  # 0x...\nUSER2_PRIVATE_KEY=  # Without prefix\n\nROOT_RPC=https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161\nMATIC_RPC=https://rpc-mumbai.maticvigil.com\nPROOF_API=https://apis.matic.network/api/v1/\n```\n\nThe RPC provided can be used as-is for testnet (Mumbai - child chain, Goerli - parent chain).\n\nTo run any of test examples, you'll need two addresses. **Don't use real addresses on testnet!**\n\nThen, to execute any transactions you'll need some MATIC tokens. You can obtain them via the [polygon faucet](https://faucet.polygon.technology/) (better - for both addresses, so you don't think later how to transfer something back).\n\nTo power transactions originating from parent chain, you'll need some Goerli ETH. You can obtain them via [this faucet](https://goerlifaucet.com/).\n\nIf you want to experiment with dummy tokens, read the following sections on how to obtain them.\n\n## ERC20\n\nERC20 token used in this tutorial is \"Dummy ERC20 (DERC20)\".\n\nMapped contracts:\n- parent: [0x655F2166b0709cd575202630952D71E2bB0d61Af](https://goerli.etherscan.io/address/0x655F2166b0709cd575202630952D71E2bB0d61Af)\n- child: [0xfe4F5145f6e09952a5ba9e956ED0C25e3Fa4c7F1](https://mumbai.polygonscan.com/address/0xfe4F5145f6e09952a5ba9e956ED0C25e3Fa4c7F1)\n\nYou can obtain them via the [polygon faucet](https://faucet.polygon.technology/). To avoid resolving unexpected \"insufficient balance\" errors in future, get this token both on Mumbai and Goerli testnets.\n\n## ERC721\n\nWe use \"Test ERC721 (DERC721)\" as a ERC721 token example.\n\nMapped contracts:\n- parent: [0x02C869F27B0D09004107818B1150e354d38Cb189](https://goerli.etherscan.io/address/0x02C869F27B0D09004107818B1150e354d38Cb189)\n- child: [0xD6A8e816D2314E5635aB71991552A435c00B2952](https://mumbai.polygonscan.com/address/0xD6A8e816D2314E5635aB71991552A435c00B2952)\n\n\nThis is perhaps the most difficult token to obtain.\n\n* First, mint them on Goerli (you can do it [directly from explorer](https://goerli.etherscan.io/address/0x02C869F27B0D09004107818B1150e354d38Cb189#writeContract), if you're using browser-syncable wallet like metamask, or by interacting with contract by any convenient tool of your choice). They are not divisible, so every transaction uses 1 or more tokens, and you mint 1 at a time. Mint as many as you need.\n* Then, deposit these tokens to Mumbai testnet. You can use the following script to do so:\n\n```python\n#!/usr/bin/env python\n\nimport os\n\nfrom dotenv import load_dotenv\nfrom matic import POSClient\nfrom web3 import Web3\n\nload_dotenv()\n\nfrom_ = os.getenv('USER1_FROM')\nfrom_pk = os.getenv('USER1_PRIVATE_KEY')\n\nparent_contract = '0x02C869F27B0D09004107818B1150e354d38Cb189'\nrpc_parent = os.getenv('ROOT_RPC', 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161')\nrpc_child = os.getenv('MATIC_RPC', 'https://rpc-mumbai.maticvigil.com')\n\npos_client = POSClient({\n    'network': 'testnet',\n    'version': 'mumbai',\n    'parent': {\n        'provider': Web3.HTTPProvider(rpc_parent),\n        'default_config': {'from': from_},\n    },\n    'child': {\n        'provider': Web3.HTTPProvider(rpc_child),\n        'default_config': {'from': from_},\n    },\n})\n\nerc_721_parent = pos_client.erc_721(parent_contract, True)\n\ntokens = erc_721_parent.get_all_tokens(from_)\n\napprove_tx = erc_721_parent.approve_all(from_pk)\nassert approve_tx.receipt\n\n# You can use only some of the tokens here to preserve something on parent chain too.\ndeposit_tx = erc_721_parent.deposit_many(tokens, from_, from_pk)\nprint(deposit_tx.transaction_hash)\nassert deposit_tx.receipt\n```\n\nYou can wait for these tokens to be added with `pos_client.is_deposited(transaction_hash)` or just monitor your balance with your wallet or an explorer.\n\nIf you've spent all of the tokens, you can mint a couple more.\n\n## ERC1155\n\nWe use \"Test ERC1155 (DERC1155)\" as a ERC1155 token example.\n\nMapped contracts:\n- parent: [0x2e3Ef7931F2d0e4a7da3dea950FF3F19269d9063](https://goerli.etherscan.io/address/0x2e3Ef7931F2d0e4a7da3dea950FF3F19269d9063)\n- child: [0xA07e45A987F19E25176c877d98388878622623FA](https://mumbai.polygonscan.com/address/0xA07e45A987F19E25176c877d98388878622623FA)\n\nYou can obtain tokens on both testnets via the [polygon faucet](https://faucet.polygon.technology/).\n\n\n# Troubleshooting\n\nIf you feel like something is going wrong with RPC, try waiting first. Although JS SDK claims to provide low timeouts, sometimes checkpoint event takes 2 hours to complete (see CI tests run time - it's waiting for 3 checkpoint events), StateSync - up to 20 minutes. If transactions are lost or pending for a long time, try sending zero MATIC to your address - sometimes it resolves this issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsterliakov%2Fpymatic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsterliakov%2Fpymatic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsterliakov%2Fpymatic/lists"}