0

我使用 ganache truffle 套件作为本地区块链来测试我的智能合约。这是我的solidity函数,我可以添加一个二维字符串数组并用它填充一个映射(字符串=>字符串):

   function AddSignature(string[][] memory _signature) public{
         for ( uint i = 0 ; i < _signature.length; i++ ) {
           
           require(!_studentExists[_signature[i][0]]);
         signatures[_signature[i][0]] = _signature[i][1];
         _studentExists[_signature[i][0]]=true;
          }  
}

这是我的 program.cs 代码,我尝试通过 .net 与 AddSignature 函数进行通信:

 class Program
{
    static void Main(string[] args)
    {
        //The URL endpoint for the blockchain network.
         string url = "HTTP://127.0.0.1:7545";

        //The contract address.
        string address =
            "0x4373671d1fC2d795A7c066E27CAB732933343b15";

        //The ABI for the contract.
        string ABI =
        @"..."

       
         Web3 web3 =  new Web3(url);
        Contract CryptoD =  web3.Eth.GetContract(ABI, address);

        Console.WriteLine("Enter your address: ");

        string addressStudent = Console.ReadLine(); 
        Console.WriteLine("Enter your signature: ");

        string signature = Console.ReadLine(); ;

        string[,] duo = new string[, ]
        {
            { addressStudent, signature }
        };

        try
        {

            Task<string> mintFunction = CryptoD.GetFunction("AddSignature").
                SendTransactionAsync(from: "0xe801bF0abd0eC70d77a954AF901D4AF747c0CfF2BALANCE",duo);
            mintFunction.Wait();
            Console.WriteLine("signature added!");
        }
        catch (Exception e)
        {
            Console.WriteLine("Error: {0}", e.Message);
        }
    }


}
4

1 回答 1

0

我通过传递二维数组而不是一维数组作为参数解决了这个错误

于 2021-08-18T14:25:36.820 回答