> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kiruse.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# CosmWasm Integration Overview

> CosmWasm integration on top of the Cosmos integration.

The CosmWasm module serves primarily as a user-friendly and convenient wrapper for a set of
predefined messages, allowing developers to interact with smart contracts more efficiently. It
exposes a few methods to upload, deploy, and execute smart contracts, as well as the query methods
subgroup implementing the various low-level queries that CosmWasm supports.

## Example

```ts theme={null}
import { Cosmos, LocalSigner, mw } from '@apophis-sdk/cosmos';
import { DefaultCosmWasmMiddlewares, CosmWasm } from '@apophis-sdk/cosmwasm';

mw.use(...DefaultCosmWasmMiddlewares);

const network = await Cosmos.getNetworkFromRegistry('neutrontestnet');
const signer = LocalSigner.fromMnemonic('...');

await Cosmos.ws(network).ready();

const response = await CosmWasm.query.smart({
  network,
  'neutron1...', // contract address
  {
    config: {},
  },
});
console.log(response);

await CosmWasm.execute(
  network,
  signer,
  'neutron1...', // contract address
  {
    increment: {},
  },
  [Cosmos.coin(1_000000n, 'untrn')], // optional native coin "funds" to pass along the call
);
```

**NOTE:** Previously, I was under the impression that smart contract messages were JSON-encoded only
by convention. This is false. Thus, previously, any smart contract message had to be passed in using
`CosmWasm.toBinary`. This, however, broke Amino support. I thus had to remove it from messages &
queries. The `CosmWasm.toBinary` helper is still useful to encode sub-messages, e.g. for the *send*
message of CW20 tokens.

## Outlook

There is still work to be done on the CosmWasm integration. Namely, further abstraction of smart
contracts and code generation for your smart contract messages, and
[AuthZ](https://docs.cosmos.network/v0.46/modules/authz/) messages.
