1

Been testing Nethereum and attempting to get a basic test class running as per the Nethereum documentation, but having trouble when running the mining command.

Issue

  1. Miner.Start was always bringing back "false" to begin with. Then I stumbled on to this question Nethereum 2.0.0-rc5 Miner which mentions that I should try using the pre-release where Web3Geth is the new way to call mining, trying both ways, I am still unable to get a true value to then continue with my test.

    var mineResult = await web3Geth.Miner.Start.SendRequestAsync(6);
    //var mineResult = await web3.Miner.Start.SendRequestAsync(6);
    

This is my XUnit test class where the issue is happening.

    using System.Threading;
    using System.Threading.Tasks;
    using Nethereum.Geth;
    using Nethereum.Hex.HexTypes;
    using Nethereum.Web3;
    using Xunit;

namespace BasicTurorial
{
    public class TestClass
    {
        [Fact]
        public async Task ShouldBeAbleToDeployAContract()
        {
            var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c";
            var password = "password";

            var abi = @"[{""constant"":false,""inputs"":[{""name"":""val"",""type"":""int256""}],""name"":""multiply"",""outputs"":[{""name"":""d"",""type"":""int256""}],""payable"":false,""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""int256""}],""payable"":false,""type"":""constructor""}]";
            var byteCode =
                "0x60606040523415600b57fe5b6040516020806100ac83398101604052515b60008190555b505b6079806100336000396000f300606060405263ffffffff60e060020a6000350416631df4f14481146020575bfe5b3415602757fe5b60306004356042565b60408051918252519081900360200190f35b60005481025b9190505600a165627a7a72305820ec2cf1c300fa92e0ccd1f5ce518cc43c9578fe9007797024f1424d07f491020a0029";
            var multiplier = 7;

            var web3 = new Web3();
            var web3Geth = new Web3Geth();

            var unlockAccountResult =
                await web3.Personal.UnlockAccount.SendRequestAsync(senderAddress, password, 120);

            Assert.True(unlockAccountResult);

            var transactionHash =
                await web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, multiplier);

            var mineResult = await web3Geth.Miner.Start.SendRequestAsync(6);
            //var mineResult = await web3.Miner.Start.SendRequestAsync(6);

            Assert.True(mineResult);

            var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);

            while (receipt == null)
            {
                Thread.Sleep(5000);
                receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash);
            }

            var contractAddress = receipt.ContractAddress;
            var contract = web3.Eth.GetContract(abi, contractAddress);

            var multiplyFunction = contract.GetFunction("multiply");

            var result = await multiplyFunction.CallAsync<int>(7);

            Assert.Equal(49, result);
        }
    }
}

Full sourcecode can be found here https://github.com/stradled/NethereumTest

  • I would like to know too, did you find the answer? – Richard Fu Aug 28 '18 at 10:00
  • Was a while ago. But don't think I did, just moved on. Sorry – stradled Aug 29 '18 at 12:37
4

I happened to stumble upon the same problem and after weeks of trial and error this worked for me:

var web3 = new Nethereum.Geth.Web3Geth("http://127.0.0.1:8454");
var mine = await web3.Miner.Start.SendRequestAsync(6);

NB:// please use the local address and port that applies to you, mine in this case is 127.0.0.1:8454

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.