These are chat archives for Nethereum/Nethereum

14th
May 2018
Scot Wallace
@nestforce
May 14 2018 02:33
Hi, does anyone know how to call eth_getLogs ?
I've searched for a while but not any sites mention the spec of API

and I tried to put the transaction hash as the parameter like "address":"0x...................", it just returned me an empty json


{
"jsonrpc": "2.0",
"id": 1,
"result": []
}


I am truly sure that the transaction hash is correct...
Stef Heyenrath
@StefH
May 14 2018 05:38
@juanfranblanco About the password question...
Is it possible to make each function require gas to be executed (payable) ?
In that way I can also make sure that only registered addresses with enough gas can call the functions? Or is the ethereum blockchain not designed te be used in that way ?
Juan Blanco
@juanfranblanco
May 14 2018 07:04
@StefH no it does not work that way
but one of the generator areas is to create a web api, which is exactly for that purpouse
Juan Blanco
@juanfranblanco
May 14 2018 08:08
and to your point, maybe another query layer more abstract will fit
which might be just driven through authentication
Stef Heyenrath
@StefH
May 14 2018 09:17
I found a possible idea, described here simple-login-system-using-ethereum which I'll investigate if this fits my requirements.
Juan Blanco
@juanfranblanco
May 14 2018 09:18
yeah that was the thought
but that could be extended
too
so mainly you sign every query
but that needs a bigger layer
(bigger abstraction layer)
check ujo does authentication through metamask
Juan Blanco
@juanfranblanco
May 14 2018 09:23
and message signing
Ganesh Prasad Kumble
@0zAND1z
May 14 2018 12:56
Hi guys, trying to check the variable value from Xamarin Forms with contract.GetFunction("variable").CallAsync<string>();
Getting exception saying that method was not found (ABI missing the definition? Although ABI has the variable defined properly)
Pls help
Enigmatic
@EnigmaticUnreal_twitter
May 14 2018 13:18
Your code looks correct... Maybe you might need to check the Solidity code to ensure the variable is set as public.
image.png
Calling from VB.NET
Dim rTokenName As String = Await contract.GetFunction("name").CallAsync(Of String)
Ganesh Prasad Kumble
@0zAND1z
May 14 2018 13:20
Thx for the suggestion but the variable is defined properly:
address public variable;
address public variable;
Enigmatic
@EnigmaticUnreal_twitter
May 14 2018 13:47

Try to double check to see what you might be missing, maybe be the contract object which isn't initialised properly, or something small which was overlooked.

I just cooked up a simple one using the same syntax:

       public async Task DeployContract()
        {
            var wordList = "envelope achieve quantum trade science trigger coffee pink bird strike interest street";
            var wallet = new Wallet(wordList, null);
            var senderAddress = wallet.GetAccount(0).Address;

            //omitted ABI and byteCode from copy-paste
            var abi = @"";
            var byteCode = "";
            var web3 = new Web3.Web3("http://localhost:8545/");
            var gas = new HexBigInteger(3000000);

            var transactionHash = await web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, gas);
            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 getOwner = contract.GetFunction("owner");
            var result = await getOwner.CallAsync<string>();
            MessageBox.Show(Convert.ToString(result));

        }

With the contract:

pragma solidity ^0.4.22;

contract test {
    address public owner;

    function test() {
        owner = msg.sender;
    }
}
danielcostaext
@danielcostaext
May 14 2018 15:07

Hi, a quick question, I've been trying to deploy the contract from the tutorials with nethereum, but I always get an exception:
Nethereum.JsonRpc.Client.RpcResponseException: intrinsic gas too low

When I'm on my nethereum node(private network) and I use Ethereum Wallet to deploy everything seems to work just fine.

Can someone tell me what I'm doing wrong?

