1

I am writing a simple smart contract using Nethereum using this solidity code:

pragma solidity >=0.4.0 <0.7.0;

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

After using Nethereum.Autogen.ContractApi Nuget Package I autogenerate the service of it. I got the code from this link: https://medium.com/coinmonks/a-net-developers-workflow-for-creating-and-calling-ethereum-smart-contracts-44714f191db2

Piece of testing code that I use:

using BlockchainPoc.SimpleStorage_sol_SimpleStorage;
using BlockchainPoc.SimpleStorage_sol_SimpleStorage.ContractDefinition;
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Web3;
using Nethereum.Web3.Accounts;
using System;
using System.Threading.Tasks;

namespace BlockchainPoc
{
    class Program
    {
        async static Task Main(string[] args)
        {
            var url = "http://localhost:7545";
            var privateKey = "0x6352ebaeef4bfe298789ae7dceb62bd9bd2fdf47b7c4b9ec2997d271482953f9";
            var account = new Account(privateKey);
            var web3 = new Web3(account, url);

            Console.WriteLine("Deploying...");
            var deployment = new SimpleStorage_sol_SimpleStorageDeployment();
            var receipt = await SimpleStorage_sol_SimpleStorageService.DeployContractAndWaitForReceiptAsync(web3, deployment);
            var service = new SimpleStorage_sol_SimpleStorageService(web3, "0x8B0AB0dA433E2Eb05CEA17DB4Cd99E62b4a740DC");
            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.SetRequestAndWaitForReceiptAsync(
                new SetFunction() { X = 42, 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("");
            var latestBlockNumber = await web3.Eth.Blocks.GetBlockNumber.SendRequestAsync();
            Console.WriteLine("Latest block number", latestBlockNumber);
            Console.WriteLine("Calling the function get()...");

            var block = await web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(latestBlockNumber);

            var intValueFromGetFunctionCall = await service.GetQueryAsync(new BlockParameter(latestBlockNumber));
            Console.WriteLine($"Int value: {intValueFromGetFunctionCall} (expecting value 42)");
            Console.WriteLine("");
        }

    }
}

enter image description here Seems that I have the same issue like here Using jsonrpc to get eth data but the result is null, but I don't see the solution. In Ganache after the deployment of the contract and setting the value I see blocks created. Also if I try to decode TXData I see correct values: enter image description here

But in the end I am not able to see the result. Can you help me?

This is the json that is sent and returned with getting request.

enter image description here

And decoded data of the request: enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.