> ## Documentation Index
> Fetch the complete documentation index at: https://injectivelabs-mintlify-jp-native-developers-first-half.mintlify.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Wasm

`wasm`モジュールはInjectiveチェーン上にデプロイされたwasmスマートコントラクトとやり取りするための中核です。こちらでInjectiveチェーン上にデプロイされている[スマートコントラクト](https://injscan.com/smart-contracts/)の一覧を確認できます。

<Callout icon="info" color="#07C1FF" iconType="regular">
  `MsgUpdateCode`と`MsgStoreCode`はEthereumウォレット（例: Metamask）ではサポートされていません。
</Callout>

## メッセージ

### MsgExecuteContract（Transfer）

このメッセージはコントラクト関数を実行するために使用されます。以下では[CW20 spec](https://github.com/CosmWasm/cw-plus/blob/main/packages/cw20/README.md)のtransferメッセージを例として使用します。

```ts theme={null}
import { Network } from "@injectivelabs/networks";
import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx";
import { MsgExecuteContract } from "@injectivelabs/sdk-ts/core/modules";

const injectiveAddress = "inj1...";
const recipientAddress = "inj2...";
const contractAddress = "cw...";

const msg = MsgExecuteContract.fromJSON({
  contractAddress,
  sender: injectiveAddress,
  exec: {
    action: "transfer",
    msg: {
      recipient: recipientAddress,
      amount: 100000,
    },
  },
});

const txHash = await new MsgBroadcasterWithPk({
  privateKey,
  network: Network.Mainnet,
}).broadcast({
  msgs: msg,
});

console.log(txHash);
```

### MsgExecuteContract（fundsの例）

シナリオによっては、スマートコントラクトの関数に依存してスマートコントラクトへトークンを転送する必要がある場合があります。CosmWasmの慣例に従い、funds フィールドを使用してユーザーのbankモジュールからスマートコントラクトへトークンを転送します。

以下は、`test`コントラクト関数を使用して`MsgExecuteContract`を送信する例です。

```ts theme={null}
import { Network } from "@injectivelabs/networks";
import { toChainFormat } from "@injectivelabs/utils";
import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx";
import { MsgExecuteContract } from "@injectivelabs/sdk-ts/core/modules";

const injectiveAddress = "inj1...";
const contractAddress = "cw...";

const msg = MsgExecuteContract.fromJSON({
  contractAddress,
  sender: injectiveAddress,
  exec: {
    action: "test",
    funds: [
      {
        denom: "inj",
        amount: toChainFormat(1).toFixed(),
      },
    ],
  },
});

const txHash = await new MsgBroadcasterWithPk({
  privateKey,
  network: Network.Mainnet,
}).broadcast({
  msgs: msg,
});

console.log(txHash);
```

### MsgExecuteContractCompat

前述の例の`funds`配列および`msgs`オブジェクトをEIP712でパースする際にいくつかの互換性の問題があります。`MsgExecuteContract`はEIP712に適切に変換できず、Ethereumウォレットで署名できないため、EIP712と完全に互換性のある`MsgExecuteContractCompat`を導入しました。

***注:*** *`MsgExecuteContract`と`MsgExecuteContractCompat`の基盤となるメッセージは同じです。`MsgExecuteContractCompat`はEIP712互換である点だけが異なります。*

以下は、`test`コントラクト関数を使用して`MsgExecuteContractCompact`を送信する例です。

```ts theme={null}
import { Network } from "@injectivelabs/networks";
import { toChainFormat } from "@injectivelabs/utils";
import { MsgBroadcasterWithPk } from "@injectivelabs/sdk-ts/core/tx";
import { MsgExecuteContractCompat } from "@injectivelabs/sdk-ts/core/modules";

const injectiveAddress = "inj1...";
const contractAddress = "cw...";

const msg = MsgExecuteContractCompat.fromJSON({
  contractAddress,
  sender: injectiveAddress,
  exec: {
    action: "test",
    funds: [
      {
        denom: "inj",
        amount: toChainFormat(1).toFixed(),
      },
    ],
  },
});

const txHash = await new MsgBroadcasterWithPk({
  privateKey,
  network: Network.Mainnet,
}).broadcast({
  msgs: msg,
});

console.log(txHash);
```
