---
eip: 7589
label: ERC-7589
title: Semi-Fungible Token Roles
status: Draft
type: Standards Track
category: ERC
created: 2023-12-28
requires: 165, 1155
official: https://eips.ethereum.org/EIPS/eip-7589
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7589.md
canonical: https://eips.huatuo.xyz/ko/eip-7589/
lang: ko
tldr: ERC-1155 토큰의 사용권을 빌려주기 위한 표준 초안. 소유자가 잔액을 커밋(commit)한 뒤, 소유권을 이전하지 않고 그 위에 기한이 있고 선택적으로 취소 가능한 역할(role)을 다른 계정에 부여한다.
tags: [erc-1155, roles, rental, gaming, sft]
---

# ERC-7589: Semi-Fungible Token Roles

> Role Management for Semi-Fungible Tokens (SFTs). Enables accounts to share the utility of SFTs via expirable role assignments.

**TL;DR:** ERC-1155 토큰의 사용권을 빌려주기 위한 표준 초안. 소유자가 잔액을 커밋(commit)한 뒤, 소유권을 이전하지 않고 그 위에 기한이 있고 선택적으로 취소 가능한 역할(role)을 다른 계정에 부여한다.

## 어떤 문제를 해결하나요?

[ERC-1155](/eip-1155/)는 각 토큰을 누가 몇 개 소유하는지는 추적하지만, 누가 그것을 **사용**할 수 있는지는 정하지 않습니다. 게임과 앱은 토큰 자체를 넘기지 않고 게임 내 아이템을 대여하거나, 길드원이 패스를 쓰게 하거나, 일정 기간 권한을 위임하고 싶을 때가 많습니다.

ERC-7589는 NFT를 위한 [ERC-7432](/eip-7432/)와 취지가 비슷한, 세미 펑저블 토큰용 표준 역할 계층을 추가합니다. 각 역할 할당은 한 명의 피부여자에게 가며 자동으로 만료됩니다.

## 어떻게 동작하나요?

부여는 두 단계로 이루어집니다.

1. **토큰 커밋.** `commitTokens(grantor, tokenAddress, tokenId, amount)`가 특정 수량을 잠그고(역할 컨트랙트에 예치하거나 동결하는 방식) `commitmentId`를 반환합니다.
2. **역할 부여.** `grantRole(commitmentId, role, grantee, expirationDate, revocable, data)`가 해당 커밋먼트에 `bytes32` 역할을 할당합니다. 영구 역할에는 `type(uint64).max`를 권장합니다.

그 밖의 요소:

- `revokeRole`은 할당을 종료합니다. 피부여자는 언제든 포기할 수 있고, 부여자는 취소 가능(revocable)하거나 이미 만료된 경우에만 취소할 수 있습니다.
- `releaseTokens(commitmentId)`는 커밋한 토큰을 돌려주지만, 취소 불가능하고 만료되지 않은 역할이 남아 있는 동안에는 revert해야 합니다.
- `setRoleApprovalForAll(tokenAddress, operator, approved)`로 오퍼레이터(예: 대여 마켓플레이스)가 소유자를 대신해 커밋하고 부여할 수 있습니다. 이 승인은 ERC-1155 승인과 별개입니다.
- 조회 함수: `grantorOf`, `tokenAmountOf`, `roleExpirationDate`, `isRoleRevocable`, `roleData` 등.
- 역할 ID는 역할 이름과 인자의 `keccak256`, 예를 들어 `keccak256("Player(uint256)")`으로 하는 것을 권장합니다.
- 선택적 확장: `commitTokensAndGrantRole`(한 번의 트랜잭션)과 `roleBalanceOf`(어떤 역할에 대해 사용자에게 부여된 총량). ERC-1155 메타데이터 JSON을 위한 선택적 `roles` 섹션도 있습니다.
- 코어 인터페이스의 ERC-165 인터페이스 ID: `0xc4c8a71d`.

## 샘플 코드

아이템 5개를 7일간 대여하는 예제(ethers v6):

```ts
import { Contract, Wallet, JsonRpcProvider, id } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const owner = new Wallet(process.env.PRIVATE_KEY!, provider);
const roles = new Contract(rolesAddress, [
  "event TokensCommitted(address indexed _grantor, uint256 indexed _commitmentId, address indexed _tokenAddress, uint256 _tokenId, uint256 _tokenAmount)",
  "function commitTokens(address,address,uint256,uint256) returns (uint256)",
  "function grantRole(uint256,bytes32,address,uint64,bool,bytes)",
], owner);

const receipt = await (await roles.commitTokens(owner.address, itemAddress, 42n, 5n)).wait();
const commitmentId = roles.interface.parseLog(receipt!.logs.find(l => l.address === rolesAddress)!)!.args._commitmentId;

const expires = BigInt(Math.floor(Date.now() / 1000) + 7 * 24 * 3600);
await roles.grantRole(commitmentId, id("Player()"), renterAddress, expires, false, "0x");
```

## 알아둘 점

- **상태: Draft.**
- 역할을 존중하는 앱은 `roleExpirationDate`를 직접 확인해야 합니다. 만료는 토큰 컨트랙트가 강제하지 않습니다.
- 커밋은 잔액을 이전하거나 동결할 수 있으므로 `commitTokens`와 `releaseTokens`의 접근 제어는 보안상 매우 중요합니다. 사양은 재진입도 언급합니다.
- 취소 불가능한 역할은 만료될 때까지 부여자의 토큰을 잠급니다.
- 단일 NFT는 [ERC-7432](/eip-7432/)를, ERC-1155 대여에 대한 더 단순한 "user" 필드는 [ERC-5006](/eip-5006/)을 참고하세요.


---

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