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.
ERC-5267 defines a mechanism for describing and retrieving the EIP-712 domain used by a smart contract, making typed-data signing integrations easier to implement.
This article translates, summarizes, and expands on the following specification.
More ERC explainers:
Overview
ERC-5267 complements EIP-712 by defining how contracts expose the fields and values describing their signing domain.
Applications can retrieve this information, construct the appropriate domain object and derive its domain separator using a common procedure. This supports reusable integrations for EIP-712 signatures.
For EIP-712, see the following article.
EIP-712: Hashing and signing typed structured data
Without a standardized discovery mechanism, applications must often obtain the domain definition from contract-specific documentation or implementation details.
Motivation
EIP-712 defines a signing scheme for structured messages. Its domain separator distinguishes the contexts in which signatures are intended to be used, helping prevent cross-domain signature replay and allowing wallets to present meaningful signing information to users.
Domain separation is not a defense against reentrancy, and it does not by itself prevent repeated use of a signature within the same domain. Applications must implement appropriate nonce, deadline, or other replay-protection mechanisms.
An EIP-712 domain is described by a data structure containing a subset of predefined fields and potentially additional fields introduced through extensions.
EIP-712 does not itself specify how a contract exposes the domain fields and their values. Consequently, applications have often needed custom integrations for individual contracts.
ERC-2612, which defines signed ERC-20 approvals, illustrates this problem. Even where signed approvals improve the user experience, discovering the correct domain can complicate generic integrations.
ERC-5267 provides an interface for retrieving the domain definition used by a contract to verify EIP-712 signatures.
For ERC-2612, see the following article.
ERC-2612: Authorizing ERC-20 allowances through signatures
Specification
A compatible contract exposes eip712Domain with the following ABI. All return positions must be present even when the corresponding optional domain fields are not used.
function eip712Domain() external view returns (
bytes1 fields,
string name,
string version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] extensions
);The returned information describes the domain separator used by the contract to verify EIP-712 signatures. It identifies both the fields included in the EIP712Domain structure and their corresponding values.
fields- A bitmap in which bit i is set exactly when the corresponding standard field is present, for i from 0 through 4.
- Bits are interpreted from least significant to most significant, corresponding to the order defined by EIP-712 and reflected in the function's return values.
name,version,chainId,verifyingContract, andsalt- The values of the corresponding standard domain fields when present according to the bitmap.
- Values for absent fields are unspecified and should not be included in the reconstructed domain.
- EIP-712 defines the semantics of these fields.
extensions- A list of EIP numbers identifying extensions that introduce additional domain fields.
- Each extension may define how its field values are obtained and when they are included.
- The standard fields bitmap does not determine whether extension fields are present.
The domain may change during the lifetime of a contract, although changes should be infrequent. When the chainId field is used, it should reflect the underlying chain's EIP-155 identifier.
A contract may emit the following event to indicate that its domain could have changed.
event EIP712DomainChanged();Applications should not assume that a previously retrieved domain remains valid indefinitely. An event can assist cache invalidation, but the event is optional.
Rationale
ERC-2612 defines a DOMAIN_SEPARATOR function returning a bytes32 value: the hash of the domain structure.
That hash alone does not provide enough information to construct an EIP-712 signing request. EIP-712 RPC methods operate on a domain object rather than merely accepting an opaque domain-separator hash.
This design allows wallets to inspect the domain and communicate relevant information to users. The hash cannot generally be reversed into the original domain fields.
ERC-5267 fills this information-discovery gap by exposing the domain's structure and values.
EIP-712 also allows future extensions to introduce new domain fields through the EIP process. ERC-5267 identifies such extensions using their EIP numbers so that clients can apply the relevant field-discovery rules.
Backward compatibility
ERC-5267 is an optional extension to EIP-712 and does not modify the signing format of existing contracts.
Upgradeable contracts that already use EIP-712 can add the discovery interface through an appropriate authorized upgrade.
Applications may also need to support immutable contracts that do not implement ERC-5267. For known contracts, a client can use a documented domain definition or attempt to reconstruct a common domain pattern from available information.
Where a domain-separator getter is available, a reconstructed domain can be checked against the returned hash. Merely guessing a domain without validating it can produce invalid or unintended signing requests.
Reference implementation
Solidity
pragma solidity 0.8.0;
contract EIP712VerifyingContract {
function eip712Domain() external view returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
) {
return (
hex"0d", // 01101
"Example",
"",
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
}The example includes name, chainId, and verifyingContract, corresponding to bitmap 01101, or hexadecimal 0d. The unused version and salt return positions do not become domain fields.
Assuming a chain ID of 1 and the illustrative contract address 0x0000000000000000000000000000000000000001, the resulting domain object would be:
{
name: "Example",
chainId: 1,
verifyingContract: "0x0000000000000000000000000000000000000001"
}The address is illustrative; it is not a claim that this sample contract is deployed at that address on Ethereum mainnet.
The resulting domain object can be supplied to a compatible typed-data signing implementation.
JavaScript
A client can construct the domain object using the results of eip712Domain.
/** Retrieves the EIP-712 domain of a contract using EIP-5267 without extensions. */
async function getDomain(contract) {
const { fields, name, version, chainId, verifyingContract, salt, extensions } =
await contract.eip712Domain();
if (extensions.length > 0) {
throw Error("Extensions not implemented");
}
return buildBasicDomain(fields, name, version, chainId, verifyingContract, salt);
}
const fieldNames = ['name', 'version', 'chainId', 'verifyingContract', 'salt'];
/** Builds a domain object without extensions based on the return values of `eip712Domain()`. */
function buildBasicDomain(fields, name, version, chainId, verifyingContract, salt) {
const domain = { name, version, chainId, verifyingContract, salt };
for (const [i, field] of fieldNames.entries()) {
if (!(fields & (1 << i))) {
delete domain[field];
}
}
return domain;
}The example rejects unsupported extensions and removes optional standard fields whose corresponding bits are not set.
Depending on the ABI library, fields may be returned as a hexadecimal string and chain IDs or extension numbers may be represented as big integers. Integrators should normalize these representations as appropriate.
Extensions
Suppose a hypothetical EIP-XYZ defines an additional bytes32 field named subdomain and a getter called getSubdomain.
/** Retrieves the EIP-712 domain of a contract using EIP-5267 with support for EIP-XYZ. */
async function getDomain(contract) {
const { fields, name, version, chainId, verifyingContract, salt, extensions } =
await contract.eip712Domain();
const domain = buildBasicDomain(fields, name, version, chainId, verifyingContract, salt);
for (const n of extensions) {
if (n === XYZ) {
domain.subdomain = await contract.getSubdomain();
} else {
throw Error(`EIP-${n} extension not implemented`);
}
}
return domain;
}The extended getDomain function works as follows:
- Call eip712Domain to retrieve the standard fields and extension identifiers.
- Construct the basic domain using buildBasicDomain, removing absent fields according to the bitmap.
- Iterate over the extension identifiers. For the supported hypothetical extension XYZ, retrieve subdomain and add it to the domain. Reject unsupported extensions.
- Return the reconstructed domain object.
Defining the extension field in the actual EIP712Domain type and encoding it according to the extension's rules is outside the scope of this example.
The code excerpts are reproduced unchanged from the original article. They have not been independently compiled or executed as part of this translation.
Security considerations
A contract may report a verifyingContract address different from its own address or a chainId different from the network on which it is being queried.
Before requesting a signature, applications should verify that the reported domain corresponds to the intended verification context.
There may be legitimate cases in which a different verifying contract or chain identifier is appropriate. Such differences require explicit validation against the application's protocol and trust assumptions rather than automatic acceptance or rejection.
Treat returned domain information as a contract-supplied claim. Validate it against the intended signing context, including the chain, verifier, message type, and application-specific authorization rules, before asking the user to sign.
Citation
Francisco Giordano (@frangio), "ERC-5267: Retrieval of EIP-712 domain," Ethereum Improvement Proposals, no. 5267, July 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5267.
Conclusion
ERC-5267 standardizes discovery of EIP-712 domain fields and values, allowing applications to reconstruct signing domains without relying entirely on contract-specific integrations.
Questions are welcome via Twitter @cardene777.
Other publications:


