# CCIP v1.5.1 CCIPReceiver API Reference
Source: https://docs.chain.link/ccip/api-reference/evm/v1.5.1/ccip-receiver

> For the complete documentation index, see [llms.txt](/llms.txt).

<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>

## CCIPReceiver

An abstract base contract that provides core functionality for CCIP-enabled applications to receive cross-chain messages.

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

> \*\*NOTE\*\*
>
>
>
> Base contract for CCIP applications that can receive messages, providing:
>
> - Secure message reception through router validation
> - Interface detection support (ERC165)
> - Customizable message handling through virtual functions

## Errors

### InvalidRouter

```solidity
error InvalidRouter(address router);
```

> \*\*NOTE\*\*
>
>
>
> Thrown when:
>
> - A zero address is provided during contract initialization
> - A function restricted to the router is called by an unauthorized address

**Parameters**

| Name     | Type      | Description                |
| -------- | --------- | -------------------------- |
| `router` | `address` | The invalid router address |

## State Variables

### i\_ccipRouter

```solidity
address internal immutable i_ccipRouter;
```

> \*\*NOTE\*\*
>
>
>
> The immutable address of the CCIP router contract that is authorized to deliver messages to this receiver.

## Modifiers

### onlyRouter

```solidity
modifier onlyRouter();
```

> \*\*NOTE\*\*
>
>
>
> Ensures that only the designated CCIP router can call the modified function. Reverts with `InvalidRouter` if called by
> any other address.

## Functions

### ccipReceive

Processes incoming CCIP messages from the router.

```solidity
function ccipReceive(Client.Any2EVMMessage calldata message) external virtual override onlyRouter;
```

> \*\*NOTE\*\*
>
>
>
> Called by the Router to deliver a message with the following characteristics:
>
> - Only accepts calls from the authorized router
> - If this function reverts, any associated token transfers also revert
> - Failed messages enter a FAILED state and become available for manual execution

**Parameters**

| Name      | Type                                                                            | Description      |
| --------- | ------------------------------------------------------------------------------- | ---------------- |
| `message` | [`Client.Any2EVMMessage`](/ccip/api-reference/evm/v1.5.1/client#any2evmmessage) | The CCIP message |

### constructor

```solidity
constructor(address router);
```

> \*\*NOTE\*\*
>
>
>
> Initializes the CCIPReceiver contract with a router address:
>
> - Validates that the router address is not zero
> - Stores the router address immutably

**Parameters**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `router` | `address` | The CCIP router contract address |

### getRouter

Returns the address of the current CCIP router.

```solidity
function getRouter() public view virtual returns (address);
```

<Aside>Provides access to the immutable router address used for message validation.</Aside>

**Returns**

| Type      | Description                     |
| --------- | ------------------------------- |
| `address` | The current CCIP router address |

### supportsInterface

Determines whether the contract implements specific interfaces.

```solidity
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool);
```

> \*\*NOTE\*\*
>
>
>
> Implements ERC165 interface detection with CCIP-specific behavior:
>
> - Returns true for IAny2EVMMessageReceiver and IERC165 interfaces
> - Used by CCIP to check if ccipReceive is available
> - If returns false or reverts: only tokens are transferred
> - If returns true: tokens are transferred and ccipReceive is called atomically
> - If contract has no code (EXTCODESIZE = 0): only tokens are transferred

**Parameters**

| Name          | Type     | Description                       |
| ------------- | -------- | --------------------------------- |
| `interfaceId` | `bytes4` | The interface identifier to check |

**Returns**

| Type   | Description                        |
| ------ | ---------------------------------- |
| `bool` | True if the interface is supported |

### \_ccipReceive

Internal function to be implemented by derived contracts for custom message handling.

```solidity
function _ccipReceive(Client.Any2EVMMessage memory message) internal virtual;
```

> \*\*NOTE\*\*
>
>
>
> Virtual function that must be overridden in implementing contracts to define custom message handling logic.

**Parameters**

| Name      | Type                                                                            | Description                 |
| --------- | ------------------------------------------------------------------------------- | --------------------------- |
| `message` | [`Client.Any2EVMMessage`](/ccip/api-reference/evm/v1.5.1/client#any2evmmessage) | The message to be processed |