CodingSpace

블록체인/클레이튼 - KIP17_tokenURI 함수에 비밀(?) 본문

블록체인

블록체인/클레이튼 - KIP17_tokenURI 함수에 비밀(?)

개발자_조이킴 2022. 7. 26. 21:41


What:

  • 기작성된 Solidity를 활용하여 NFT Minting 프로젝트를 수행중
  • 필자는 NFT tokenURI를 KlaytnScope에서 조회할 수 있는 기능을 확인 및 검토하고 있었음
  • Solidity 코드를 살펴봐도 NFT Mint 함수가 실행될 때 tokenURI를 설정하는 부분이 없었음
  • 다만 setRevealedURI 함수를 통해 revealedURI 변수에 URI 값을 할당해줄 수 있었음
  • 하지만 해당 URI가 특정 NFT와 mapping 되는 부분이 없어 매우 혼란스러웠음

그림#1. tokenURI가 없는 경우

 

그림#2. tokenURI가 있는 경우


Solved:

  • Klaytnscope API에서 tokenURI 함수를 실행시켜 tokenURI 값을 조회하는 것 같음!
  • 즉, tokenURI 형식만 맞추면 (tokenId가 입력되었을 때, 해당 tokenId와 매칭되는 URI를 반환하는 함수) 그림#2 처럼 Klaytnscope에서 tokenURI를 확인할 수 있는 것임!
// 문제의 Solidity 코드
function tokenURI(uint256 tokenId) public view returns (string memory) {
        require(
            _exists(tokenId),
            "KIP17Metadata: URI query for nonexistent token"
        );
        if (revealed == false) {
            string memory currentUnrevealedUri = _unrevealedURI();
            return
                bytes(currentUnrevealedUri).length > 0
                    ? string(
                        abi.encodePacked(
                            currentUnrevealedUri,
                            String.uint2str(tokenId),
                            ".json"
                        )
                    )
                    : "";
        }
        string memory currentRevealedURI = _revealedURI();
        return
            bytes(currentRevealedURI).length > 0
                ? string(
                    abi.encodePacked(
                        currentRevealedURI,
                        String.uint2str(tokenId),
                        ".json"
                    )
                )
                : "";
    }

References. 

클레이스코프 (Baobab)

https://baobab.scope.klaytn.com/

 

Klaytnscope

Klaytnscope allows you to find data by monitoring network health and statistics of Klaytn as well as profiling blocks and transactions on Klaytn.

baobab.scope.klaytn.com

 

체인의 정석 "ERC721) token URI에 대한 코드분석"

https://it-timehacker.tistory.com/230

 

ERC721) token URI에 대한 코드 분석

ERC721에서 token URI는 토큰아이디와 base URI의 조합으로 만들어 진다. IERC721Metadata.sol function tokenURI(uint256 tokenId) external view returns (string memory); ERC721.sol /** * @dev See {IERC721M..

it-timehacker.tistory.com


For Developer. 

  • 잘못되거나 부족한 부분이 있다면 언제든지 댓글 부탁드립니다 :)
Comments