ERC-725 · Draft · ERC · 2017-10-02
ERC-725: General data key/value store and execution
Two building blocks for smart contract accounts: ERC725X, a generic owner-only execute function, and ERC725Y, a bytes32-keyed data store for upgradable metadata.
What problem does it solve?
A smart contract can act as an account (it can hold assets and call other contracts) and it can carry information about itself (a profile, permissions, links). Before ERC-725, every project invented its own function names for both, so wallets and dapps could not treat these contracts in a uniform way.
ERC-725 defines two small, separable interfaces:
- ERC725X: "do something on my behalf". One function that can call, deploy or delegate.
- ERC725Y: "store anything about me". A key/value store whose keys are
bytes32and values are rawbytes.
Together they form a flexible contract account; separately, ERC725Y can add upgradable metadata to tokens, NFTs or any other contract.
How it works
Ownership. The contract has one owner (an EOA or another contract), following ERC-173 (owner(), transferOwnership()). Only the owner may execute or write data.
ERC725X (interface ID 0x7545acac):
operationType |
Action |
|---|---|
0 |
CALL |
1 |
CREATE |
2 |
CREATE2 (salt appended to data, see EIP-1014) |
3 |
STATICCALL |
4 |
DELEGATECALL (dangerous) |
execute(operationType, target, value, data) runs one operation and executeBatch(...) runs several. Events Executed and ContractCreated record what happened.
ERC725Y (interface ID 0x629aa694): getData(key), getDataBatch(keys), setData(key, value), setDataBatch(keys, values), plus a DataChanged event. Keys are usually a hash of a descriptive name, e.g. keccak256("MyStandardKey"), so different standards do not collide.
Both interfaces must be advertised with ERC-165.
Sample code
Using an ERC-725 contract (Solidity):
interface IERC725X {
function execute(uint256 operationType, address target, uint256 value, bytes calldata data)
external payable returns (bytes memory);
}
interface IERC725Y {
function getData(bytes32 dataKey) external view returns (bytes memory);
function setData(bytes32 dataKey, bytes calldata dataValue) external;
}
contract Owner {
function demo(address account, address token, address to) external {
// Send 100 token units from the account (operation 0 = CALL)
IERC725X(account).execute(
0, token, 0,
abi.encodeWithSignature("transfer(address,uint256)", to, 100)
);
// Attach a profile pointer to the account
bytes32 key = keccak256("ProfileURI");
IERC725Y(account).setData(key, bytes("ipfs://..."));
}
}
Reading data off chain (ethers v6):
import { Contract, keccak256, toUtf8Bytes, toUtf8String } from "ethers";
const acct = new Contract(addr, ["function getData(bytes32) view returns (bytes)"], provider);
const raw = await acct.getData(keccak256(toUtf8Bytes("ProfileURI")));
console.log(toUtf8String(raw));
Things to know
- This proposal is still a Draft. The interface has changed over the years: older versions used overloaded
getData(bytes32[])andexecute(...[]), which were renamed to the...Batchfunctions in 2023. Check which version a contract implements via its ERC-165 interface IDs. DELEGATECALL(operation4) runs foreign code in the account's own storage. It can overwrite the owner or data, or self-destruct the account. Only delegate to code you fully trust.- Generic execution means reentrancy and call-chain attacks need extra care.
- The full account profile built on ERC-725 is standardized outside the EIP process as
LSP0-ERC725Account, withLSP2defining typed data keys. - For the more widely used smart account path, see ERC-4337. For accounts owned by NFTs, see ERC-6551.