mxpyserializer


Namemxpyserializer JSON
Version 0.3.2 PyPI version JSON
download
home_page
SummaryPython package that serialize and deserialize MultiversX data format by using ABI definitions
upload_time2024-02-28 06:11:49
maintainer
docs_urlNone
authorEtienne Wallet
requires_python>=3.10
license
keywords elrond multiversx smart-contract abi data serialize
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MxPySerializer
MxPySerializer is a python package that serialize and deserialize MultiversX data format by using ABI definitions.

## Installation

Install MxPySerializer with PyPi

```bash
pip install -U mxpyserializer
```

## Quick Example

```python
import json
from pathlib import Path
from multiversx_sdk_core import Address, ContractQueryBuilder

from multiversx_sdk_network_providers import ProxyNetworkProvider

from mxpyserializer.abi_serializer import AbiSerializer

# create the serializer and encode the arguments
file_path = Path("abis/onedex-sc.abi.json")
abi_serializer = AbiSerializer.from_abi(file_path)
endpoint_name = "viewPair"
args = [57]  # id of the Pair
encoded_args = abi_serializer.encode_endpoint_inputs(endpoint_name, args)

# create the query as usual
proxy_provider = ProxyNetworkProvider("https://gateway.multiversx.com")
builder = ContractQueryBuilder(
    contract=Address.from_bech32(
        "erd1qqqqqqqqqqqqqpgqqz6vp9y50ep867vnr296mqf3dduh6guvmvlsu3sujc"
    ),
    function=endpoint_name,
    call_arguments=encoded_args,
)
query = builder.build()
response = proxy_provider.query_contract(query)

# parse the results and display them
parsed_results = abi_serializer.decode_contract_query_response(
    endpoint_name, response
)
print(json.dumps(parsed_results, indent=4))
```

```json
[
    {
        "pair_id": 57,
        "state": {
            "name": "Active",
            "discriminant": 1,
            "values": null
        },
        "enabled": true,
        "owner": "erd1vudplk63q6fph97suwkqeafw2hmlgctp2aqszsxhv5ur3lkvgrmscg53uk",
        "first_token_id": "HYPE-619661",
        "second_token_id": "LEGLD-d74da9",
        "lp_token_id": "HYPELEGLD-d65493",
        "lp_token_decimal": 18,
        "first_token_reserve": 27675995026043458404845725,
        "second_token_reserve": 586365485849411410,
        "lp_token_supply": 1016042899275369744,
        "lp_token_roles_are_set": true
    }
]
```

## Documentation

Heads up to the [documentation](https://mxpyserializer.readthedocs.io) to get started!

## Contribution

If you have a feedback, a proposal or if you want to contribute, don't hesitate! we welcome all hands on board :wink:

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "mxpyserializer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "elrond,multiversx,smart-contract,ABI,data,serialize",
    "author": "Etienne Wallet",
    "author_email": "",
    "download_url": "",
    "platform": null,
    "description": "# MxPySerializer\nMxPySerializer is a python package that serialize and deserialize MultiversX data format by using ABI definitions.\n\n## Installation\n\nInstall MxPySerializer with PyPi\n\n```bash\npip install -U mxpyserializer\n```\n\n## Quick Example\n\n```python\nimport json\nfrom pathlib import Path\nfrom multiversx_sdk_core import Address, ContractQueryBuilder\n\nfrom multiversx_sdk_network_providers import ProxyNetworkProvider\n\nfrom mxpyserializer.abi_serializer import AbiSerializer\n\n# create the serializer and encode the arguments\nfile_path = Path(\"abis/onedex-sc.abi.json\")\nabi_serializer = AbiSerializer.from_abi(file_path)\nendpoint_name = \"viewPair\"\nargs = [57]  # id of the Pair\nencoded_args = abi_serializer.encode_endpoint_inputs(endpoint_name, args)\n\n# create the query as usual\nproxy_provider = ProxyNetworkProvider(\"https://gateway.multiversx.com\")\nbuilder = ContractQueryBuilder(\n    contract=Address.from_bech32(\n        \"erd1qqqqqqqqqqqqqpgqqz6vp9y50ep867vnr296mqf3dduh6guvmvlsu3sujc\"\n    ),\n    function=endpoint_name,\n    call_arguments=encoded_args,\n)\nquery = builder.build()\nresponse = proxy_provider.query_contract(query)\n\n# parse the results and display them\nparsed_results = abi_serializer.decode_contract_query_response(\n    endpoint_name, response\n)\nprint(json.dumps(parsed_results, indent=4))\n```\n\n```json\n[\n    {\n        \"pair_id\": 57,\n        \"state\": {\n            \"name\": \"Active\",\n            \"discriminant\": 1,\n            \"values\": null\n        },\n        \"enabled\": true,\n        \"owner\": \"erd1vudplk63q6fph97suwkqeafw2hmlgctp2aqszsxhv5ur3lkvgrmscg53uk\",\n        \"first_token_id\": \"HYPE-619661\",\n        \"second_token_id\": \"LEGLD-d74da9\",\n        \"lp_token_id\": \"HYPELEGLD-d65493\",\n        \"lp_token_decimal\": 18,\n        \"first_token_reserve\": 27675995026043458404845725,\n        \"second_token_reserve\": 586365485849411410,\n        \"lp_token_supply\": 1016042899275369744,\n        \"lp_token_roles_are_set\": true\n    }\n]\n```\n\n## Documentation\n\nHeads up to the [documentation](https://mxpyserializer.readthedocs.io) to get started!\n\n## Contribution\n\nIf you have a feedback, a proposal or if you want to contribute, don't hesitate! we welcome all hands on board :wink:\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python package that serialize and deserialize MultiversX data format by using ABI definitions",
    "version": "0.3.2",
    "project_urls": {
        "Homepage": "https://github.com/Catenscia/MxPySerializer"
    },
    "split_keywords": [
        "elrond",
        "multiversx",
        "smart-contract",
        "abi",
        "data",
        "serialize"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "65a186743c9e689f5fe25c4b6dcccd2aa048f1fb60a3b66d948969998b902fda",
                "md5": "e7bb717865f21183d080a0db15adf4dc",
                "sha256": "0f1869a7b5e5b0e59866e5c7c1df24a63451f327c1158a0ea94d6560070c5060"
            },
            "downloads": -1,
            "filename": "mxpyserializer-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e7bb717865f21183d080a0db15adf4dc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 25360,
            "upload_time": "2024-02-28T06:11:49",
            "upload_time_iso_8601": "2024-02-28T06:11:49.516116Z",
            "url": "https://files.pythonhosted.org/packages/65/a1/86743c9e689f5fe25c4b6dcccd2aa048f1fb60a3b66d948969998b902fda/mxpyserializer-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-28 06:11:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Catenscia",
    "github_project": "MxPySerializer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "mxpyserializer"
}
        
Elapsed time: 0.26867s