0

スマート コントラクトとやり取りしたい Nethereum を使用して .net から CryptoD.sol スマート コントラクトを作成しました


pragma solidity  ^0.8.0;



contract CryptoD {
    mapping(string => string) public signatures;
    mapping(string =>bool) _studentExists;


   function AddSignature(string[2][] memory _signature) public{
             for ( uint i = 0 ; i < _signature.length; i++ ) {
               
               require(!_studentExists[_signature[i][0]],"this provided address already exists !");
             signatures[_signature[i][0]] = _signature[i][1];
             _studentExists[_signature[i][0]]=true;
                 revert("Signature Added");
              }  
    }

  function SignatureOf(string memory owner) public view returns (string memory) {
             return signatures[owner];
             revert("here goes the OWNER");
    }


}


次に、スマート コントラクトの vs コードを生成しました。ご覧のとおり、追加する関数と表示する関数の 2 つがあります。


   static async Task program()
        {
            
            try
            {
                //list of signatures and adresses
                var list = new List<List<string>>
                {
                    new() {"0x71be63f3384f5fb35995893a86b02fb2426c5788","vsv"},
                    new() {"0x2546bcd3c84621e976d8183a915322ae77ecec30","2vsv"}
                };


                // Setup
                // Here we're using local chain eg Geth https://github.com/Nethereum/TestChains#geth
                var url = "http://127.0.0.1:8545/";
                var privateKey = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
                var account = new Account(privateKey,31337);
                var web3 = new Web3(account, url);
                
                Console.WriteLine("Deploying...");
                var deployment = new CryptoDDeployment();
                var receipt = await CryptoDService.DeployContractAndWaitForReceiptAsync(web3, deployment);
                var service = new CryptoDService(web3, receipt.ContractAddress);
                Console.WriteLine($"Contract Deployment Tx Status: {receipt.Status.Value}");
                Console.WriteLine($"Contract Address: {service.ContractHandler.ContractAddress}");
                Console.WriteLine("");
             
                Console.WriteLine("Sending a transaction to the function set()...");
                
                var receiptForSetFunctionCall = await service.AddSignatureRequestAndWaitForReceiptAsync(
                    new AddSignatureFunction() 
                        { Signature = list, Gas = 400000}
                    );
                Console.WriteLine($"Finished storing an int: Tx Hash: {receiptForSetFunctionCall.TransactionHash}");
                Console.WriteLine($"Finished storing an int: Tx Status: {receiptForSetFunctionCall.Status.Value}");
                Console.WriteLine($"Finished storing an int: Tx Status: {receiptForSetFunctionCall.LogsBloom}");
                Console.WriteLine($"Finished storing an int: Tx Status: {receiptForSetFunctionCall.Logs}");
                Console.WriteLine("");

                Console.WriteLine("Calling the function get()...");
                var signatureValueFromGetFunctionCall = await service.SignatureOfQueryAsync("0x71be63f3384f5fb35995893a86b02fb2426c5788");
                Console.WriteLine($"Int value: {signatureValueFromGetFunctionCall} ");
                Console.WriteLine("");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("Finished");
            Console.ReadLine();
        }

ログ出力として Deploying... Contract Deployment Tx Status: 1 Contract Address: 0x5fbdb2315678afecb367f032d93f642f64180aa3

関数 set() にトランザクションを送信しています... Nethereum.JsonRpc.Client.RpcResponseException: エラー: トランザクションが理由文字列なしで取り消されました: eth_sendRawTransaction at Nethereum.JsonRpc.Client.ClientBase.HandleRpcError(RpcResponseMessage response, String reqMsg) at Nethereum. JsonRpc.Client.ClientBase.SendInnerRequestAsync[T](RpcRequestMessage reqMsg、文字列ルート) Nethereum.JsonRpc.Client.ClientBase.SendRequestAsync[T](RpcRequest リクエスト、文字列ルート) Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignAndSendTransactionAsync(TransactionInput トランザクション) ) Nethereum.Contracts.TransactionHandlers.TransactionSenderHandler で1.SendTransactionAsync(String contractAddress, TFunctionMessage functionMessage) at Nethereum.Contracts.TransactionHandlers.TransactionReceiptPollHandler1.C:\Users\jamid\source\repos\CryptoDiplomaWorkflow1.1\SimpleStorage\Program.cs:line 51 の SimpleStorage.Program.program() で、SendTransactionAsync(String contractAddress, TFunctionMessage functionMessage, Cancellation TokenSource cancelTokenSource)

前もって感謝します 。

4

0 に答える 0