Skip to main content

Python package that serialize and deserialize MultiversX data format by using ABI definitions

Project description

MxPySerializer

MxPySerializer is a python package that serialize and deserialize MultiversX data format by using ABI definitions.

Installation

Install MxPySerializer with PyPi

pip install -U mxpyserializer

Quick Example

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))
[
    {
        "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 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:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mxpyserializer-0.2.0.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

mxpyserializer-0.2.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file mxpyserializer-0.2.0.tar.gz.

File metadata

  • Download URL: mxpyserializer-0.2.0.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for mxpyserializer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bbf1d09d2cb127bccbb3666c06e1aacb2521ed395a8f347b9b6775fd930965de
MD5 110e0d4ef113869de5a8c07149d62b3d
BLAKE2b-256 f03c242766f90e4a5e8ff5db5de44e071bd30e6ac4c4030492d5754a1120ab4d

See more details on using hashes here.

File details

Details for the file mxpyserializer-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mxpyserializer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f85bfad5c02302971553063d816f2ea421544635e5a7c7ec865a07dc6fa9dcd1
MD5 88ccebd8cee179aefe3b9f8e7d945913
BLAKE2b-256 c42c26711fa4baf5fa4dd0bb2c823d058706a7a1d8b595a2635440b3560039cc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page