These are chat archives for Nethereum/Nethereum

18th
Sep 2017
ChinhP
@Chinh-P
Sep 18 2017 05:40
Hello, may I ask what is the best way to conver from HexBigInterger to decimal (I'm getting account balance and show the value in Eth)
what Im doing now is convert it to Wei
var balance = await web3.Eth.GetBalance.SendRequestAsync(account); var weiAmount = UnitConversion.Convert.ToWei(balance);
then from wei convert to Ether:
var eth = UnitConversion.Convert.FromWei(weiAmount, 18);
Juan Blanco
@juanfranblanco
Sep 18 2017 05:42
yes thats about it
ChinhP
@Chinh-P
Sep 18 2017 05:42
but look like there is a bug in converting FromWei
public decimal FromWei(BigInteger value, BigInteger toUnit) { return (decimal) value/(decimal) toUnit; }
Juan Blanco
@juanfranblanco
Sep 18 2017 05:42
what version are you using?
ChinhP
@Chinh-P
Sep 18 2017 05:43
Im using 2.0.0.0
Juan Blanco
@juanfranblanco
Sep 18 2017 05:43
rc7 I pressume
ChinhP
@Chinh-P
Sep 18 2017 05:43
yes
Juan Blanco
@juanfranblanco
Sep 18 2017 05:43
did you convert your balance to BigInteger?
ChinhP
@Chinh-P
Sep 18 2017 05:44

`

<package id="Nethereum.ABI" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.Contracts" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.Geth" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.Hex" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.JsonRpc.Client" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.JsonRpc.RpcClient" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.KeyStore" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.RLP" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.RPC" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.Signer" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.Util" version="2.0.0-rc7" targetFramework="net452" />
<package id="Nethereum.Web3" version="2.0.0-rc7" targetFramework="net452" />
`

Juan Blanco
@juanfranblanco
Sep 18 2017 05:44
ok so we are in the same version :)
ChinhP
@Chinh-P
Sep 18 2017 05:44
:)
Juan Blanco
@juanfranblanco
Sep 18 2017 05:44
so what is the problem
ChinhP
@Chinh-P
Sep 18 2017 05:44
the converting to Wei has been done successfully
but the 3rd line, convert from wei to eth
Value was either too large or too small for a Decimal.
Juan Blanco
@juanfranblanco
Sep 18 2017 05:45
ah.. ok
there is not support from BigDecimal in .net
ChinhP
@Chinh-P
Sep 18 2017 05:45
ya
So, should I use double instead of decimal
Juan Blanco
@juanfranblanco
Sep 18 2017 05:46
decimal is bigger it is 128 bit
so you are going to have to lose some precision
what figures do you have?
ChinhP
@Chinh-P
Sep 18 2017 05:48
my Eth value is 1000000218006.28125
I know maybe in the real world, it's almost impossible to have that amount, this one this the auto given number go with first account in azure
so, basically, the wei is almost 10^30
decimal.MaxValue is 79,228,162,514,264,337,593,543,950,335
<10^28
Juan Blanco
@juanfranblanco
Sep 18 2017 05:50
yes
what you can do is trim the excess
and do a conversion then
i don't know if that will be good or not to have it in Nethereum
ChinhP
@Chinh-P
Sep 18 2017 05:54
Ok, so, maybe I just get string.sub first 26 characters
Juan Blanco
@juanfranblanco
Sep 18 2017 05:54
yes you mainly remove zeros
which are not needed
ChinhP
@Chinh-P
Sep 18 2017 05:54
ya, thanks
Juan Blanco
@juanfranblanco
Sep 18 2017 05:55
then your unit coversion will be 18 - number of zeros removed
ChinhP
@Chinh-P
Sep 18 2017 05:55
But I thought the max value of double is bigger than decimal
Float- 340282346638528986604286022844204804240,
Double - 179769313486231680088648464220646842686668242844028646442228680066046004606080400844208228060084840044686866242482868202680268820402884062800406622428864666882406066422426822086680426404402040202424880224808280820888844286620802664406086660842040886824002682662666864246642840408646468824200860804260804068888,
Decimal - 79228162514264337593543950335
so you want more precission
but good point
ChinhP
@Chinh-P
Sep 18 2017 05:59
yes, double only have 15-16 digits, so If we use it to save eth, maybe I lose around 10^2 wei
Juan Blanco
@juanfranblanco
Sep 18 2017 06:00
yes
but nevertheless I think the 0 trimming belongs to Nethereum as a simple safe guard
ChinhP
@Chinh-P
Sep 18 2017 06:03
yes, I'll use that way
Juan Blanco
@juanfranblanco
Sep 18 2017 06:07
ok cool, I will add (thinking out loud) a simple trimming for zeros, a truncate mechanism on conversion (mainly avoid to throw exceptions ) and finally throw as per now
ChinhP
@Chinh-P
Sep 18 2017 06:25
Ok, so, I use this way to handle the conversion
 var weiAmount = balance.Value;
                var weiAmountLength = weiAmount.ToString().Length;
                var rounding =  weiAmountLength - 23 > 0 ? Math.Pow(10, weiAmountLength - 23)  : 1;
                var weiRounding = weiAmount / (System.Numerics.BigInteger)rounding;


                var eth = UnitConversion.Convert.FromWei(weiRounding, 18) * (decimal)rounding;
