Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when passing dict to custom message #33

Open
123Serg opened this issue Jan 2, 2025 · 1 comment
Open

Error when passing dict to custom message #33

123Serg opened this issue Jan 2, 2025 · 1 comment

Comments

@123Serg
Copy link

123Serg commented Jan 2, 2025

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'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@123Serg and others