ERC-7654 · Draft · ERC · 2024-03-13
ERC-7654: Request Method Types
A draft interface that exposes a contract's functions through HTTP-like GET, POST and PUT entry points with self-describing parameter types, so clients can discover and call any contract the same way.
What problem does it solve?
Every contract has its own function names and argument lists. A client must know a contract's ABI in advance to do anything with it, and there is no common way to ask a contract "what can you do and what does each action expect?".
ERC-7654 borrows the familiar web pattern of request methods. Instead of arbitrary functions, a contract exposes a fixed set of entry points (get, post, put) plus discovery functions. A client can then list the available methods, read their instructions and parameter types, and call them generically.
How it works
There are four method types:
| Type | Meaning | Safe (read-only)? |
|---|---|---|
GET |
read records | yes |
POST |
create a record | no |
PUT |
update a record | no |
OPTIONS |
list supported method types | yes |
There is deliberately no DELETE: deleting on-chain data is inefficient, so the spec suggests a PUT that marks records invalid and a GET that hides them.
The client workflow:
options()to see which method types the contract supports.getMethods(type)to list method names for a type.getMethodInstruction(name)to read a human-readable description.getMethodReqAndRes(name)to get the request and response parameter types (an enum of Solidity types from the spec'sTypeslibrary).- ABI-encode the request and call
get,postorputwith the method name. - ABI-decode the
bytesresponse.postandputalso emitResponse(bytes).
Sample code
Interface excerpt:
// 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);
}
Calling a hypothetical getUser method (ethers v6):
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);
Things to know
- Status is Draft; the interface may still change.
- Methods are dispatched by string name and arguments are packed into
bytes, which costs extra gas and loses compile-time type checking compared with ordinary typed functions. - Standard tools (explorers, wallets, ERC-20/721 integrations) expect normal function selectors, so a contract using only this pattern will not be recognised by them.
postandputchange state and must have their own access control; the method type labels are descriptive, not enforced.