naming is not good, but the idea is use a smaller bigInt and use it for the FromWei funcion
Juan Blanco
@juanfranblanco
Sep 18 2017 06:26
yes
ChinhP
@Chinh-P
Sep 18 2017 06:28
:)
Juan Blanco
@juanfranblanco
Sep 18 2017 06:28
(deleted ! :D )
ChinhP
@Chinh-P
Sep 18 2017 06:28
it has some trade off
Juan Blanco
@juanfranblanco
Sep 18 2017 06:30
yes
Juan Blanco
@juanfranblanco
Sep 18 2017 06:39
maybe using strings and positioning the decimal point will help as it will not be a bigger issue with the precission
ChinhP
@Chinh-P
Sep 18 2017 06:42
Yes, using string and moving to decimal point should be good
but I just rethink about double, actually it's not bad
Juan Blanco
@juanfranblanco
Sep 18 2017 06:43
yes
ChinhP
@Chinh-P
Sep 18 2017 06:43
because the double save Wei value
not Eth value
and Wei value 15-16 digits is Ok
Juan Blanco
@juanfranblanco
Sep 18 2017 06:44
well the idea is that you should be ok losing precission
hence i thought to fall back to double
ChinhP
@Chinh-P
Sep 18 2017 06:45
Maybe It wont lose any
Juan Blanco
@juanfranblanco
Sep 18 2017 06:46
depends yes
ChinhP
@Chinh-P
Sep 18 2017 06:48
something like this one
 public decimal FromWei(BigInteger value, BigInteger toUnit)
        {
            return (decimal) ((double) value/(double) toUnit);
        }
Juan Blanco
@juanfranblanco
Sep 18 2017 06:49
hmm yep as we don't support
ChinhP
@Chinh-P
Sep 18 2017 06:49
for examle the value is 10^35 +123; toUnit = 10^18; then the return value still 10^17 + 123*10^-18,isn't it
Juan Blanco
@juanfranblanco
Sep 18 2017 06:50
Tether..
so gether is "1000000000000000000000000000"
ChinhP
@Chinh-P
Sep 18 2017 06:57
Ic, so moving decimal point is the only way for now
Juan Blanco
@juanfranblanco
Sep 18 2017 06:58
yes.. the safest
not the "nicest"
ChinhP
@Chinh-P
Sep 18 2017 06:58
:)
hanhvn
@vonhathanh
Sep 18 2017 07:07
hi all
can some one help me use the unity module in visual studio guys :worried:
im going to create a mobile game to interact with ethereum blockchain but i the unity module was not installed when i run "Install-Package Nethereum.Portable -Pre"
kai
@kaista82_twitter
Sep 18 2017 07:42
Im not sure but you may have to put the dll in plugins dir with unity project folder structure
hanhvn
@vonhathanh
Sep 18 2017 07:44
@kaista82_twitter thanks, i find out that i have to download it manually :D
Matt.Tan
@mtbitcoin
Sep 18 2017 07:49
@juanfranblanco i am trying to get Nethereum to verify message signatures in a compatible way as MyEtherwallet but have been having trouble doing so.

