Skip to content

Error when passing dict to custom message #33

@123Serg

Description

@123Serg

Hello, I'm trying to send MsgTokenizeShares and I have to pass amount(dict of denom and value) as an argument. Here is the code:

from mospy import Account, Transaction
from mospy.clients import HTTPClient
account = Account(
    seed_phrase="",
    hrp='cosmos'
)
tx = Transaction(
    account=account,
    chain_id='cosmoshub-4',
    gas=200000,
)
msg = {
    "delegator_address": account.address,
    "validator_address": "cosmosvaloper157v7tczs40axfgejp2m43kwuzqe0wsy0rv8puv",
    "amount": {"denom": "uatom", "amount": "1000"},
    "tokenized_share_owner": account.address
}
tx.add_dict_msg(msg, type_url="/cosmos.staking.v1beta1.MsgTokenizeShares")
client = HTTPClient(
    api="https://cosmos-rest.publicnode.com"
)
tx.set_fee(
    amount=10000,
    denom="uatom"
)
client.load_account_data(account=account)
print(tx.get_tx_bytes())
response = client.broadcast_transaction(transaction=tx)
print(response)

I'm getting error:
Traceback (most recent call last): File "C:\Users\soldier\PycharmProjects\flash\cosm.py", line 23, in <module> tx.add_dict_msg(msg, type_url="/cosmos.staking.v1beta1.MsgTokenizeShares") File "C:\Users\soldier\AppData\Local\Programs\Python\Python38\lib\site-packages\mospy\Transaction.py", line 111, in add_dict_msg msg_any = generic_proto.create_any_message(type_url=type_url, msg_dict=msg_dict) File "C:\Users\soldier\AppData\Local\Programs\Python\Python38\lib\site-packages\mospy\protobuf\GenericProtobuf.py", line 67, in create_any_message self.create_message_type(type_name, msg_dict) File "C:\Users\soldier\AppData\Local\Programs\Python\Python38\lib\site-packages\mospy\protobuf\GenericProtobuf.py", line 45, in create_message_type self.create_message_type(nested_type_name, field_value[0]) KeyError: 0

Also when I'm trying to pass amount as a sting:

...
"amount": json.dumps({"denom": "uatom", "amount": "1000"}),
...

I'm getting no code errors, but response is:
{'hash': 'D2EF0A23F3EEF37BC3CF3DD50B62549340CD1CC529471708AD1FBF69868ECEE5', 'code': 2, 'log': 'errUnknownField "*types.Coin": {TagNum: 15, WireType:"start_group"}: tx parse error'}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions