1

I'm trying to retrieve the total supply of an ERC1155 SmartContract. This code was made by my friend and has been deployed. He took the code from OpenZeppelin with Burnable and Pausable presets.

The function totalSupply that I am trying to retrieve exists in the code. But, when I see the ABI, the totalSupply does not included.

(Sorry for small screenshot. Please see this screenshot in the new tab) enter image description here

MyErc1155Contract compiled

enter image description here

This is where to get the ABI

enter image description here

Full code is here: click_this_to_go_to_pastebin

Then I am trying to write smartcontract to retrieve the totalSupply;

pragma solidity ^0.8.0;

contract TotSup {

    uint256 public hasilBal;
    uint256 public hasil;

    function balanceOf(address erc1155_address, 
        address user_address, 
        uint256 nft_id) public {

        (bool successA, bytes memory resultA) = 
            erc1155_address.call(abi.encodeWithSignature(
                "balanceOf(address,uint256)", 
                user_address, 
                nft_id
        ));

        hasil = abi.decode(resultA, (uint256));

    }

    function bal(address erc1155_address, uint256 nft_id) public {
        (bool successA, bytes memory resultA) = 
            erc1155_address.call(
                abi.encodeWithSignature("totalSupply(uint256)", nft_id
        ));

        hasilBal = abi.decode(resultA, (uint256)); 
    }

}

I test my idea with writing another function balanceOf and it works perfectly. And for the totalSupply in function bal is fail.

Is it possible to retrieve or calling function which is not included in the ABI? If yes, how to achieve that? And last, why call balanceOf still need for paying gas for just retrieving the data?

user1034754
  • 71
  • 2
  • 8
  • After code inspection, I found ERC1155Supply which is contains `totalSupply` code not included anywhere in the code. So, this is the mistake. – user1034754 Oct 10 '22 at 05:20

1 Answers1

0

When a function exists in the code when you compile the code it reflects in the ABI, Without the function signature, you can't call the function.

As for your second answer, balanceOf in TotSup will cost you gas as it is not a view function.

Muhammad Hassan
  • 424
  • 3
  • 5
  • Hi, thanks for the answer. I edit my question and added more screenshot to strengthen my argument that the `totalSupply` not exists in the ABI. Do you have any idea how to call the `totalSupply`? – user1034754 Oct 09 '22 at 10:17