cosmpy.clients package — cosmpy documentation

# cosmpy.clients package

## Submodules

## cosmpy.clients.cosmwasm_client module

Implementation of CosmWasm query client.

class cosmpy.clients.cosmwasm_client.CosmWasmClient(channel: Union[grpc._channel.Channel, cosmpy.common.rest_client.RestClient])

  Bases: `object`

  High level client for REST/gRPC node interaction.

  get_balance(address: cosmpy.crypto.address.Address, denom: str) → cosmos.bank.v1beta1.query_pb2.QueryBalanceResponse

    Get balance of specific account and denom

    Parameters

      - address – Address

      - denom – Denomination

    Returns

      QueryBalanceResponse

  query_account_data(address: cosmpy.crypto.address.Address) → cosmos.auth.v1beta1.auth_pb2.BaseAccount

    Query account data for signing

    Parameters

      address – Address of account to query data about

    Raises

      TypeError – in case of wrong account type.

    Returns

      BaseAccount

  query_contract_state(contract_address: str, msg: Union[Dict[str, Optional[Union[str, int, bool, float, Dict[Any, Any], List[Any]]]], Dict[str, Dict[Any, Any]]]) → Union[Dict[str, Optional[Union[str, int, bool, float, Dict[Any, Any], List[Any]]]], Dict[str, Dict[Any, Any]]]

    Get state of smart contract

    Parameters

      - contract_address – Contract address

      - msg – Parameters to be passed to query function inside contract

    Returns

      JSON query response

## cosmpy.clients.signing_cosmwasm_client module

Implementation of CosmWasm signing client.