My Code:
var abi = @"[{""constant"":false,""inputs"":[{""name"":""value"",""type"":""int256""}],""name"":""multiply"",""outputs"":[{""name"":""resultValue"",""type"":""int256""}],""payable"":false,""stateMutability"":""nonpayable"",""type"":""function""},{""inputs"":[{""name"":""multiplier"",""type"":""int256""}],""payable"":false,""stateMutability"":""nonpayable"",""type"":""constructor""}]";
var byteCode = "0x608060405234801561001057600080fd5b506040516020806100d08339810160405251600055609d806100336000396000f300608060405260043610603e5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416631df4f14481146043575b600080fd5b348015604e57600080fd5b506058600435606a565b60408051918252519081900360200190f35b60005402905600a165627a7a72305820c2bd5842eeba9d3555f7d901aeb96ae21437f16042d5247aff72d676533bafb70029";
var unlockAccResult = await web3.Personal.UnlockAccount.SendRequestAsync(senderAddress, password, duration);
Assert.IsTrue(unlockAccResult);
web3Geth.TransactionManager.DefaultGas = Transaction.DEFAULT_GAS_LIMIT;
web3Geth.TransactionManager.DefaultGasPrice = Transaction.DEFAULT_GAS_PRICE;
var transactionHash = await web3Geth.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, 7);

            var mineResult = await web3Geth.Miner.Start.SendRequestAsync(6);
ok, now I can send the transaction, but the web3Geth.Miner.Start.SendRequestAsync(6); is always false
Juan Blanco
@juanfranblanco
May 14 2018 15:38
@danielcostaext i would not bother controlling the mining
just use one of the test chains
from here
geth and parity are configured to use the Proof of Authority consensus so are very fast
and ganache-cli is the ethereum chain emulator created by the truffle guys (old testrpc)
Psilon
@Pzixel
May 14 2018 16:39
How can I handle ethereum exceptions?
For example I call
await function.SendTransactionAndWaitForReceiptAsync(accountAddress,
                                                           new HexBigInteger(4600000),
                                                           new HexBigInteger(0),
                                                           functionInput: functionInput);
with wrong accountAddress
and i have onlyOwner modifier on my function
thus transaction fails
but on C# side it silently passes
Juan Blanco
@juanfranblanco
May 14 2018 16:42
you can check the status of the receipt
or you could be more creative and raise an event on error
Psilon
@Pzixel
May 14 2018 16:46
even on error
wow
so dirty
Juan Blanco
@juanfranblanco
May 14 2018 16:47
well depends how you consider what an event is
which is mainly writing to the logs
But mainly that's about it :)
the only options
Enigmatic
@EnigmaticUnreal_twitter
May 14 2018 17:02
With Solidity 0.4.22, we should be able to return messages on a require statement - Which just reminded me, I haven't tested how the message is passed back yet........
Hmm. I wonder if there is a way to hook this return.
image.png
pragma solidity ^0.4.22;

contract test {
    address public owner;

    function test() {
        owner = msg.sender;
    }

    function callowner() {
        require(msg.sender == owner, "nope nope nope nope nope.");
    }
}
Psilon
@Pzixel
May 14 2018 17:14
@juanfranblanco so
I can throw an error
but I can't know it on C# side?
because this is example of successful call {"transactionHash":"0x0c9ad8f41c9cab15eda380292edf3b97c76475fc4c11535da77f26243ab5c555","transactionIndex":"0x0","blockHash":"0xdf8754009033f587916120381bb7dcf961e1b5055f9c5df436bcb246f5f892a1","blockNumber":"0x6e1","cumulativeGasUsed":"0x6df9","gasUsed":"0x6df9","contractAddress":null,"status":"0x0","logs":[]}
and this is an example of failed one {"transactionHash":"0x985895afed3c6c48481e31b932e719cdbbb856b8dbe0b93ea4e50c92aab89377","transactionIndex":"0x0","blockHash":"0x7c49c1cbc579976f3df8f37556113730b2f08ea5ad43f8f8665205342953504f","blockNumber":"0x6ab","cumulativeGasUsed":"0x5f14","gasUsed":"0x5f14","contractAddress":null,"status":"0x0","logs":[]}
I personally don't see any difference
I can only know if I have created some object during this call or I didn't
Juan Blanco
@juanfranblanco
May 14 2018 17:19
yes that is part of the require in 22, 23 but
not part of the trasactionreceipt
if you debug you can get that info but that's about it
But that will come i guess
Status
should be 0
for failed
you need Byzantium for that
enable Byzantium
Psilon
@Pzixel
May 14 2018 17:24
I have byzantium
it's not failed
Juan Blanco
@juanfranblanco
May 14 2018 17:25
k
check the poa
from Testchains
might help
Psilon
@Pzixel
May 14 2018 17:25
I currently have status 1 if there is something created
and 0 if it wasn't
Juan Blanco
@juanfranblanco
May 14 2018 17:26
ah ok
so 1 good
0 failed
Psilon
@Pzixel
May 14 2018 17:26

This is logs for succesffully deployed contract:

{"transactionHash":"0xf3bf40a22efedf0026d75810c5e4b14aa44fbbdb144d29b1a6b861e521d46387","transactionIndex":"0x0","blockHash":"0x1f0594dbee0bc70da7e853f93d1e4cc6a439d80e34384ee236574db8c1c56d00","blockNumber":"0x6af","cumulativeGasUsed":"0x1b9d22","gasUsed":"0x1b9d22","contractAddress":null,"status":"0x1","logs":[{"address":"0x5b2c696502260040b76111dae1a5ba0409b81593","blockHash":"0x1f0594dbee0bc70da7e853f93d1e4cc6a439d80e34384ee236574db8c1c56d00","blockNumber":"0x6af","data":"0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000519b68739d8b85c2aeec4033a7265b3f61acbdc50000000000000000000000000000000000000000000000000000000000000020303030312d393330303030332d3033303330312d303030303132362f31383130","logIndex":"0x0","topics":["0x9d88489a85ac9c748e6a88e307dd6cc012b1f5a524486b9b9bfbdd130a9283f9","0xc6552a8c341d158f67c5966c7888914567bff82dfb4320f69439e08353acdcb0"],"transactionHash":"0xf3bf40a22efedf0026d75810c5e4b14aa44fbbdb144d29b1a6b861e521d46387","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}]}

as you see 0x1
but it doesn't man 0 is failed
it's rather mean 0 if nothing was created during transaction
for example I have following method
    function updateStatus(uint64 updateDate, uint64 statusCode, string note) public onlyOwner {
        statusUpdates.push(StatusUpdate(updateDate, statusCode, note));
    }
it works fine
but the status is 0
Juan Blanco
@juanfranblanco
May 14 2018 17:28
hmm
have you tested it with geth?
Ill check it later
Psilon
@Pzixel
May 14 2018 19:25
I'm not sure what geth could get)
I mean it receives the same receipt, isn't it?
the only question is how we interpret it
Juan Blanco
@juanfranblanco
May 14 2018 21:35
it might be an issue with parity
that was my point
so in theory the status is supposed to be 0 on error
Psilon
@Pzixel
May 14 2018 21:37
hm
Juan Blanco
@juanfranblanco
May 14 2018 21:37
"The CALL opcode returns 0 on failure and 1 on success."
Psilon
@Pzixel
May 14 2018 21:38
can you compile some contract with such a method and show me its receipt
when you call it via nethereum
it would be really helpful
Juan Blanco
@juanfranblanco
May 14 2018 21:38
well i was going to bed :)
two seconds lets see how fast is the code generator and tester :)
Psilon
@Pzixel
May 14 2018 21:44
well
i will be fine to see it tommorow if you don't mind ;)
Juan Blanco
@juanfranblanco
May 14 2018 22:03
ok tested in both chains
geth and parity both return 1
using this contract
pragma solidity ^0.4.23;

contract TestReceipt {

    struct StatusUpdate{
        uint64 updateDate;
        uint64 statusCode;
        string note;
    }

    StatusUpdate[] statusUpdates;

    address public owner;

    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    constructor() public {
        owner = msg.sender;
    }

    function updateStatus(uint64 updateDate, uint64 statusCode, string note) public onlyOwner 
    {
        statusUpdates.push(StatusUpdate(updateDate, statusCode, note));
    }
}
and this test
public class ContractTest : NethereumIntegrationTest
    {
        public ContractTest(ITestOutputHelper xunitTestOutputHelper) : base("http://localhost:8545",
            DefaultTestAccountConstants.PrivateKey,
            new NethereumTestDebugLogger(new XunitOutputWriter(xunitTestOutputHelper)))
        {

        }

        [Fact]
        public async Task AfterDeploymentAndUpdate_ShouldNotError()
        {
            var contractDeploymentDefault = new TestReceiptDeployment()
            {
                FromAddress = DefaultTestAccountConstants.Address,
            };

            GivenADeployedContract(contractDeploymentDefault);

            var updateFunction = new UpdateStatusFunction()
            {
                Note = "hello",
                StatusCode = 1,
                UpdateDate = 1

            };

            var receipt = GivenATransaction(updateFunction).TransactionReceipt;

            Assert.True(receipt.Status.Value == 1);

        }

    }
both using geth poa and parity poa from testchains
I need a ThenShouldNotError
Psilon
@Pzixel
May 14 2018 22:12
thank you for your massive work
I'l try to come back later with results