---
eip: 8100
label: ERC-8100
title: Representable Contract State
status: Draft
type: Standards Track
category: ERC
created: 2025-12-01
requires: 155
official: https://eips.ethereum.org/EIPS/eip-8100
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-8100.md
canonical: https://eips.huatuo.xyz/zh/eip-8100/
lang: zh
tldr: 让合约发布一个 XML 模板，其属性绑定到合约的 view 函数，使链下渲染器能生成合约状态的规范化、固定区块的 XML 文档，面向金融工具和报告场景。
tags: [xml, state, finance, tooling, standard]
---

# ERC-8100: Representable Contract State

> Interface and XML binding schema for contracts that expose a canonical representation of their state.

**TL;DR:** 让合约发布一个 XML 模板，其属性绑定到合约的 view 函数，使链下渲染器能生成合约状态的规范化、固定区块的 XML 文档，面向金融工具和报告场景。

## 它解决什么问题？

智能合约可以管理金融产品（如衍生品或债券）的整个生命周期，甚至到合约实际上*就是*该产品的程度。但外部世界仍然需要一份描述它的文档：估值预言机需要结算所需的输入，代币化债券需要条款清单和监管报告，审计人员希望得到可复现的快照。

传统金融用 FpML 等基于 XML 的标准来处理这些需求，XML 文档就是事实来源（source of truth）。ERC-8100 把这一点反过来：**合约才是事实来源**，并提供一种标准方式，让通用工具把合约的当前状态渲染为 XML，而无需针对具体项目的适配器。

## 它如何运作

- **接口。** 合约实现 `IXMLRepresentableState.stateXmlTemplate()`，返回一个实际上恒定不变的 XML 字符串。
- **绑定。** 模板中的元素带有 `urn:evm:state:1.0` 命名空间（前缀 `evmstate`）下的属性。`evmstate:call="notional()(uint256)"` 告诉渲染器调用哪个 view 函数以及如何解码结果。`evmstate:format` 和 `evmstate:scale` 控制格式化（scale 为 2 时，`100000000` 变成 `1000000.00`），`evmstate:target` 则写入属性而不是元素文本。通过分号分隔的列表，一个元素可以有多个绑定；可选的数组 profile 可把数组（例如付款计划）展开为重复的行。
- **一致的快照。** 渲染器必须预先选定单个区块 `B`，并在该区块上执行每一次 `eth_call`，使文档反映同一个一致的状态。根元素会带上 `evmstate:chain-id`（[EIP-155](/eip-155/) 链 ID）、`evmstate:contract-address` 和 `evmstate:block-number`。
- **XML 完备（XML-complete）。** 如果合约的渲染结果涵盖了所有语义相关的可变状态，它就是 XML-complete。这是作者的承诺，而不是链上强制执行的。
- **可选扩展。** `stateVersion()` 用于低成本的变更检测和缓存，`stateHash()` 用于完整性检查，`statePartXmlTemplate(partId)` 用于局部视图（例如结算上下文）。事件可以通过 URI（例如 `evmstate://self/part/{partId}`）引用这类视图，而不是在日志中记录大块数据。

## 示例代码

一段模板片段，以及渲染器据此生成的结果：

```xml
<!-- returned by stateXmlTemplate() -->
<Swap xmlns="urn:example:instrument"
      xmlns:evmstate="urn:evm:state:1.0"
      evmstate:chain-id="" evmstate:contract-address="" evmstate:block-number="">
  <Notional evmstate:call="notional()(uint256)" evmstate:format="decimal" evmstate:scale="2"/>
  <Party evmstate:call="partyALEI()(string)" evmstate:target="id"/>
</Swap>

<!-- rendered at a fixed block (evmstate:* binding attributes may be stripped) -->
<Swap xmlns="urn:example:instrument" xmlns:evmstate="urn:evm:state:1.0"
      evmstate:chain-id="1337" evmstate:contract-address="0x..." evmstate:block-number="37356">
  <Notional>1000000.00</Notional>
  <Party id="LEI-of-Party-A"/>
</Swap>
```

Solidity 一侧：

```solidity
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.19;

interface IXMLRepresentableState {
    function stateXmlTemplate() external view returns (string memory);
}
```

## 需要注意

- **状态：Draft。** 绑定模式和 profile 仍可能改变。
- 只绑定确定性的 view。读取 `block.timestamp` 或调用其他合约的函数可能使渲染结果不稳定。
- 合约可能声称自己是 XML-complete，却遗漏了某些内容。请审查代码，并在提供时使用 `stateHash()` 检查渲染结果是否与链上状态一致。
- 正确性最终取决于链下渲染器；建议有独立的实现和测试。
- 大型模板意味着大量 `eth_call`，在公共 RPC 上可能很慢或受到速率限制。
- 可以与 [ERC-20](/eip-20/)、[ERC-721](/eip-721/)、[ERC-1155](/eip-1155/) 或任何其他标准一起实现。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-8100
