我愿意使用 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 代码,如您所见,我有两个函数要添加,另一个要显示
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();
}
并且作为日志输出正在部署... 合同部署 Tx 状态:1 合同地址:0x5fbdb2315678afecb367f032d93f642f64180aa3
将事务发送到函数 set()... Nethereum.JsonRpc.Client.RpcResponseException:错误:事务在没有原因字符串的情况下恢复:在 Nethereum 的 Nethereum.JsonRpc.Client.ClientBase.HandleRpcError(RpcResponseMessage response, String reqMsg) 处的 eth_sendRawTransaction。 JsonRpc.Client.ClientBase.SendInnerRequestAsync[T](RpcRequestMessage reqMsg, String route) at Nethereum.JsonRpc.Client.ClientBase.SendRequestAsync[T](RpcRequest request, String route) at Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignAndSendTransactionAsync(TransactionInput transaction ) 在 Nethereum.Contracts.TransactionHandlers.TransactionSenderHandler1.SendTransactionAsync(String contractAddress, TFunctionMessage functionMessage) at Nethereum.Contracts.TransactionHandlers.TransactionReceiptPollHandler
1.C:\Users\jamid\source\repos\CryptoDiplomaWorkflow1.1\SimpleStorage\Program.cs:line 51 中 SimpleStorage.Program.program() 的 SendTransactionAsync(String contractAddress, TFunctionMessage functionMessage, Cancellation TokenSource cancelTokenSource)
先感谢您 。