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-5247, a proposal for a standard interface for creating and executing executable proposals.
The explanation below translates, summarizes, and expands on the original proposal.
ERC-5247 was at the Review stage as of October 5, 2023.
Overview
This Ethereum Improvement Proposal defines a way to create and execute proposals involving smart contracts on a blockchain. Smart contracts are programs executed on-chain when invoked. An executable proposal can specify the following information.
-
Target contract address
- Identifies the smart contract against which a proposed action will be executed.
- Specifies the destination of the call.
-
Amount of ether to transfer
- Specifies the amount of ether associated with the proposed call.
- For example, a call may transfer ether when purchasing tokens through a smart contract.
-
Gas limit
- Specifies a limit on the gas available for executing a proposed call.
- Gas measures the computational resources required for execution.
- A gas limit bounds the resources that execution can consume, including when code enters an infinite loop.
-
Calldata
- Contains the data required to invoke the function associated with the proposal.
- Smart contract functions accept inputs and execute according to their code.
- Calldata identifies the requested function and its arguments.
The interface allows applications to describe and prepare specific on-chain actions before executing them. This is useful in decentralized applications and smart contract systems that separate decision-making from execution.
Motivation
The central idea is that defining executable actions and executing them may need to occur at different times or under different conditions. Examples include the following scenarios.
-
Decentralized autonomous organizations (DAOs)
- A participant creates and submits an executable proposal.
- Members decide whether to support it and vote accordingly (see ERC-1202).
- If the required agreement is reached, the proposal can be executed.
-
Trusted delegates
- A person works with a trusted delegate, trustee, or legal representative to create an executable proposal.
- The proposal is discussed, approved through an appropriate mechanism, and ultimately executed.
-
Offers that require acceptance
- One party can make a conditional offer to another.
- The recipient reviews the executable proposal and may accept it, allowing the specified action to be executed.
Consider two friends, Alice and Bob. Alice wants to offer Bob a payment if he fulfills a particular condition.
-
Creating the proposal
- Alice uses a smart contract to create a proposal for Bob.
- The proposal includes the following conditions:
- Condition 1
- Bob completes a specified task, such as maintaining a garden.
- Condition 2
- Bob is entitled to receive the amount of ether specified in the proposal.
- Condition 1
-
Presenting the proposal
- Alice presents the proposal to Bob.
- Bob can inspect it through the smart contract.
- It describes the required work and the intended payment.
-
Accepting the proposal
- Bob reviews the proposed terms.
- He decides to accept the gardening task.
- Bob records his acceptance through the smart contract.
- If the implementation provides appropriate funding and enforcement, the agreed payment becomes payable under those conditions.
-
Executing the proposal
- After Bob accepts and fulfills the conditions, the payment can be executed through the smart contract.
- An appropriate external verification or approval mechanism is needed to establish that the gardening task has been completed. Once that condition is satisfied, the contract can transfer the agreed amount to Bob.
Executable proposals can thus support conditional agreements on-chain. Recipients can review the conditions before accepting them, and execution can be performed once those conditions are satisfied. ERC-5247 itself does not prescribe the verification, funding, or acceptance mechanism.
The proposal separates the process of defining executable actions from the process of executing them. This provides a common way to connect proposals and execution across different scenarios, including decentralized decision-making.
Specification
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
interface IERC5247 {
event ProposalCreated(
address indexed proposer,
uint256 indexed proposalId,
address[] targets,
uint256[] values,
uint256[] gasLimits,
bytes[] calldatas,
bytes extraParams
);
event ProposalExecuted(
address indexed executor,
uint256 indexed proposalId,
bytes extraParams
);
function createProposal(
uint256 proposalId,
address[] calldata targets,
uint256[] calldata values,
uint256[] calldata gasLimits,
bytes[] calldata calldatas,
bytes calldata extraParams
) external returns (uint256 registeredProposalId);
function executeProposal(uint256 proposalId, bytes calldata extraParams) external;
}Rationale
The interface was initially part of ERC-1202, a standard for managing on-chain voting on proposals.
The authors subsequently recognized that executable proposals could be useful beyond voting. Applications might need proposals without being constrained to a particular approval mechanism. The proposal interface was therefore separated from the voting interface.
Two major changes accompanied this decision.
-
Using arrays
- Previously, information such as the target, value, and calldata associated with a proposal was represented by individual variables.
- Representing these as arrays allows a proposal to contain multiple operations.
- A single proposal can therefore describe several actions.
-
Customizable proposal identifiers
- A new return value,
registeredProposalId, was introduced. - Returned by
createProposal, it allows implementations to use their own proposal registration and identification schemes. - Projects can maintain unique registered identifiers while supporting project-specific identifier formats.
- A new return value,
Separating proposal creation from voting preserves their relationship where needed while allowing executable proposals to be used for other purposes. This makes proposal management more adaptable to different projects and use cases.
Tests
it("Should work for a simple case", async function () {
const { contract, erc721, owner } = await loadFixture(deployFixture);
const callData1 = erc721.interface.encodeFunctionData("mint", [owner.address, 1]);
const callData2 = erc721.interface.encodeFunctionData("mint", [owner.address, 2]);
await contract.connect(owner)
.createProposal(
0,
[erc721.address, erc721.address],
[0,0],
[0,0],
[callData1, callData2],
[]);
expect(await erc721.balanceOf(owner.address)).to.equal(0);
await contract.connect(owner).executeProposal(0, []);
expect(await erc721.balanceOf(owner.address)).to.equal(2);
});The complete test code is available here.
Source: https://eips.ethereum.org/EIPS/eip-5247
Reference implementation
function createProposal(
uint256 proposalId,
address[] calldata targets,
uint256[] calldata values,
uint256[] calldata gasLimits,
bytes[] calldata calldatas,
bytes calldata extraParams
) external returns (uint256 registeredProposalId) {
require(targets.length == values.length, "GeneralForwarder: targets and values length mismatch");
require(targets.length == gasLimits.length, "GeneralForwarder: targets and gasLimits length mismatch");
require(targets.length == calldatas.length, "GeneralForwarder: targets and calldatas length mismatch");
registeredProposalId = proposalCount;
proposalCount++;
proposals[registeredProposalId] = Proposal({
by: msg.sender,
proposalId: proposalId,
targets: targets,
values: values,
calldatas: calldatas,
gasLimits: gasLimits
});
emit ProposalCreated(msg.sender, proposalId, targets, values, gasLimits, calldatas, extraParams);
return registeredProposalId;
}
function executeProposal(uint256 proposalId, bytes calldata extraParams) external {
Proposal storage proposal = proposals[proposalId];
address[] memory targets = proposal.targets;
string memory errorMessage = "Governor: call reverted without message";
for (uint256 i = 0; i < targets.length; ++i) {
(bool success, bytes memory returndata) = proposal.targets[i].call{value: proposal.values[i]}(proposal.calldatas[i]);
Address.verifyCallResult(success, returndata, errorMessage);
}
emit ProposalExecuted(msg.sender, proposalId, extraParams);
}The complete reference example is available here.
Source: https://eips.ethereum.org/EIPS/eip-5247
proposals
mapping(uint256 => Proposal) public proposals;Overview A data structure for storing proposals on-chain.
Details
The smart contract needs a way to store proposals.
This mapping associates integer identifiers with individual Proposal structs, providing a registry through which proposals can be retrieved.
proposalCount
uint256 private proposalCount;Overview A variable that tracks the number of registered proposals. It is declared private, so the compiler does not generate a public getter for it.
Details The contract increments this counter whenever a proposal is added. This allows it to track the number of registrations and allocate unique sequential registered proposal identifiers.
createProposal
function createProposal(
uint256 proposalId,
address[] calldata targets,
uint256[] calldata values,
uint256[] calldata gasLimits,
bytes[] calldata calldatas,
bytes calldata extraParams
) external returns (uint256 registeredProposalId) {
require(targets.length == values.length, "GeneralForwarder: targets and values length mismatch");
require(targets.length == gasLimits.length, "GeneralForwarder: targets and gasLimits length mismatch");
require(targets.length == calldatas.length, "GeneralForwarder: targets and calldatas length mismatch");
registeredProposalId = proposalCount;
proposalCount++;
proposals[registeredProposalId] = Proposal({
by: msg.sender,
proposalId: proposalId,
targets: targets,
values: values,
calldatas: calldatas,
gasLimits: gasLimits
});
emit ProposalCreated(msg.sender, proposalId, targets, values, gasLimits, calldatas, extraParams);
return registeredProposalId;
}Overview Creates and registers a new proposal. The caller supplies the details of the proposed actions to the smart contract.
Details
- Creates and registers a new proposal.
- Receives a proposal identifier, target addresses, ether amounts, gas limits, calldata, and additional parameters.
- Checks that the operation arrays have matching lengths and allocates a registered identifier.
- Stores the proposal details in the
proposalsmapping. - Emits
ProposalCreatedto record proposal creation.
Arguments
proposalId- The proposal identifier supplied by the caller.
targets- An array of target addresses.
values- An array of ether amounts to transfer.
gasLimits- An array of gas limits.
calldatas- An array of calldata payloads.
extraParams- Additional parameters, if required.
Return value
registeredProposalId- The unique identifier allocated to the registered proposal.
executeProposal
function executeProposal(uint256 proposalId, bytes calldata extraParams) external {
Proposal storage proposal = proposals[proposalId];
address[] memory targets = proposal.targets;
string memory errorMessage = "Governor: call reverted without message";
for (uint256 i = 0; i < targets.length; ++i) {
(bool success, bytes memory returndata) = proposal.targets[i].call{value: proposal.values[i]}(proposal.calldatas[i]);
Address.verifyCallResult(success, returndata, errorMessage);
}
emit ProposalExecuted(msg.sender, proposalId, extraParams);
}Overview Executes the actions associated with a registered proposal.
Details
- Retrieves the proposal to execute.
- Uses the supplied identifier to locate its actions.
- Calls the specified targets with their associated ether values and calldata.
- If a call fails,
Address.verifyCallResultpropagates the failure. - Emits
ProposalExecutedafter successful execution.
The illustrative implementation does not apply the stored per-call gas limits and does not show approval checks or protection against repeated execution. These controls must be addressed separately in a production system.
Arguments
proposalId- The registered identifier of the proposal to execute in this example.
extraParams- Additional parameters, if required.
Return value
- None.
getProposal
function getProposal(uint256 proposalId) external view returns (Proposal memory) {
return proposals[proposalId];
}Overview Retrieves the details of a specified proposal.
Details
- Looks up the proposal using its registered identifier.
- The returned details include the proposer, supplied proposal identifier, targets, ether values, gas limits, and calldata.
Arguments
proposalId- The registered identifier of the proposal to retrieve.
Return value
Proposal- A struct containing the proposal details.
getProposalCount
function getProposalCount() external view returns (uint256) {
return proposalCount;
}Overview Returns the total number of registered proposals.
Details
- Retrieves the total registration count.
- Allows callers to determine how many proposals have been registered.
Return value
uint256- The total number of registered proposals.
Security considerations
The original proposal identifies this area as requiring further discussion.
Citation
Zainan Victor Zhou (@xinbenlv), "ERC-5247: Smart Contract Executable Proposal Interface [DRAFT]," Ethereum Improvement Proposals, no. 5247, July 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5247.
Conclusion
This article covered ERC-5247, a standard interface for creating and executing smart contract proposals.
If you have questions, feel free to reach out via Twitter DM.
I also publish on the following platforms.


