> ## Documentation Index
> Fetch the complete documentation index at: https://initialabs-develop.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Messages

Message is a data structure that represents an action to be executed on the blockchain.

It is a part of the transaction, which is a collection of messages that are executed atomically.

This guide will show you how to create a message object for different types of actions.

## VM-Agnostic Messages

VM-agnostic messages are messages that can be used across all VMs.

* `MsgSend()`: send coins to other address

```typescript theme={null}
const msg = new MsgSend(
    'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu',   // sender address
    'init18sj3x80fdjc6gzfvwl7lf8sxcvuvqjpvcmp6np',   // recipient address
    '1000uinit'                                      // send amount
)
```

* `MsgDelegate()`: delegate governance coin to validators (staking)

```typescript theme={null}
const msg = new MsgDelegate(
    'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // delegator address
    'init18sj3x80fdjc6gzfvwl7lf8sxcvuvqjpvcmp6np', // validator's operator addres
    '100000uinit',                                 // delegate amount
)
```

## VM-Specific Messages

#### MoveVM

* `MsgExecute()`: execute move contract entry functions

```typescript theme={null}
const msg = new MsgExecute(
    'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // sender address
    '0x1',                                         // module owner address
    'dex',                                         // module name
    'swap_script',                                 // function name
    [],                                            // type arguments
    [
        bcs.address().serialize('0x2').toBase64(), // arguments, BCS-encoded
        bcs.address().serialize('0x3').toBase64(), // arguments, BCS-encoded
        bcs.u64().serialize(10000).toBase64()      // arguments, BCS-encoded
    ], 
)
```

#### WasmVM

* `MsgStoreCode()`: store wasm contract code

```typescript theme={null}
const wasmByteCode = fs
      .readFileSync('./wasm-modules/miniwasm/example.wasm') // path of wasm file
      .toString('base64'),

const msg = new MsgStoreCode(
    'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // sender address
    wasmByteCode,                                  // raw or gzip compressed wasm bytecode
    undefined                                      // instantiate permission (optional)
  )
```

* `MsgInstantiateContract()`: instantiate wasm contract

```typescript theme={null}
const instantiateMsg = Buffer.from(JSON.stringify({ init_list: ['init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu'] })).toString('base64')

const msg = new MsgInstantiateContract(
    'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // sender address
    'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // admin address
    9,                                             // code id
    'example',                                     // label
    instantiateMsg,                                // instantiate msg
    new Coins(),                                   // init funds
  )
```

* `MsgExecuteContract()`: execute wasm contract functions

```typescript theme={null}
const jsonEncodedMsg = Buffer.from(
      JSON.stringify({
        prepare_point: {
          stage: 1,
        },
      })
    ).toString('base64')

const msg = new MsgExecuteContract(
    'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu',                     // sender address
    'init1jue5rlc9dkurt3etr57duutqu7prchqrk2mes2227m52kkrual3qdrydg6', // contract address
    jsonEncodedMsg,                                                    // json encoded input msg
    new Coins()                                                        // coins transferred to the contract on execution
  ),
```

#### EVM

* `MsgCreate()`: create EVM contract code

```typescript theme={null}
const contractInfo = JSON.parse(
  fs
    .readFileSync(
      '../solidity/evm-example/artifacts/contracts/example.sol/example.json' // path of build response
    )
    .toString()
);

const msg = new MsgCreate(
    'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // sender address
    contractInfo.bytecode.slice(2)                 // hex encoded raw contract bytes code
),
```

* `MsgCall()`: execute EVM contract functions

```typescript theme={null}
const contractAddress = '0x1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu'
const contractInfo = JSON.parse(
  fs
    .readFileSync(
      '../solidity/evm-example/artifacts/contracts/example.sol/example.json' // path of build response
    )
    .toString()
);
const contract = new ethers.Contract(contractAddress, contractInfo.abi)

const msg = new MsgCall(
    'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu',                      // sender address
    contractAddress,                                                    // contract address
    contract.interface.encodeFunctionData('preparePoint', [2]).slice(2) // hex encoded execution input bytes
  )
```