For instance using (which was generated in MyEtherwallet)
{
"address": "0xe651c5051ce42241765bbb24655a791ff0ec8d13",
"msg": "wee test message 18/09/2017 02:55PM",
"sig": "0xf5ac62a395216a84bd595069f1bb79f1ee08a15f07bb9d9349b3b185e69b20c60061dbe5cdbe7b4ed8d8fea707972f03c21dda80d99efde3d96b42c91b2703211b",
"version": "2"
}

I am unable to recover the signed message using the methods from https://github.com/Nethereum/Nethereum/tree/efbad339f16322eebd7913ad6c0cf2b0aa862361/src/Nethereum.Web3.Tests/Signing

would you have nay idea what the issue might be?
Juan Blanco
@juanfranblanco
Sep 18 2017 07:56
@vonhathanh use the unity dlls from the release in github
@mtbitcoin let me try it
Matt.Tan
@mtbitcoin
Sep 18 2017 07:59
are the new library available via NUGET?
Juan Blanco
@juanfranblanco
Sep 18 2017 07:59
yes 2.0.0 rc7
Matt.Tan
@mtbitcoin
Sep 18 2017 07:59
i am currently running Nethereum Portable and it only shows 1.0.6 as the latest
Juan Blanco
@juanfranblanco
Sep 18 2017 08:00
oh man you need to include pre release
Matt.Tan
@mtbitcoin
Sep 18 2017 08:00
:-)
Juan Blanco
@juanfranblanco
Sep 18 2017 08:00
stay with the latest, it includes all the stuff
I think I am going to move to 2.0.0 relase now after a couple of fixes
documentation can catch up later
Matt.Tan
@mtbitcoin
Sep 18 2017 08:01
fingers crossed
Juan Blanco
@juanfranblanco
Sep 18 2017 08:02
:)
Matt.Tan
@mtbitcoin
Sep 18 2017 08:12
upgrade went ok :-)
but i still cant get the signature to work?
Juan Blanco
@juanfranblanco
Sep 18 2017 08:13
yes I am checking their code and how the sign it
yes it is
Matt.Tan
@mtbitcoin
Sep 18 2017 08:14
thanks :-)
used to work.. not sure what changed
Juan Blanco
@juanfranblanco
Sep 18 2017 08:15
they just love to change things all the time
:)
Matt.Tan
@mtbitcoin
Sep 18 2017 08:19
:-(
hanhvn
@vonhathanh
Sep 18 2017 08:22
@juanfranblanco thanks :D
Juan Blanco
@juanfranblanco
Sep 18 2017 08:26
@mtbitcoin
Matt.Tan
@mtbitcoin
Sep 18 2017 08:26
yes?
Juan Blanco
@juanfranblanco
Sep 18 2017 08:26
 [Fact]
        public void ShouldVerifyMEWSignature()
        {
            var address = "0xe651c5051ce42241765bbb24655a791ff0ec8d13";
            var msg = "wee test message 18/09/2017 02:55PM";
            var sig = "0xf5ac62a395216a84bd595069f1bb79f1ee08a15f07bb9d9349b3b185e69b20c60061dbe5cdbe7b4ed8d8fea707972f03c21dda80d99efde3d96b42c91b2703211b";

            var signer = new EthereumMessageSigner();
            var addressRec = signer.EcRecover(Encoding.UTF8.GetBytes(msg), sig);
            Assert.Equal(address.ToLower(), addressRec.ToLower());
        }
mainly they use the UTF8 bytes and pass it to the signer
V2 indicates the Ethereum prefix message type
V1 will be the simple one which uses the SHA3 hash
Juan Blanco
@juanfranblanco
Sep 18 2017 08:31
and then signs
In nethereum V1 is the Signer class, V2 IS THE EthereumMessageSigner
I added an overload now to sign and recover using UTF8 encoding
Matt.Tan
@mtbitcoin
Sep 18 2017 08:42
@juanfranblanco you are the man! ... THANK YOU!
Juan Blanco
@juanfranblanco
Sep 18 2017 08:43
Nethereum/Nethereum@b16d892
check the new overloads for signing and recovery
Thanks :D
kai
@kaista82_twitter
Sep 18 2017 09:21
ahh I wondered why that ecrecover method returned a string rather than a bool, I have to compare the addresses nice
Juan Blanco
@juanfranblanco
Sep 18 2017 09:23
yes this is specific to Ethereum, it returns the address
same as solidity
Free Account
@viettienbk
Sep 18 2017 09:26
@juanfranblanco
private IEnumerable abc()
{
Debug.Log("start abc");
blockNumberRequest = new EthBlockNumberUnityRequest("http://118.69.187.7:8545");
Debug.Log(blockNumberRequest);
// yield return tokenRequest.SendRequest(balanceOf.CreateCallInput("0x0f816ba0d79ebb478fc86c1e0901460e5b43bfee"), Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest());
yield return blockNumberRequest.SendRequest();
}
i tried to code as you guide in : https://medium.com/@juanfranblanco/nethereum-2-0-0-rc5-unity3d-integration-eb7664664813 but my function is never called. I put it in the start() function of my main class.
kai
@kaista82_twitter
Sep 18 2017 09:27
is the main class attached to a game object?
Free Account
@viettienbk
Sep 18 2017 09:28
yes, it is
kai
@kaista82_twitter
Sep 18 2017 09:28
and you dont even get start abc?
Juan Blanco
@juanfranblanco
Sep 18 2017 09:28
have you started the coroutine?
Free Account
@viettienbk
Sep 18 2017 09:28
yes, i call it in the start() but no log is print
kai
@kaista82_twitter
Sep 18 2017 09:29
so you just run abc() from start() or startcoroutine
can you put Debug.Log("Working"); in update pls
Free Account
@viettienbk
Sep 18 2017 09:30
wait me a sec
kai
@kaista82_twitter
Sep 18 2017 09:30
just to 100% confirm its attached right
ok no rush
Free Account
@viettienbk
Sep 18 2017 09:36
@kaista82_twitter i put the Debug.Log("working") as you said, it does appear on the console.
kai
@kaista82_twitter
Sep 18 2017 09:46
can you paste me the entire start method please
or the entire class if its not too big
Free Account
@viettienbk
Sep 18 2017 09:48

`
void Start () {
Debug.Log("Start");
StartCoroutine("abc");
}
private IEnumerable abc()
{
Debug.Log("start abc");
blockNumberRequest = new EthBlockNumberUnityRequest("http://118.69.187.7:8545");
Debug.Log(blockNumberRequest);
yield return blockNumberRequest.SendRequest();
}

// Update is called once per frame
void Update () {
    Debug.Log("working");
    if (blockNumberRequest != null)
    {
        if (blockNumberRequest.Exception == null)
        {
            var blockNumber = blockNumberRequest.Result.Value;
            Debug.Log(blockNumber.ToString());
        }
    }
}`

@kaista82_twitter

kai
@kaista82_twitter
Sep 18 2017 09:49
where are you calling abc
h
oh the formatting got messed up
Free Account
@viettienbk
Sep 18 2017 09:49
sorry
kai
@kaista82_twitter
Sep 18 2017 09:49
not your fault
sec
erm shouldn't it be startcoroutine(abc()); ?
Free Account
@viettienbk
Sep 18 2017 09:50
let me try again @kaista82_twitter
it worked like a charm thanks @kaista82_twitter
kai
@kaista82_twitter
Sep 18 2017 09:52
you're welcome, enjoy!
I have just pushed the scripts for contextual info
Free Account
@viettienbk
Sep 18 2017 10:09
@juanfranblanco thank you very much
Juan Blanco
@juanfranblanco
Sep 18 2017 10:28
wow!!
and that
kai
@kaista82_twitter
Sep 18 2017 11:03
I dont know waht the xamarin forms unity thing is but the gtk progress is always nice
IM SO EXCITED
i hope first RC is decent
Juan Blanco
@juanfranblanco
Sep 18 2017 11:16
it means that you can create apps and run them in any platformt oo
including web
using xamarin forms
obviously it won't be the same..if you use coroutines / www as everywhere else
but also the capability of mixing 3d and forms is great. I love UrhoSharp for that
kai
@kaista82_twitter
Sep 18 2017 11:20
so you can host the game in the window or the windows in the game
Juan Blanco
@juanfranblanco
Sep 18 2017 12:33
the windows in the game
Juan Blanco
@juanfranblanco
Sep 18 2017 12:38
but you can have a game that is has just windows
kai
@kaista82_twitter
Sep 18 2017 12:39
so you can load up scenes in those windows
as well as windows in the scenes
?
oh
im confused what people will use the windows for
Juan Blanco
@juanfranblanco
Sep 18 2017 12:40
simple scenario..
imagine a vr world
which requires some form input
or a menu for a game
or just a forms application that runs on a ps4, web, switch?
kai
@kaista82_twitter
Sep 18 2017 12:41
ahh so i dont have to use the built in UI stuff
oh good point, unity is rather compatible
Juan Blanco
@juanfranblanco
Sep 18 2017 12:41
yes same stuff
same forms (ish)
slightly different backend processing
but same core business logic
kai
@kaista82_twitter
Sep 18 2017 12:41
cool
Juan Blanco
@juanfranblanco
Sep 18 2017 15:18
actually it is using the unity engine ui underneath but using Xaml to instantiate it
which is great too :)
kai
@kaista82_twitter
Sep 18 2017 15:19
yeah pretty cool
Free Account
@viettienbk
Sep 18 2017 15:19
@juanfranblanco How I can send Ether with Nethereum.Unity
Juan Blanco
@juanfranblanco
Sep 18 2017 15:20
it will be the "same" as normal Nethereum
but you need to build your transaction input
separately
Free Account
@viettienbk
Sep 18 2017 15:25
thank you
I will try
Free Account
@viettienbk
Sep 18 2017 15:34
@juanfranblanco When sending ether, I don't have var function = GetFunctionSetTopScore ();
kai
@kaista82_twitter
Sep 18 2017 15:35
contract.GetFunction("SetTopScore");
maybe? or do you mean actually send value
like a normal tx
Free Account
@viettienbk
Sep 18 2017 15:35
I mean actually send value
Juan Blanco
@juanfranblanco
Sep 18 2017 15:37
oh.. yes
that is to interact with a contract but the principle is the same
just create a transaction input with the value amount
Free Account
@viettienbk
Sep 18 2017 15:40
oh
I understood
thank @juanfranblanco
Free Account
@viettienbk
Sep 18 2017 16:03
I have successfully transferred ether
var transactionInput = new TransactionInput(){
            From = walletAddress,
            To = _to,
            Value = new HexBigInteger(_value)
        };
var transactionSignedRequest = new TransactionSignedUnityRequest(url, privateKey, walletAddress);
yield return transactionSignedRequest.SignAndSendTransaction(transactionInput);
Juan Blanco
@juanfranblanco
Sep 18 2017 16:12
awesome :D
Free Account
@viettienbk
Sep 18 2017 16:19
:smile: