ERC-5489 · Final(확정) · ERC · 2022-08-16
ERC-5489: NFT Hyperlink Extension
각 NFT에 하이퍼링크 슬롯을 부여하는 ERC-721 확장. 소유자가 주소에 슬롯 관리 권한을 주고, 각 슬롯은 URI를 가리키며, 소유자는 언제든 취소할 수 있다.
어떤 문제를 해결하나요?
ERC-721 토큰에는 컬렉션 컨트랙트가 제어하는 tokenURI가 하나 있습니다. 토큰의 소유자가 추가 콘텐츠(프로젝트 링크, 광고, 동영상)를 붙이거나 다른 사람이 붙이도록 허용할 표준적인 방법은 없습니다.
ERC-5489는 NFT를 작은 광고판 같은 것으로 바꿉니다. 소유자는 다른 주소에 슬롯을 나눠 줍니다. 각 슬롯 보유자는 NFT에 URI를 게시하고, 앱은 그 링크를 표시할 수 있습니다. 슬롯을 승인하는 것은 온체인 동작이므로, 예를 들어 dApp은 자신에게 슬롯을 승인해 준 NFT 소유자에게 보상을 주고 슬롯이 취소되면 보상을 중단할 수 있습니다.
어떻게 동작하나요?
슬롯은 매니저의 주소를 키로 하는 토큰별 맵의 항목입니다.
| 함수 | 호출 가능한 사람 | 효과 |
|---|---|---|
authorizeSlotTo(tokenId, slotManagerAddr) |
토큰 소유자 | 해당 주소를 위한 슬롯 생성 |
revokeAuthorization(tokenId, slotManagerAddr) |
토큰 소유자 | 슬롯 하나 제거 |
revokeAllAuthorizations(tokenId) |
토큰 소유자 | 모든 슬롯 제거 |
setSlotUri(tokenId, newUri) |
승인된 매니저 | 호출자 자신의 슬롯 URI 설정 |
getSlotUri(tokenId, slotManagerAddr) |
누구나 | 슬롯의 URI 읽기 |
인덱서와 프런트엔드가 슬롯을 추적할 수 있도록 이벤트 SlotAuthorizationCreated, SlotAuthorizationRevoked, SlotUriUpdated를 emit해야 합니다. supportsInterface는 0x8f65987b에 대해 true를 반환합니다(ERC-165).
각 슬롯 URI는 선택 필드 세 개를 가진 JSON 문서를 가리켜야 합니다.
{
"icon": "ipfs://<cid>/logo.png",
"description": "Short text about the linked resource",
"target": "https://example.com/landing"
}
icon은 썸네일 이미지, description은 짧은 소개문, target은 사용자가 NFT의 링크를 클릭했을 때 여는 URI입니다.
샘플 코드
소유자가 슬롯을 승인하고, 매니저가 링크를 설정하고, 조회자가 이를 읽기(ethers v6):
import { Contract } from "ethers";
const abi = [
"function authorizeSlotTo(uint256 tokenId, address slotManagerAddr)",
"function setSlotUri(uint256 tokenId, string newUri)",
"function getSlotUri(uint256 tokenId, address slotManagerAddr) view returns (string)",
"function supportsInterface(bytes4) view returns (bool)",
];
const asOwner = new Contract(hnft, abi, ownerSigner);
if (!(await asOwner.supportsInterface("0x8f65987b"))) throw new Error("not ERC-5489");
await (await asOwner.authorizeSlotTo(1n, adManager)).wait();
const asManager = new Contract(hnft, abi, adManagerSigner);
await (await asManager.setSlotUri(1n, "ipfs://<cid>/slot.json")).wait();
const uri = await new Contract(hnft, abi, provider).getSlotUri(1n, adManager);
const meta = await (await fetch(toGatewayUrl(uri))).json(); // { icon, description, target }
알아둘 점
- 상태는 Final입니다.
- 슬롯 내용은 컬렉션이 아니라 슬롯 매니저가 제어합니다. 프런트엔드는
target링크를 신뢰할 수 없는 것으로 취급하고 피싱에 대비해야 합니다. - 스펙은 토큰을 전송한 뒤에도 슬롯이 유지되는지 밝히지 않습니다. 구현을 확인하세요(참조 코드는 ERC에서 링크되어 있습니다).
- 스펙은 토큰당 슬롯 수에 제한을 두지 않으므로
revokeAllAuthorizations가 비싸질 수 있습니다.