---
eip: 7580
label: ERC-7580
title: Advertisement Tracking Interface
status: Draft
type: Standards Track
category: ERC
created: 2023-12-13
official: https://eips.ethereum.org/EIPS/eip-7580
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7580.md
canonical: https://eips.huatuo.xyz/zh/eip-7580/
lang: zh
tldr: 一个草案接口，让 dapp 可以用事件标记用户操作的开始和结束，使链上广告或空投协议能够追踪它，并同时奖励用户和 dapp。
tags: [advertising, tracking, airdrop, interface]
---

# ERC-7580: Advertisement Tracking Interface

> Interfaces for advertisement clients tracking user actions and checking proportional rewards.

**TL;DR:** 一个草案接口，让 dapp 可以用事件标记用户操作的开始和结束，使链上广告或空投协议能够追踪它，并同时奖励用户和 dapp。

## 它解决什么问题？

项目常常想奖励那些在*另一个*项目的合约中完成某件事的用户："在 dapp B 上兑换，就能从项目 A 获得空投"。为了公平发放，A 需要一个可靠的信号，证明某个用户确实在 B 中执行了那个确切的操作，而 B 则希望因为导入流量而分到一部分奖励。

没有通用接口的话，每个活动都需要定制集成和临时的日志解析。ERC-7580 提出了一个最小的、共享的追踪钩子，使 dapp 可以加入广告协议，而这些协议也能以统一的方式归因操作。

## 它如何运作

该接口定义了两个函数和两个对应的事件：

- `onTrackStart(track_id, contract_address, function_hash)` 在被推广的操作开始之前调用，并触发 `onTrackStartRecorded`。
- `onTrackEnd(track_id, contract_address, function_hash)` 在操作结束之后调用，并触发 `onTrackEndRecorded`。

`track_id` 标识活动，`contract_address` 标识被追踪的合约，`function_hash` 是被追踪函数连同其参数的哈希。这一对事件在交易内部标记出一个"关注区域"。

规范设想的流程：

1. 项目从推广方收到一个种子 id。
2. 其合约在目标操作之前调用 `onTrackStart`。
3. 在操作之后调用 `onTrackEnd`。
4. 推广合约收集被记录的操作，并把奖励分发回用户和项目。

奖励逻辑被有意排除在标准之外，给广告协议留出创新空间。

## 示例代码

一个用追踪钩子包裹被推广函数的 dapp：

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

interface IERC7580 {
    event onTrackStartRecorded(uint256 track_id, address contract_address, bytes32 function_hash);
    event onTrackEndRecorded(uint256 track_id, address contract_address, bytes32 function_hash);
    function onTrackStart(uint256 track_id, address contract_address, bytes32 function_hash) external;
    function onTrackEnd(uint256 track_id, address contract_address, bytes32 function_hash) external;
}

contract PromotedDapp is IERC7580 {
    uint256 public immutable campaignId;

    constructor(uint256 id) { campaignId = id; }

    function onTrackStart(uint256 id, address c, bytes32 h) public {
        emit onTrackStartRecorded(id, c, h);
    }

    function onTrackEnd(uint256 id, address c, bytes32 h) public {
        emit onTrackEndRecorded(id, c, h);
    }

    function mint(uint256 amount) external {
        bytes32 h = keccak256(abi.encode(this.mint.selector, msg.sender, amount));
        onTrackStart(campaignId, address(this), h);
        // ... the promoted action ...
        onTrackEnd(campaignId, address(this), h);
    }
}
```

## 需要注意

- 状态为 **Draft**。接口可能会变化，规范中说以后可能会增加更多函数。
- 按照原文，规范中的接口在 `onTrackEnd` 上漏写了 `external`，并且仍在使用占位名称 `IERCXXX`；上面的示例加上了 `external` 以便能够编译。
- Security Considerations 一节仍然是 TODO。尤其是，没有任何机制阻止任何人调用这些公开的钩子或触发伪造的开始/结束事件，所以奖励协议必须自行决定信任哪些合约和调用者。
- `function_hash` 的计算方式没有被固定，因此追踪方和推广方必须就编码方式达成一致。


---

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