0

Just trying get count of uniswap NFT-s on 0x5794d36de0c21211a7906688981371132bd7c6f0 wallet

enter image description here

Step one: Get contract from adress 0xc36442b4a4522e871399cd717abdd847ab11fe88 (Contract address for uniswap NFT)

 var contract = new Web3().Eth.GetContract(abiERC721, "0xc36442b4a4522e871399cd717abdd847ab11fe88");

Step two: Ask this contract about balanceOf on wallet with number 0x5794d36de0c21211a7906688981371132bd7c6f0

var bal = contract.GetFunction("balanceOf").GetData("0x5794d36de0c21211a7906688981371132bd7c6f0");

ExpectationResult: 5 (we can see this on etherscan.io https://etherscan.io/token/0xc36442b4a4522e871399cd717abdd847ab11fe88?a=0x5794d36de0c21211a7906688981371132bd7c6f0#inventory)

My result: 0x70a082310000000000000000000000005794d36de0c21211a7906688981371132bd7c6f0

What am I doing wrong?

Full code

void GetCountOfTokensERC721()
    {
 string abiERC721 =
            "[{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}," +
            "{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[]," +
            "\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[" +
            "{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}" +
            "],\"name\":\"mint\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":" +
            "[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}," +
            "{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"safeTransferFrom\",\"outputs\":[]," +
            "\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\"" +
            ":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"}," +
            "{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_data\",\"type\":\"bytes\"}]," +
            "\"name\":\"safeTransferFrom\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":" +
            "[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\"," +
            "\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\"," +
            "\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":" +
            "\"transferFrom\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\"," +
            "\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":" +
            "\"address\",\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"}," +
            "{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}," +
            "{\"indexed\":true,\"internalType\":\"address\",\"name\":\"approved\",\"type\":\"address\"}," +
            "{\"indexed\":true,\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}]," +
            "\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":" +
            "[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}," +
            "{\"indexed\":true,\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}," +
            "{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"approved\",\"type\":\"bool\"}]," +
            "\"name\":\"ApprovalForAll\",\"type\":\"event\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}]," +
            "\"name\":\"balanceOf\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\"" +
            ":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}]," +
            "\"name\":\"getApproved\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":" +
            "\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"}," +
            "{\"internalType\":\"address\",\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":" +
            "[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":" +
            "[{\"internalType\":\"uint256\",\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}]," +
            "\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"internalType\":\"bytes4\",\"name\":\"interfaceId\",\"type\":\"bytes4\"}]," +
            "\"name\":\"supportsInterface\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]\r\n";


        var contract = new Web3().Eth.GetContract(abiERC721, "0xc36442b4a4522e871399cd717abdd847ab11fe88");
        
        var bal = contract.GetFunction("balanceOf").GetData("0x5794d36de0c21211a7906688981371132bd7c6f0");
        UnityEngine.Debug.LogError(bal);
    }

1 Answer 1

0

I was found alternative solution. This works fine and returns 5(real count)

    [Function("balanceOf", "uint256")]
    public class BalanceOfFunction : FunctionMessage
    {
        [Parameter("address", "_owner", 1)]
        public string Owner { get; set; }
    }




    public void QueryingForBalanceAtBlockNumberWorksAsExpected()
    {
        var web3 = new Nethereum.Web3.Web3("https://mainnet.infura.io/v3/7238211010344719ad14a89db874158c");

        string contractAddress = "0xc36442b4a4522e871399cd717abdd847ab11fe88";

        string accountAddress = "0x5794d36de0c21211a7906688981371132bd7c6f0";

        var balanceOfFunctionMessage = new BalanceOfFunction()
        {
            Owner = accountAddress,
        };

        var balanceHandler = web3.Eth.GetContractQueryHandler<BalanceOfFunction>();


       var k =  balanceHandler.QueryAsync<BigInteger>(contractAddress, balanceOfFunctionMessage);
        UnityEngine.Debug.LogError(k.Result);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.