How can I track private function or contructor without event in subgraph?

Hi, I wrote and deployed the subgraph to hosted service for tracking all events of erc721 & 1155 on the network.
Here, each nft item needs to save its image url in the subgraph.
But _setUri function is a private function on erc1155 and it is only called in constructor and furhtermore, it doesn’t have any event on it.
So I can’t catch up on its event.
How can I track this function for saving nft’s image url in the subgraph for erc721 & 1155 without tracking event? is this available?
I hope your appreciate advices.

2 Likes

Hi Rick,
We support callHandlers & BlockHandlers as well. CallHandlers will trigger on a function call, but the issue here is that the function is private. A subgraph can’t track private functions.

2 Likes

thanks for reaching out. yeah, that’s it. I tried to use the callHandlers but the function was private so I couldn’t use it.
Any solutions for tracking constructor in the graph?

2 Likes

We don’t support triggering on the constructor yet.

2 Likes

hi @Rick you should be able to call the contract state when a token is minted, e.g. to call uri(tokenId) (docs) - note that if the base URI will be the same for all nfts, you could choose to only call this for the first token minted to speed up indexing

2 Likes

thanks. @adamfuller
I can see the way to get the symbol (state) of erc20 contract.
if so, can I get public view function same way in erc721?

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
        _requireOwned(tokenId);

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
    }

this is a public view function to get tokenUri of erc721.

can I use like this?

  let contract = ERC721Contract.bind(event.address)
  let erc721TokenURI = contract.tokenURI(tokenId)

thanks

3 Likes

:+1: yes @Rick, assuming you have the ERC721 ABI accessible that should work

2 Likes