如何在.net core 2.2中使用Nethereum调用具有多个输入参数和多个输出参数的复杂函数

这些天你好,我正在使用.net core 2.2和nethereum库创建一个去中心化的Web api。 现在,我处于紧急状态,因为当我尝试通过nethereum调用具有多个输入和输出参数的智能合约的函数时,发生了以下错误。

  

处理请求时发生未处理的异常。

     

NotSupportedException:不支持System.Int32

     

Nethereum.ABI.Decoders.StringTypeDecoder.Decode(byte []编码,类型   类型)

我在Google上搜索了此内容,但发现的任何文章都无助于我解决此问题。因此,如果有人可以帮助我,我将非常感激。


这是我的智能合约功能

function test(string memory x,uint256 y,bool z) public view returns(string memory _x,uint256 _y,bool _z){
            return(x,y,z);
    }

这是我使用.net core调用函数的方法

[FunctionOutput]
    public class Test : IFunctionOutputDTO
    {
        [Parameter("string","_x",1)]
        private string X { get; set; }

        [Parameter("uint256","_y",2)]
        private bool Y { get; set; }

        [Parameter("bool","_z",3)]
        private bool Z { get; set; }


    [Function("test")]
    public class TestFunction : Functionmessage
    {
        [Parameter("string","x",1)]
        public string X { get; set; }
        [Parameter("uint256","y",2)]
        public string Y { get; set; }
        [Parameter("bool","z",3)]
        public bool Z { get; set; }
    }

在我的服务范围内,我致电合同

public async Task<Test> Test(TestBody body)
        {
            var dataset = new TestFunction
            {
                X = body.x,Y = body.y,Z = body.z
            };
            var testHandler = web3.Eth.getcontractQueryHandler<TestFunction>();
            var response = await testHandler.QueryDeserializingToObjectAsync<Test>(dataset,contractAddress);
            return response;
        }

在这里 body 只是带有

的请求正文映射类的对象
public string x; 
public BigInteger y; 
public bool z;
ly13644593292 回答:如何在.net core 2.2中使用Nethereum调用具有多个输入参数和多个输出参数的复杂函数

我不知道该库的工作方式或智能合约,但是仅查看您的参数和类型,您似乎在DTO上设置了错误的类型:

    [Parameter("uint256","_y",2)]
    private bool Y { get; set; }

这不是一个无符号的整数吗?

,

我还认为您可能在DTO和functionMessage上设置了错误的类型。 Uint256应该与BigInteger一起使用。

[FunctionOutput]
    public class Test : IFunctionOutputDTO
    {
        [Parameter("string","_x",1)]
        private string X { get; set; }

        [Parameter("uint256",2)]
        private BigInteger Y { get; set; }

        [Parameter("bool","_z",3)]
        private bool Z { get; set; }


    [Function("test")]
    public class TestFunction : FunctionMessage
    {
        [Parameter("string","x",1)]
        public string X { get; set; }
        [Parameter("uint256","y",2)]
        public BigInteger Y { get; set; }
        [Parameter("bool","z",3)]
        public bool Z { get; set; }
    }
本文链接:https://www.f2er.com/3138063.html

大家都在问