How to call Nethereum Web3 slot0 function

46 views Asked by At

I'm quite new with web3 and Nethereum and I'm struggling to understand how to properly call smart contract funcion such as slot0, so far I have made, but it crashes within .CallAsync method code below:

var web3 = new Web3("https://mainnet.infura.io/v3/SECRET_KEY");
var abi = GetAbi("Abi.json");
var pool = web3.Eth.GetContract(abi, "0x4e68Ccd3E89f51C3074ca5072bbAC773960dFa36");
var slot1 = pool.GetFunction("slot0");
var slotFunc = await slot1.CallAsync<Slot0>();

[Function("slot0", "uint160")]
internal class Slot0 : FunctionMessage
{
    [Parameter("uint160", "sqrtPriceX96")]
    public BigInteger sqrtPriceX96 { get; set; }
}

Expected result to return(example from https://etherscan.io/address/0x4e68ccd3e89f51c3074ca5072bbac773960dfa36#readContract):

enter image description here

Exception I receive: System.NotSupportedException: 'Slot0 is not a supported decoding type for IntType'

Almost related topic: UniswapV3 incorrect price in slot0() sqrtPriceX96

1

There are 1 answers

0
speed258 On

Found the problem instead of using:

[Function("slot0", "uint160")]
internal class Slot0 : FunctionMessage
{
    [Parameter("uint160", "sqrtPriceX96")]
    public BigInteger sqrtPriceX96 { get; set; }
}

Change to:

[FunctionOutput]
internal class Slot0 : FunctionMessage
{
    [Parameter("uint160", "sqrtPriceX96")]
    public BigInteger sqrtPriceX96 { get; set; }
}