---
eip: 7786
label: ERC-7786
title: Cross-Chain Messaging Gateway
status: Final
type: Standards Track
category: ERC
created: 2024-10-14
requires: 7930
official: https://eips.ethereum.org/EIPS/eip-7786
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7786.md
canonical: https://eips.huatuo.xyz/ko/eip-7786/
lang: ko
tldr: 임의의 크로스체인 메시지를 보내고 받기 위한 단일 게이트웨이 인터페이스. 컨트랙트가 특정 벤더의 API에 묶이지 않고 (네이티브 또는 어댑터를 통해) 어떤 브리지로든 체인 간에 통신할 수 있게 한다.
tags: [cross-chain, bridges, messaging, interoperability]
---

# ERC-7786: Cross-Chain Messaging Gateway

> An interface for contracts to send and receive cross-chain messages containing arbitrary data.

**TL;DR:** 임의의 크로스체인 메시지를 보내고 받기 위한 단일 게이트웨이 인터페이스. 컨트랙트가 특정 벤더의 API에 묶이지 않고 (네이티브 또는 어댑터를 통해) 어떤 브리지로든 체인 간에 통신할 수 있게 한다.

## 어떤 문제를 해결하나요?

모든 브리지나 크로스체인 메시징 프로토콜은 저마다 고유한 인터페이스, 워크플로, 신뢰 모델을 가지고 있습니다. 한 프로토콜용으로 만든 컨트랙트는 다시 작성하지 않고는 다른 프로토콜로 바꿀 수 없고, 어떤 브리지에서든 동작하는 범용 "크로스체인 앱"을 쓸 수도 없습니다.

ERC-7786은 작은 공통 인터페이스를 정의합니다. 메시지를 보내는 **소스 게이트웨이**와 메시지를 받는 **수신자** 콜백입니다. 프로토콜이 직접 구현할 수도 있고, 누군가 기존 프로토콜을 감싸는 어댑터를 만들 수도 있습니다. 브리지별 기능은 선택적인 **속성(attributes)**으로 전달합니다. 주소에 체인에 독립적인 [ERC-7930](/eip-7930/) 형식을 쓰기 때문에 비 EVM 체인에서도 동작합니다.

## 어떻게 동작하나요?

**메시지**는 발신자, 수신자, 불투명한 `payload`, 선택적 네이티브 토큰 `value`, `attributes` 목록으로 이루어집니다. 발신자와 수신자는 ERC-7930 Interoperable Address(바이너리, CAIP-350 직렬화)이며 체인과 계정을 모두 인코딩합니다.

**보내기.** 소스 체인의 게이트웨이는 `IERC7786GatewaySource`를 구현합니다.

- `sendMessage(recipient, payload, attributes)`는 `MessageSent`를 emit하며 0이 아닌 `sendId`를 반환할 수 있습니다. 알 수 없는 속성에는 `UnsupportedAttribute`로 revert해야 하고, ETH가 첨부되었는데 게이트웨이가 value를 지원하지 않으면 revert해야 합니다.
- `supportsAttribute(bytes4)`는 어떤 기능이 있는지 호출자에게 알려줍니다. 각 속성은 `bytes4 key ++ value`이며, 키는 함수 셀렉터로 하는 것이 권장됩니다. 예를 들어 `minGasLimit(uint256)` → `0x39f87ba1`이며, 각 요소는 `abi.encodeWithSignature`로 만들 수 있습니다.
- 목적지 가스비 지불("후처리") 같은 추가 단계가 필요할 수 있지만, 그 방식은 범위 밖입니다.

**받기.** 목적지 쪽 프로토콜이 수신자의 `receiveMessage(receiveId, sender, payload)`를 호출하며, 수신자는 자신의 셀렉터(`0x2432ef26`)를 반환해야 합니다. 수신자는 **호출자가 신뢰하는 게이트웨이인지 반드시 확인해야 합니다**.

**필수 보장:** *안전성*(전송되고 확정된 경우에만, 그리고 한 번만 전달됨)과 *활성*(수수료가 지불되면 결국 전달됨). *적시성*과 분산된 신뢰는 권장 사항입니다.

## 샘플 코드

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IERC7786GatewaySource {
    function sendMessage(bytes calldata recipient, bytes calldata payload, bytes[] calldata attributes)
        external payable returns (bytes32 sendId);
}

interface IERC7786Recipient {
    function receiveMessage(bytes32 receiveId, bytes calldata sender, bytes calldata payload)
        external payable returns (bytes4);
}

contract PingPong is IERC7786Recipient {
    address public immutable gateway;
    constructor(address g) { gateway = g; }

    function ping(bytes calldata remote /* ERC-7930 address */) external payable {
        bytes[] memory attrs = new bytes[](0);
        IERC7786GatewaySource(gateway).sendMessage{value: msg.value}(remote, "ping", attrs);
    }

    function receiveMessage(bytes32, bytes calldata, bytes calldata payload)
        external payable returns (bytes4)
    {
        require(msg.sender == gateway, "untrusted gateway");
        // handle payload ...
        return IERC7786Recipient.receiveMessage.selector;
    }
}
```

## 알아둘 점

- 상태는 **Final**입니다.
- 수신자의 `msg.sender` 확인이 보안 모델 전부입니다. 받아들이는 모든 게이트웨이의 신뢰 가정을 그대로 물려받게 됩니다.
- 네이티브 `value`가 목적지 체인에서 어떻게 나타나는지는 정해져 있지 않습니다.
- 정규 ERC-7930 인코딩을 사용하세요. 사양은 정규가 아닌 인코딩은 전달이 조용히 실패할 수 있다고 경고합니다.
- 관련 작업: [ERC-5164](/eip-5164/)(이전의 크로스체인 실행 인터페이스), [ERC-7683](/eip-7683/)(크로스체인 인텐트), [ERC-7841](/eip-7841/)(메시지 포맷과 메일박스).


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-7786
