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

Multiple Transacations and GetCw20Balance #302

Open
thehood1 opened this issue Feb 8, 2024 · 1 comment
Open

Multiple Transacations and GetCw20Balance #302

thehood1 opened this issue Feb 8, 2024 · 1 comment

Comments

@thehood1
Copy link

thehood1 commented Feb 8, 2024

Hello,

There is GetCw20Balance in python API docs, but there isn't example code. Can you please add it?

Also, is it possible to broadcast two or more different transactions at once, or transactions must be broadcasted one by one? If it is possible which msg I should use?

Thanks

@apri-me
Copy link

apri-me commented Jul 25, 2024

Here's an example of how you can get cw20 balances via python SDK.

import asyncio
#
from pyinjective import AsyncClient
from pyinjective.core.network import Network
#
from pprint import pprint


async def main():
    client = AsyncClient(Network.mainnet())
    result = await client.exchange_explorer_api.fetch_cw20_balance('inj...')
    pprint(result)


if __name__ == "__main__":
    asyncio.run(main())

Output will be something like below:

{'field': [{'account': 'inj...',
            'balance': '....',
            'contractAddress': 'inj...',
            'cw20Metadata': {'tokenInfo': {'decimals': '...',
                                           'name': '...',
                                           'symbol': '...',
                                           'totalSupply': ''}},
            'updatedAt': '...'},
           {'account': 'inj...',
            'balance': '....',
            'contractAddress': 'inj...',
            'cw20Metadata': {'tokenInfo': {'decimals': '...',
                                           'name': '...',
                                           'symbol': '...',
                                           'totalSupply': ''}},
            'updatedAt': '...'}]}

Also, You can send multiple messages through one tx. Examples are provided in the API docs, I just show you how you can put multiple messages in one tx.

tx = (
      Transaction()
      .with_messages(*msgs)
      .with_sequence(sequence)
      .with_account_num(client.get_number())
      .with_chain_id(chain_id)
)

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