Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article examines ERC-7654, a proposal for organizing contract operations around request methods and their associated data.
This article translates, summarizes, and expands on the following specification.
More EIP explainers:
Overview
The proposal defines a common communication interface between clients and contracts. POST, GET, and PUT requests correspond to creating, reading, and updating contract data. Implementations can customize request parameters and response values.
A client here is an application or other software interacting with a smart contract.
Motivation
Different smart contracts expose different functions, making it difficult for clients to interact with them through a consistent interface.
The proposal defines a shared request-method model so clients can discover and invoke operations according to common rules.
- POST
- Creates new data, such as registering a user or issuing a token.
- GET
- Reads existing data, such as retrieving user information or token details.
- PUT
- Updates existing data, such as changing user information or a token's status.
Associating each method with a specific operation helps organize access to data. For example, POST is intended for creation, whereas GET is intended for reading. The implementation must still enforce these semantics and the relevant permissions.
Common rules reduce the complexity of calling functions on different contracts and make their capabilities easier to understand. Standardized descriptions of request and response parameter types also make interactions more predictable.
Specification
The standard describes four request method types.
- GET — retrieve a record.
- POST — create a new record.
- PUT — update a record.
- OPTIONS — discover the supported request method types.
The intended interaction sequence is:
- Call the options discovery method to determine which request types the contract supports.
- Call
getMethodsto obtain the names of available methods. - Call
getMethodReqAndResto retrieve the request and response parameter types for a method. - Encode the request according to the reported types and invoke
get,post, orput, as appropriate. - Decode the returned bytes into the expected response values.
Interface
IRequestMethodTypes.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.8.0;
import "./Types.sol";
interface IRequestMethodTypes{
/**
* Requested method type.
* GET, POST, PUT, OPTIONS
*/
enum MethodTypes{
GET,
POST,
PUT,
OPTIONS
}
/**
* Response data event.
* @param _response is the response value of the post request or put request.
*/
event Response(bytes _response);
/**
* Get method names based on request method type.
* @param _methodTypes is the request method type.
* @return Method names.
*/
function getMethods(MethodTypes _methodTypes)external view returns (string[] memory);
/**
* Get the data types of request parameters and responses based on the requested method name.
* @param _methodName is the method name.
* @return Data types of request parameters and responses.
*/
function getMethodReqAndRes(string memory _methodName) external view returns(Types.Type[] memory ,Types.Type[] memory );
/**
* Request the contract to retrieve records.
* @param _methodName is the method name.
* @param _methodReq is the method type.
* @return The response to the get request.
*/
function get(string memory _methodName,bytes memory _methodReq)external view returns(bytes memory);
/**
* Request the contract to create a new record.
* @param _methodName is the method name.
* @param _methodReq is the method type.
* @return The response to the post request.
*/
function post(string memory _methodName,bytes memory _methodReq)external returns(bytes memory);
/**
* Request the contract to update a record.
* @param _methodName is the method name.
* @param _methodReq is the method type.
* @return The response to the put request.
*/
function put(string memory _methodName,bytes memory _methodReq)external returns(bytes memory);
/**
* Supported request method types.
* @return Method types.
*/
function options()external returns(MethodTypes[] memory);
}Library
The Types.sol library lists Solidity types used by IRequestMethodTypes.
Types.sol
// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.8.0;
library Types {
enum Type {
BOOL,
INT8,
INT16,
INT24,
INT32,
INT40,
INT48,
INT56,
INT64,
INT72,
INT80,
INT88,
INT96,
INT104,
INT112,
INT120,
INT128,
INT136,
INT144,
INT152,
INT160,
INT168,
INT176,
INT184,
INT192,
INT200,
INT208,
INT216,
INT224,
INT232,
INT240,
INT248,
INT256,
UINT8,
UINT16,
UINT24,
UINT32,
UINT40,
UINT48,
UINT56,
UINT64,
UINT72,
UINT80,
UINT88,
UINT96,
UINT104,
UINT112,
UINT120,
UINT128,
UINT136,
UINT144,
UINT152,
UINT160,
UINT168,
UINT176,
UINT184,
UINT192,
UINT200,
UINT208,
UINT216,
UINT224,
UINT232,
UINT240,
UINT248,
UINT256,
ADDRESS,
BYTES1,
BYTES2,
BYTES3,
BYTES4,
BYTES5,
BYTES6,
BYTES7,
BYTES8,
BYTES9,
BYTES10,
BYTES11,
BYTES12,
BYTES13,
BYTES14,
BYTES15,
BYTES16,
BYTES17,
BYTES18,
BYTES19,
BYTES20,
BYTES21,
BYTES22,
BYTES23,
BYTES24,
BYTES25,
BYTES26,
BYTES27,
BYTES28,
BYTES29,
BYTES30,
BYTES31,
BYTES32,
BYTES,
STRING,
INT8_ARRAY,
INT16_ARRAY,
INT24_ARRAY,
INT32_ARRAY,
INT40_ARRAY,
INT48_ARRAY,
INT56_ARRAY,
INT64_ARRAY,
INT72_ARRAY,
INT80_ARRAY,
INT88_ARRAY,
INT96_ARRAY,
INT104_ARRAY,
INT112_ARRAY,
INT120_ARRAY,
INT128_ARRAY,
INT136_ARRAY,
INT144_ARRAY,
INT152_ARRAY,
INT160_ARRAY,
INT168_ARRAY,
INT176_ARRAY,
INT184_ARRAY,
INT192_ARRAY,
INT200_ARRAY,
INT208_ARRAY,
INT216_ARRAY,
INT224_ARRAY,
INT232_ARRAY,
INT240_ARRAY,
INT248_ARRAY,
INT256_ARRAY,
UINT8_ARRAY,
UINT16_ARRAY,
UINT24_ARRAY,
UINT32_ARRAY,
UINT40_ARRAY,
UINT48_ARRAY,
UINT56_ARRAY,
UINT64_ARRAY,
UINT72_ARRAY,
UINT80_ARRAY,
UINT88_ARRAY,
UINT96_ARRAY,
UINT104_ARRAY,
UINT112_ARRAY,
UINT120_ARRAY,
UINT128_ARRAY,
UINT136_ARRAY,
UINT144_ARRAY,
UINT152_ARRAY,
UINT160_ARRAY,
UINT168_ARRAY,
UINT176_ARRAY,
UINT184_ARRAY,
UINT192_ARRAY,
UINT200_ARRAY,
UINT208_ARRAY,
UINT216_ARRAY,
UINT224_ARRAY,
UINT232_ARRAY,
UINT240_ARRAY,
UINT248_ARRAY,
UINT256_ARRAY,
ADDRESS_ARRAY,
BYTES1_ARRAY,
BYTES2_ARRAY,
BYTES3_ARRAY,
BYTES4_ARRAY,
BYTES5_ARRAY,
BYTES6_ARRAY,
BYTES7_ARRAY,
BYTES8_ARRAY,
BYTES9_ARRAY,
BYTES10_ARRAY,
BYTES11_ARRAY,
BYTES12_ARRAY,
BYTES13_ARRAY,
BYTES14_ARRAY,
BYTES15_ARRAY,
BYTES16_ARRAY,
BYTES17_ARRAY,
BYTES18_ARRAY,
BYTES19_ARRAY,
BYTES20_ARRAY,
BYTES21_ARRAY,
BYTES22_ARRAY,
BYTES23_ARRAY,
BYTES24_ARRAY,
BYTES25_ARRAY,
BYTES26_ARRAY,
BYTES27_ARRAY,
BYTES28_ARRAY,
BYTES29_ARRAY,
BYTES30_ARRAY,
BYTES31_ARRAY,
BYTES32_ARRAY,
BYTES_ARRAY,
STRING_ARRAY
}
}Additional explanation
Type of Request Method
The GET, POST, and PUT categories provide a predictable way for clients to operate on contracts. Implementations define these operations so callers can discover and process the information required for a request.
The proposal does not include a DELETE category. Instead of physically removing data from storage, an implementation can expose a PUT method that marks a record active or inactive. GET methods can then return only active records. This is a design choice rather than a universal claim that deleting data is always inefficient.
Request Method Parameter Type
Each request method type can expose multiple named operations with associated request and response types. The example configures these types in the constructor and retrieves them by method name through getMethodReqAndRes.
- Type definitions
- Parameter types are represented by an enumeration.
- Request processing
- Use
abi.decodewith the expected types to decode the supplied request bytes.
- Use
- Response processing
- Use
abi.encodeto encode returned values according to the response types.
- Use
Examples
- Configuring request parameter types
struct RequestParameter {
string paramName;
uint256 paramValue;
}- Decoding request parameters
function decodeRequest(bytes memory encodedRequest) public pure returns (RequestParameter memory) {
return abi.decode(encodedRequest, (RequestParameter));
}- Encoding a response
struct Response {
bool success;
string message;
}
function encodeResponse(Response memory response) public pure returns (bytes memory) {
return abi.encode(response);
}Reference implementation
// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.8.0;
import "./Types.sol";
import "./IRequestMethodTypes.sol";
contract RequestMethodTypes is IRequestMethodTypes{
//@dev define the data type of this component
struct Profiles{
string name;
uint256 age;
}
mapping (address=>Profiles) users;
//@dev Types contains all data types in solidity
mapping (string=>Types.Type[]) methodRequests;
mapping (string=>Types.Type[]) methodResponses;
mapping (MethodTypes=>string[]) methods;
constructor(){
Types.Type[] memory getReqArray = new Types.Type[](1);
getReqArray[0] = Types.Type.ADDRESS;
Types.Type[] memory dataTypeArray = new Types.Type[](2);
dataTypeArray[0] = Types.Type.STRING;
dataTypeArray[1] = Types.Type.UINT256;
Types.Type[] memory putReqArray = new Types.Type[](2);
putReqArray[0] = Types.Type.ADDRESS;
putReqArray[1] = Types.Type.STRING;
// @dev initialize get, post, put request parameter data types and response data types
setMethod("getUser",MethodTypes.GET,getReqArray,dataTypeArray);
setMethod("createUser",MethodTypes.POST,dataTypeArray,new Types.Type[](0));
setMethod("updateUserName",MethodTypes.PUT,putReqArray,new Types.Type[](0));
}
function setMethod(string memory _methodName,MethodTypes _methodType,Types.Type[] memory _methodReq,Types.Type[] memory _methodRes) private {
methods[_methodType].push(_methodName);
methodRequests[_methodName]=_methodReq;
methodResponses[_methodName]=_methodRes;
}
function getMethodReqAndRes(string memory _methodName)public view returns(Types.Type[] memory ,Types.Type[] memory ){
return(
methodRequests[_methodName],
methodResponses[_methodName]
);
}
function getMethods(MethodTypes _methodTypes)public view returns (string[] memory){
return methods[_methodTypes];
}
function get(string memory _methodName,bytes memory _methodReq)public view returns(bytes memory){
if(compareStrings(_methodName,"getUser")){
address user=abi.decode(_methodReq, (address));
bytes memory userData=abi.encode(users[user].name,users[user].age);
return userData;
}else{
return abi.encode("");
}
}
function post(string memory _methodName,bytes memory _methodReq)public returns(bytes memory){
if(compareStrings(_methodName,"createUser")){
(string memory name,uint256 age)=abi.decode(_methodReq, (string,uint256));
users[msg.sender]=Profiles(name,age);
}
return abi.encode("");
}
function put(string memory _methodName,bytes memory _methodReq)public returns(bytes memory){
if(compareStrings(_methodName,"updateUserName")){
(address userAddress,string memory name)=abi.decode(_methodReq, (address,string));
require(userAddress==msg.sender);
users[userAddress].name=name;
}
return abi.encode("");
}
function options()public pure returns(MethodTypes[] memory){
MethodTypes[] memory methodTypes=new MethodTypes[](4);
methodTypes[0]=MethodTypes.GET;
methodTypes[1]=MethodTypes.POST;
methodTypes[2]=MethodTypes.PUT;
methodTypes[3]=MethodTypes.OPTIONS;
return methodTypes;
}
//@dev compares two strings for equality
function compareStrings(string memory _a, string memory _b) private pure returns (bool) {
return keccak256(abi.encodePacked(_a)) == keccak256(abi.encodePacked(_b));
}
}Profiles
Stores a user's profile, with name (string) and age (uint256) fields.
users
Maps user addresses to their profile information.
// ユーザーアドレスと対応するプロフィール
mapping(address => Profiles) users;
// 例:
users[0x123...abc] = Profiles("Alice", 25);
users[0x456...def] = Profiles("Bob", 30);methodRequests
Stores the request parameter types associated with each method name.
// メソッド名と対応するリクエストパラメータのデータ型
mapping(string => Types.Type[]) methodRequests;
// 例:
methodRequests["getUser"] = [Types.Type.ADDRESS];
methodRequests["createUser"] = [Types.Type.STRING, Types.Type.UINT256];
methodRequests["updateUserName"] = [Types.Type.ADDRESS, Types.Type.STRING];methodResponses
Stores the response parameter types associated with each method name.
// メソッド名と対応するレスポンスパラメータのデータ型
mapping(string => Types.Type[]) methodResponses;
// 例:
methodResponses["getUser"] = [Types.Type.STRING, Types.Type.UINT256];
methodResponses["createUser"] = [];
methodResponses["updateUserName"] = [];methods
Stores lists of method names for each request type, including GET, POST, and PUT.
// メソッドタイプと対応するメソッド名のリスト
mapping(MethodTypes => string[]) methods;
// 例:
methods[MethodTypes.GET] = ["getUser"];
methods[MethodTypes.POST] = ["createUser"];
methods[MethodTypes.PUT] = ["updateUserName"];setMethod
Configures a method name, method type, request parameter types, and response parameter types.
getMethodReqAndRes
Returns the request and response types associated with a method name.
getMethods
Returns the method names for the specified request type.
get
Processes GET requests. For getUser, the example decodes a user address and returns the corresponding encoded profile.
post
Processes POST requests. For createUser, the example decodes the name and age and creates a new user record.
put
Processes PUT requests. For updateUserName, the example decodes a user address and a new name, then updates the record.
options
Returns the supported request types: GET, POST, PUT, and OPTIONS.
compareStrings
Compares two strings for equality.
Security
The proposal distinguishes safe request methods from methods that can modify data.
Here, safe refers to read-only request semantics, not a guarantee that the implementation has no security vulnerabilities.
- Safe methods
- GET
- OPTIONS
- Methods that can change state
- POST
- PUT
Implementations must enforce access control and validate encoded inputs for state-changing methods. A method category alone does not guarantee security.
Citation
Rickey (@HelloRickey), "ERC-7654: Request Method Types [DRAFT]," Ethereum Improvement Proposals, no. 7654, March 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7654.
Conclusion
ERC-7654 proposes a shared interface for discovering contract operations and their request and response types, using request methods as an organizing model.
If you have questions, feel free to contact me on Twitter.
I also publish material on the following platforms.



