---
eip: 7654
label: ERC-7654
title: Request Method Types
status: Draft
type: Standards Track
category: ERC
created: 2024-03-13
official: https://eips.ethereum.org/EIPS/eip-7654
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7654.md
canonical: https://eips.huatuo.xyz/ko/eip-7654/
lang: ko
tldr: HTTP와 비슷한 GET, POST, PUT 진입점과 스스로를 설명하는 파라미터 타입으로 컨트랙트의 함수를 노출하는 초안 인터페이스. 클라이언트가 어떤 컨트랙트든 같은 방식으로 찾아 호출할 수 있게 한다.
tags: [interface, api, discovery, rest, draft]
---

# ERC-7654: Request Method Types

> Use a set of request methods to indicate the type of action to take on the contract.

**TL;DR:** HTTP와 비슷한 GET, POST, PUT 진입점과 스스로를 설명하는 파라미터 타입으로 컨트랙트의 함수를 노출하는 초안 인터페이스. 클라이언트가 어떤 컨트랙트든 같은 방식으로 찾아 호출할 수 있게 한다.

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

컨트랙트마다 함수 이름과 인자 목록이 제각각입니다. 클라이언트는 컨트랙트로 무언가를 하려면 미리 그 ABI를 알아야 하고, 컨트랙트에 "무엇을 할 수 있고 각 동작은 무엇을 필요로 하나요?"라고 물어볼 공통된 방법이 없습니다.

ERC-7654는 익숙한 웹의 요청 메서드 패턴을 빌려 옵니다. 컨트랙트는 임의의 함수 대신 고정된 진입점 집합(`get`, `post`, `put`)과 탐색(discovery) 함수를 노출합니다. 그러면 클라이언트는 사용 가능한 메서드를 나열하고, 설명과 파라미터 타입을 읽고, 범용적으로 호출할 수 있습니다.

## 어떻게 동작하나요?

메서드 유형은 네 가지입니다.

| 유형 | 의미 | 안전한가(읽기 전용)? |
| --- | --- | --- |
| `GET` | 레코드 읽기 | 예 |
| `POST` | 레코드 생성 | 아니요 |
| `PUT` | 레코드 갱신 | 아니요 |
| `OPTIONS` | 지원하는 메서드 유형 나열 | 예 |

`DELETE`는 일부러 없습니다. 온체인 데이터를 삭제하는 것은 비효율적이므로, 명세는 레코드를 무효로 표시하는 `PUT`과 이를 숨기는 `GET`을 제안합니다.

클라이언트 워크플로:

1. `options()`로 컨트랙트가 어떤 메서드 유형을 지원하는지 확인합니다.
2. `getMethods(type)`로 어떤 유형의 메서드 이름을 나열합니다.
3. `getMethodInstruction(name)`으로 사람이 읽을 수 있는 설명을 읽습니다.
4. `getMethodReqAndRes(name)`로 요청과 응답의 파라미터 타입을 가져옵니다(명세의 `Types` 라이브러리에 있는 Solidity 타입 enum).
5. 요청을 ABI 인코딩하고 메서드 이름과 함께 `get`, `post`, `put`을 호출합니다.
6. `bytes` 응답을 ABI 디코딩합니다. `post`와 `put`은 `Response(bytes)`도 emit합니다.

## 샘플 코드

인터페이스 발췌:

```solidity
// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.8.0;

interface IRequestMethodTypes {
    enum MethodTypes { GET, POST, PUT, OPTIONS }

    event Response(bytes _response);

    function getMethods(MethodTypes _methodTypes) external view returns (string[] memory);
    function getMethodInstruction(string memory _methodName) external view returns (string memory);
    function get(string memory _methodName, bytes memory _methodReq) external view returns (bytes memory);
    function post(string memory _methodName, bytes memory _methodReq) external payable returns (bytes memory);
    function put(string memory _methodName, bytes memory _methodReq) external payable returns (bytes memory);
    function options() external returns (MethodTypes[] memory);
}
```

가상의 `getUser` 메서드 호출하기(ethers v6):

```ts
import { AbiCoder, Contract } from "ethers";

const abi = AbiCoder.defaultAbiCoder();
const c = new Contract(addr, [
  "function getMethods(uint8) view returns (string[])",
  "function get(string,bytes) view returns (bytes)",
], provider);

console.log(await c.getMethods(0)); // GET methods, e.g. ["getUser"]
const raw = await c.get("getUser", abi.encode(["address"], [userAddress]));
const [name, score] = abi.decode(["string", "uint256"], raw);
```

## 알아둘 점

- 상태는 **Draft**이며 인터페이스는 아직 바뀔 수 있습니다.
- 메서드는 문자열 이름으로 분기되고 인자는 `bytes`에 담기므로, 일반적인 타입 있는 함수에 비해 gas가 더 들고 컴파일 시점의 타입 검사를 잃습니다.
- 표준 도구(익스플로러, 지갑, ERC-20/721 연동)는 일반적인 함수 셀렉터를 기대하므로, 이 패턴만 쓰는 컨트랙트는 그것들이 인식하지 못합니다.
- `post`와 `put`은 상태를 바꾸므로 자체 접근 제어가 있어야 합니다. 메서드 유형 라벨은 설명용이며 강제되지 않습니다.


---

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