简体   繁体   English

如何使用 python 的库 cosmpy 获取 cosmos 钱包余额?

[英]How to get cosmos wallet balance with python's library cosmpy?

I'm trying to use the cosmpy library as a client for Cosmos network我正在尝试使用cosmpy库作为Cosmos 网络的客户端

Trying to do it this way:尝试这样做:

    from cosmpy.aerial.client import LedgerClient
    from cosmpy.aerial.config import NetworkConfig
    from cosmpy.aerial.wallet import LocalWallet
    from cosmpy.crypto.address import Address

    receiver_addr = Address(tests_address2)

    generated_wallet = LocalWallet.generate(prefix='cosmos')

    cfg = NetworkConfig(
        chain_id="Cosmos-Hub",
        url="grpc+https://grpc-cosmoshub.blockapsis.com:429",
        fee_minimum_gas_price=1,
        fee_denomination="uatom",
        staking_denomination="uatom",
    )
    cl = LedgerClient(cfg)

    res = cl.query_bank_balance(address=Address(receiver_addr))

but always getting this exception:但总是得到这个例外:

E0829 19:01:51.948000000 35660 src/core/ext/transport/chttp2/transport/hpack_parser.cc:1234] Error parsing metadata: error=invalid value key=content-type value=text/html
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2022.1.2\plugins\python\helpers\pydev\pydevd.py", line 1491, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2022.1.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/Python_Projects/Cosmos_Client/tests/test_client.py", line 104, in <module>
    res = cl.query_bank_balance(address=Address(wallet_data['address']))
  File "D:\Python_Projects\Cosmos_Client\venv\lib\site-packages\cosmpy\aerial\client\__init__.py", line 226, in query_bank_balance
    resp = self.bank.Balance(req)
  File "D:\Python_Projects\Cosmos_Client\venv\lib\site-packages\grpc\_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "D:\Python_Projects\Cosmos_Client\venv\lib\site-packages\grpc\_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.UNAVAILABLE
    details = "Received http2 header with status: 502"
    debug_error_string = "{"created":"@1661788911.949000000","description":"Error received from peer ipv4:54.219.236.123:429","file":"src/core/lib/surface/call.cc","file_line":967,"grpc_message":"Received http2 header with status: 502","grpc_status":14}"
>
python-BaseException

how to process blockchain operations with cosmpy library?如何使用cosmpy库处理区块链操作?

The error was due inactive chain peer URL.错误是由于非活动链对等体 URL。 Need to find working URL here: https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/chain.json需要在这里找到工作的 URL: https://raw.githubusercontent.com/cosmos/chain-registry/master/cosmoshub/chain.Z466DEEC76ECDF5FCA6D38571F6324D54

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM