These are chat archives for Nethereum/Nethereum

11th
Jul 2018
Esteban Gallardo
@EstebanGameDevelopment
Jul 11 2018 08:56
Hi Juan. Thanks a lot for the help of the other day. I'm able to deploy new contracts. Now I'm experiencing problems to call the constructor in Solidity. I've not found any way to make work the constructor function. In the transaction explorer it fails the contract's creation every time I try to use it, I have tried all the possible combination that I have found out there but none of them work. For the moment I'm working without constructor but it will be a problem in the future since I need to initialize in the constructor the owner. Thanks for your support!
Enigmatic
@EnigmaticUnreal_twitter
Jul 11 2018 08:59
@EstebanGameDevelopment - If I got you correctly... You were trying to deploy a contract with some constructor arguments, but you weren't able to?
Esteban Gallardo
@EstebanGameDevelopment
Jul 11 2018 09:01

No, the constructor have no arguments, it's just like in the example of the Examples of Netehreum Flappy bird: {
contract PlayerScore {

    address owner;

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

}

Enigmatic
@EnigmaticUnreal_twitter
Jul 11 2018 09:03
Interesting - You have an example tx of the failed contract creation, or the error message? I can test this out too.
Esteban Gallardo
@EstebanGameDevelopment
Jul 11 2018 09:05

pragma solidity ^0.4.22;

/// @title Keeps the information about the data that belong to the owner.
contract SignedData {

address owner;

struct SignatureInformation {
    address addr;
    int256 url;
    int256 hashcode;
}

SignatureInformation[] public signedDocuments;

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

// Owner save the hashcode of the data he belongs
function signDocument(int256 url, int256 hashcode)
{
    if (msg.sender != owner) return;

    int indexDocument = getSignedDocument(url);
    if (indexDocument == -1)
    {        
        var newSignedDocument = SignatureInformation(msg.sender, url, hashcode);
        signedDocuments.push(newSignedDocument);
    }
    else
    {
        signedDocuments[uint(indexDocument)].hashcode=hashcode;
    }    
}

// Any user can check if the owner has signed the data
function verifyDocument(int256 url, int256 hashcode) returns(int)
{
    int indexDocument = getSignedDocument(url);
    if (indexDocument != -1)
    {        
        SignatureInformation storage currentSignedDocument = signedDocuments[uint(indexDocument)];
        if (currentSignedDocument.hashcode == hashcode)
        {
            return indexDocument;
        }
        else
        {
            return -1;
        }
    }
    else
    {
        return -1;
    }    
}

// Total number of documents signed
function getCountSignedDocuments() returns(uint) {
    return signedDocuments.length;
}

// Private function to get the hashcode by url
function getSignedDocument(int256 url) private returns(int) 
{
    for (uint i = 0; i < signedDocuments.length; i++)
    {
        SignatureInformation storage currentSignedDocument = signedDocuments[i];
        if (currentSignedDocument.url == url)
        {
            return int(i);
        }
    }
    return -1; 
}

}

The rest of the contract work as intended. The only missing part is that I need the constructor to work to set up the owner.
Enigmatic
@EnigmaticUnreal_twitter
Jul 11 2018 09:10
If I deploy this right out from Remix it seems to work fine - You're getting an error from Nethereum I presume? Will load up Nethereum once I am done with some work on my side.
Esteban Gallardo
@EstebanGameDevelopment
Jul 11 2018 09:16
Ok, give me some minutes, I have to redo the contract to reproduce the fail and give you the information about the contract id that fails so you can check it out in the transaction explorer
Esteban Gallardo
@EstebanGameDevelopment
Jul 11 2018 09:24
The contract id of the previous code is: 0xb2899423f3738bd02c4f57fbe90c26444edb5bfe
Enigmatic
@EnigmaticUnreal_twitter
Jul 11 2018 09:31

Ah. Might be because of gas limits. Copied your bytecode and tested - seem to take around 330k gas (https://ropsten.etherscan.io/tx/0x4ec9deccd3aeaa961fce41aa8742985852e6bd2ce2eec219f3920e0f0dc0d169).

Maybe just overestimate gas a little, say 500k, and see how it works out for you?

(Am also wondering if you're using the EstimateGasAsync function, in which case I am wondering if it is reporting the amount of gas needed to deploy your contract correctly. But let's see if bumping up gas limits help you first.)
Esteban Gallardo
@EstebanGameDevelopment
Jul 11 2018 09:36
Yes, about the gas estimation, I still don't know how to calculate it right. Right now I'm calculating it like this: BigInteger gasValue = new BigInteger();
var requestGas = new EthBlockNumberUnityRequest(BASE_URL_ADDRESS_ACCESS_ETHEREUM_NETWORK);
yield return requestGas.SendRequest();
if (requestGas.Exception == null)
{
//get transaction receipt
gasValue = requestGas.Result.Value * 2;
}
it's plain dirty code, but I've not been able to use the gas estimation unity, I've not found any working example
Enigmatic
@EnigmaticUnreal_twitter
Jul 11 2018 09:55

Ah I wish I know about Unity to help. :( I did some searching around and yea, so far I found some code snippets for EthEstimateGasUnityRequest but that's for calling a function (Nethereum/Nethereum#234).

If it's VB.NET it's just:

Dim gas As HexBigInteger = Await iweb3.Eth.DeployContract.EstimateGasAsync(abi, bytecode, account.Address, Nothing)

So far my code reports it to be 330686 gas required, so I am quite certain your contract deployment is having issues because of gas limits. Just need to find out how to do it properly for Unity.

Esteban Gallardo
@EstebanGameDevelopment
Jul 11 2018 09:59
@EnigmaticUnreal_twitter Thanks a lot for your help! For the moment, I'm skipping this issue to progress in other areas
Fiblan
@fiblan
Jul 11 2018 13:27
Hi folks, just a question about best practices. In this example https: //github.com/Nethereum/Nethereum.Flappy/blob/master/Scripts/TopScoreService.cs#L34 to set a topscore, you use a hard-coded private key of the contract owner and in the comments it is suggested to hide / obscure it. I wonder how? Is obfuscation really a best practice? What are the correct alternatives, for example for sending a score of a flappy like game? I hope I'm not OT.
Juan Blanco
@juanfranblanco
Jul 11 2018 13:43
That is just an example to validate the user has send the transaction using the game (mainly the game signs the request). If you put in plain text it will be very easy to find / "crack"
so it is mainly a very simple anti cheating system
and yeah... that should not be the "owner" of the contract :D
it is a simple example
Fiblan
@fiblan
Jul 11 2018 14:07
ok, thanks @juanfranblanco. However, I find it curious how difficult it is to find a reliable anti-cheating solution based on ethereum.
Esteban Gallardo
@EstebanGameDevelopment
Jul 11 2018 14:29
One short question. Is it possible to get the list of transaction performed using the public address? I have found "EthGetTransactionCountUnityRequest" helps you to know that number of transactions performed by a public address but I've not been able to find a function that could give me the list of the transaction ids. Is there any function for that? The reason why I'm asking for that is that in the project I'm developing I will need to display the list of transactions performed by a address. You could call this feature a transaction explorer within Unity mobile app. I've been able to do it with NBitcoin and I wonder how I could do the same with NEthereum. Thanks for the help!
Enigmatic
@EnigmaticUnreal_twitter
Jul 11 2018 18:47

@EstebanGameDevelopment - You will probably want to obtain the transaction list from public services like etherscan's API or Quickblocks. Not sure how NBitcoin does it, I suspect through Qbit's API, but in either case some form of traversing through blocks and indexing relevant transactions will be needed.

On the other hand if it's contract events, we could use filters. :) Bloom filters are amazing. Then again, I think there are public APIs for that too...

Sam
@shessenauer
Jul 11 2018 22:51
Hey everyone, do we still need to run a full node in order to use nethereum for sending transactions or is that resolved yet?
Sam
@shessenauer
Jul 11 2018 22:58
It looks like there is infura now so I am assuming no more full nodes
Is the latest Nethereum release supporting unity?