Skip to content

Multiple Transacations and GetCw20Balance #302

Open

Description

@thehood1

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

Activity

  1. apri-me commented on Jul 25, 2024

    @apri-me

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions