# CCIP v1.5.1 Client Library API Reference
Source: https://docs.chain.link/ccip/api-reference/evm/v1.5.1/client


<Aside type="note" title="Integrate Chainlink CCIP v1.5.1 into your project">
  <Tabs sharedStore="ccip-v1-5-1-package" client:visible>
    <Fragment slot="tab.1">npm</Fragment>
    <Fragment slot="tab.2">yarn</Fragment>
    <Fragment slot="tab.3">foundry</Fragment>

    <Fragment slot="panel.1">
      If you use [NPM](https://www.npmjs.com/), install the [@chainlink/contracts-ccip NPM package](https://www.npmjs.com/package/@chainlink/contracts-ccip):

      ```shell
      npm install @chainlink/contracts-ccip@1.5.1-beta.0
      ```
    </Fragment>

    <Fragment slot="panel.2">
      If you use [Yarn](https://yarnpkg.com/), install the [@chainlink/contracts-ccip NPM package](https://www.npmjs.com/package/@chainlink/contracts-ccip):

      ```shell
      yarn add @chainlink/contracts-ccip@1.5.1-beta.0
      ```
    </Fragment>

    <Fragment slot="panel.3">
      If you use [Foundry](https://book.getfoundry.sh/), install the package:

      ```shell
      forge install smartcontractkit/ccip@5e7b2096586bc32c6e975fc13f4c411eb687f833
      ```
    </Fragment>
  </Tabs>
</Aside>

## Client

A library that provides core data structures and utilities for building and handling cross-chain messages in CCIP.

[Git Source](https://github.com/smartcontractkit/ccip/blob/0df0625eea603ba8572d5382d72979a7f2b12bfb/contracts/src/v0.8/ccip/libraries/Client.sol)

## Structs

### Any2EVMMessage

Structure representing a message received from any chain to an EVM chain.

```solidity
struct Any2EVMMessage {
  bytes32 messageId;
  uint64 sourceChainSelector;
  bytes sender;
  bytes data;
  EVMTokenAmount[] destTokenAmounts;
}
```

> \*\*NOTE\*\*
>
>
>
> Contains all necessary information about an incoming cross-chain message:
>
> - Message identification and source chain details
> - Sender information (can be decoded if from an EVM chain)
> - Custom message payload
> - Token transfer details in destination chain format

**Properties**

| Name                  | Type                                  | Description                                       |
| --------------------- | ------------------------------------- | ------------------------------------------------- |
| `messageId`           | `bytes32`                             | Message ID corresponding to ccipSend on source    |
| `sourceChainSelector` | `uint64`                              | Identifier of the source chain                    |
| `sender`              | `bytes`                               | Sender address (use abi.decode if from EVM chain) |
| `data`                | `bytes`                               | Custom payload from the original message          |
| `destTokenAmounts`    | [`EVMTokenAmount[]`](#evmtokenamount) | Token amounts in destination chain representation |

### EVM2AnyMessage

Structure for sending a message from an EVM chain to any supported chain.

```solidity
struct EVM2AnyMessage {
  bytes receiver;
  bytes data;
  EVMTokenAmount[] tokenAmounts;
  address feeToken;
  bytes extraArgs;
}
```

> \*\*NOTE\*\*
>
>
>
> Defines the format for outgoing cross-chain messages:
>
> - Default gas limit is 200k if extraArgs is empty
> - Fee token can be set to address(0) to use native tokens (msg.value)
> - Extra arguments should be encoded using \_argsToBytes([`EVMExtraArgsV2`](#evmextraargsv2))

**Properties**

| Name           | Type                                  | Description                                         |
| -------------- | ------------------------------------- | --------------------------------------------------- |
| `receiver`     | `bytes`                               | Encoded receiver address for destination EVM chains |
| `data`         | `bytes`                               | Custom payload to send                              |
| `tokenAmounts` | [`EVMTokenAmount[]`](#evmtokenamount) | Tokens and amounts to transfer                      |
| `feeToken`     | `address`                             | Token used for fees (address(0) for native tokens)  |
| `extraArgs`    | `bytes`                               | Additional arguments encoded with \_argsToBytes     |

### EVMExtraArgsV1

Structure for V1 extra arguments in cross-chain messages.

```solidity
struct EVMExtraArgsV1 {
  uint256 gasLimit;
}
```

<Aside>First version of extra arguments, supporting basic gas limit configuration.</Aside>

**Properties**

| Name       | Type      | Description                                  |
| ---------- | --------- | -------------------------------------------- |
| `gasLimit` | `uint256` | Gas limit for execution on destination chain |

### EVMExtraArgsV2

Structure for V2 extra arguments in cross-chain messages.

```solidity
struct EVMExtraArgsV2 {
  uint256 gasLimit;
  bool allowOutOfOrderExecution;
}
```

> \*\*NOTE\*\*
>
>
>
> Enhanced version of extra arguments adding execution order control:
>
> - Includes configurable gas limit
> - Allows specifying out-of-order execution preference
> - Default value for allowOutOfOrderExecution varies by chain
> - Some chains enforce specific values and will revert if not set correctly

**Properties**

| Name                       | Type      | Description                                   |
| -------------------------- | --------- | --------------------------------------------- |
| `gasLimit`                 | `uint256` | Gas limit for execution on destination chain  |
| `allowOutOfOrderExecution` | `bool`    | Whether messages can be executed in any order |

### EVMTokenAmount

Structure representing token amounts in CCIP messages.

```solidity
struct EVMTokenAmount {
  address token;
  uint256 amount;
}
```

> \*\*NOTE\*\*
>
>
>
> Core structure for token transfers used by the Risk Management Network (RMN):
>
> - Changes to this struct require RMN maintainer notification
> - Represents token amounts in their chain-specific format

**Properties**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `token`  | `address` | Token address on the local chain |
| `amount` | `uint256` | Amount of tokens to transfer     |

## State Variables

### EVM\_EXTRA\_ARGS\_V1\_TAG

```solidity
bytes4 public constant EVM_EXTRA_ARGS_V1_TAG = 0x97a657c9;
```

<Aside>The identifier tag for V1 extra arguments (bytes4(keccak256("CCIP EVMExtraArgsV1"))).</Aside>

### EVM\_EXTRA\_ARGS\_V2\_TAG

```solidity
bytes4 public constant EVM_EXTRA_ARGS_V2_TAG = 0x181dcf10;
```

<Aside>The identifier tag for V2 extra arguments (bytes4(keccak256("CCIP EVMExtraArgsV2"))).</Aside>

## Functions

### \_argsToBytes (V1)

Encodes EVMExtraArgsV1 into bytes for message transmission.

```solidity
function _argsToBytes(EVMExtraArgsV1 memory extraArgs) internal pure returns (bytes memory bts);
```

<Aside>Serializes V1 extra arguments with the V1 tag identifier for cross-chain message processing.</Aside>

**Parameters**

| Name        | Type                                | Description                      |
| ----------- | ----------------------------------- | -------------------------------- |
| `extraArgs` | [`EVMExtraArgsV1`](#evmextraargsv1) | The V1 extra arguments to encode |

**Returns**

| Type    | Description                          |
| ------- | ------------------------------------ |
| `bytes` | The encoded extra arguments with tag |

### \_argsToBytes (V2)

Encodes EVMExtraArgsV2 into bytes for message transmission.

```solidity
function _argsToBytes(EVMExtraArgsV2 memory extraArgs) internal pure returns (bytes memory bts);
```

<Aside>Serializes V2 extra arguments with the V2 tag identifier for cross-chain message processing.</Aside>

**Parameters**

| Name        | Type                                | Description                      |
| ----------- | ----------------------------------- | -------------------------------- |
| `extraArgs` | [`EVMExtraArgsV2`](#evmextraargsv2) | The V2 extra arguments to encode |

**Returns**

| Type    | Description                          |
| ------- | ------------------------------------ |
| `bytes` | The encoded extra arguments with tag |