class cosmpy.clients.signing_cosmwasm_client.SigningCosmWasmClient(private_key: cosmpy.crypto.keypairs.PrivateKey, channel: Union[grpc._channel.Channel, cosmpy.common.rest_client.RestClient], chain_id: str)

  Bases: `cosmpy.clients.cosmwasm_client.CosmWasmClient`

  High level client for REST/gRPC node interaction with ability to sign transactions.

  DEFAULT_DEPLOY_GAS_LIMIT = 1500000
  DEFAULT_GAS_LIMIT = 200000
  broadcast_tx(tx: cosmos.tx.v1beta1.tx_pb2.Tx, wait_time: int = 10) → cosmos.tx.v1beta1.service_pb2.GetTxResponse

    Broadcast transaction and get receipt

    Parameters

      - tx – Transaction

      - wait_time – Number of seconds to wait before getting transaction receipt

    Raises

      RuntimeError – if broadcasting fails.

    Returns

      GetTxResponse

  deploy_contract(contract_filename: pathlib.Path, gas_limit: int = 1500000) → int

    Deploy smart contract on chain

    Parameters

      - contract_filename – Path to smart contract bytecode

      - gas_limit – Gas limit

    Returns

      Code ID

  execute_contract(contract_address: str, msg: Union[Dict[str, Optional[Union[str, int, bool, float, Dict[Any, Any], List[Any]]]], Dict[str, Dict[Any, Any]]], funds: Optional[List[cosmos.base.v1beta1.coin_pb2.Coin]] = None, gas_limit: int = 200000) → cosmos.tx.v1beta1.service_pb2.GetTxResponse

    Send execute message to interact with smart contract

    Parameters

      - contract_address – Address of contract

      - msg – Paramaters to be passed to smart contract

      - funds – Funds to be sent to smart contract

      - gas_limit – Gas limit

    Returns

      GetTxResponse

  generate_tx(packed_msgs: List[google.protobuf.any_pb2.Any], from_addresses: List[cosmpy.crypto.address.Address], pub_keys: List[bytes], fee: Optional[List[cosmos.base.v1beta1.coin_pb2.Coin]] = None, memo: str = '', gas_limit: int = 200000) → cosmos.tx.v1beta1.tx_pb2.Tx

    Generate transaction that can be later signed

    Parameters

      - packed_msgs – Messages to be in transaction

      - from_addresses – List of addresses of each sender

      - pub_keys – List of public keys

      - fee – Transaction fee

      - memo – Memo

      - gas_limit – Gas limit

    Returns

      Tx

  static get_code_id(response: cosmos.tx.v1beta1.service_pb2.GetTxResponse) → int

    Get code id from store code transaction response

    Parameters

      response – Response of store code transaction

    Returns

      integer code_id

  static get_contract_address(response: cosmos.tx.v1beta1.service_pb2.GetTxResponse) → str

    Get contract address from instantiate msg response :param response: Response of MsgInstantiateContract transaction

    Returns

      contract address string

  static get_packed_exec_msg(sender_address: cosmpy.crypto.address.Address, contract_address: str, msg: Union[Dict[str, Optional[Union[str, int, bool, float, Dict[Any, Any], List[Any]]]], Dict[str, Dict[Any, Any]]], funds: Optional[List[cosmos.base.v1beta1.coin_pb2.Coin]] = None) → google.protobuf.any_pb2.Any

    Create and pack MsgExecuteContract

    Parameters

      - sender_address – Address of sender

      - contract_address – Address of contract

      - msg – Paramaters to be passed to smart contract

      - funds – Funds to be sent to smart contract

    Returns

      Packed MsgExecuteContract

  static get_packed_init_msg(sender_address: cosmpy.crypto.address.Address, code_id: int, init_msg: Union[Dict[str, Optional[Union[str, int, bool, float, Dict[Any, Any], List[Any]]]], Dict[str, Dict[Any, Any]]], label='contract', funds: Optional[List[cosmos.base.v1beta1.coin_pb2.Coin]] = None) → google.protobuf.any_pb2.Any

    Create and pack MsgInstantiateContract

    Parameters

      - sender_address – Sender’s address

      - code_id – code_id of stored contract bytecode

      - init_msg – Parameters to be passed to smart contract constructor

      - label – Label

      - funds – Funds transferred to new contract

    Returns

      Packed MsgInstantiateContract

  static get_packed_send_msg(from_address: cosmpy.crypto.address.Address, to_address: cosmpy.crypto.address.Address, amount: List[cosmos.base.v1beta1.coin_pb2.Coin]) → google.protobuf.any_pb2.Any

    Generate and pack MsgSend

    Parameters

      - from_address – Address of sender

      - to_address – Address of recipient

      - amount – List of Coins to be sent

    Returns

      packer ProtoAny type message

  static get_packed_store_msg(sender_address: cosmpy.crypto.address.Address, contract_filename: pathlib.Path) → google.protobuf.any_pb2.Any

    Loads contract bytecode, generate and return packed MsgStoreCode

    Parameters

      - sender_address – Address of transaction sender

      - contract_filename – Path to smart contract bytecode

    Returns

      Packed MsgStoreCode

  instantiate_contract(code_id: int, init_msg: Union[Dict[str, Optional[Union[str, int, bool, float, Dict[Any, Any], List[Any]]]], Dict[str, Dict[Any, Any]]], label='contract', funds: Optional[List[cosmos.base.v1beta1.coin_pb2.Coin]] = None, gas_limit: int = 200000) → str

    Instantiate smart contract and return contract address

    Parameters

      - code_id – code_id of stored contract bytecode

      - init_msg – Parameters to be passed to smart contract constructor

      - label – Label

      - funds – Funds transferred to new contract

      - gas_limit – Gas limit

    Returns

      Contract address

  send_tokens(to_address: cosmpy.crypto.address.Address, amount: List[cosmos.base.v1beta1.coin_pb2.Coin]) → cosmos.tx.v1beta1.service_pb2.GetTxResponse

    Send native tokens from clients address to to_address

    Parameters

      - to_address – Address of recipient

      - amount – List of tokens to be transferred

    Returns

      GetTxResponse

  sign_tx(tx: cosmos.tx.v1beta1.tx_pb2.Tx)

    Sign transaction

    Parameters

      tx – Transaction to be signed

## Module contents

This package contains high level clients modules.