These are chat archives for Nethereum/Nethereum

13th
Sep 2017
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 02:40
Hi guys, deploying a contract with params. Anything special? Heres my code:
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 03:15
    public static void DeplyContract(String contractPath, String contractName, Object[] param)
    {
        String bytes = GetBytesFromFile(contractPath + contractName + ".bin");
        Nethereum.Hex.HexTypes.HexBigInteger gas = new Nethereum.Hex.HexTypes.HexBigInteger(2000000);

        String abi = GetABIFromFile(String.Format("{0}{1}.abi", contractPath, contractName));

        if (param != null)
        {
            String tx =  web3.Eth.DeployContract.SendRequestAsync(bytes, puntaa, gas, param).Result;
            contractAddress = MonitorTx(tx);
        }
        else
        {
            String tx =  web3.Eth.DeployContract.SendRequestAsync(bytes, puntaa, gas).Result;
            contractAddress = MonitorTx(tx);
        }
    }
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 06:13
To confirm, 1 ETH as HexBigInt is
Nethereum.Hex.HexTypes.HexBigInteger ethToSend = new Nethereum.Hex.HexTypes.HexBigInteger(1000000000000000000);
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 06:18
Seems to have to be Nethereum.Hex.HexTypes.HexBigInteger ethToSend = new Nethereum.Hex.HexTypes.HexBigInteger("8AC7230489E80000");
kai
@kaista82_twitter
Sep 13 2017 06:56
Imo use toWei(1)
kai
@kaista82_twitter
Sep 13 2017 07:22
Utils.unitconversion
Convert
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 09:35
Ok
kai
@kaista82_twitter
Sep 13 2017 09:37
thats fine with ethereum, if you're working with a token with less decimal places you'll need to do something special, but it seems you're writing for eth
Utils.UnitConversion.Convert.ToWei and FromWei
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 09:46
Just trying to "unit test" really. The contract stats 1 eth == n tokens.
Seems I was passing in the wrong amount of eth, given its base 16
kai
@kaista82_twitter
Sep 13 2017 09:47
ok well, hopefully that helps you out
you can see the class on the repo (the code)
Juan Blanco
@juanfranblanco
Sep 13 2017 09:58
@kaista82_twitter i will push today a new version which includes an improved validation
kai
@kaista82_twitter
Sep 13 2017 09:58
validation of what mate
Juan Blanco
@juanfranblanco
Sep 13 2017 09:59
of the private key on key store
kai
@kaista82_twitter
Sep 13 2017 09:59
oh nice
wonderful, that's brilliant thank you mate
Juan Blanco
@juanfranblanco
Sep 13 2017 10:00
just converting to an unsigned byte array from a biginteger
then it should match the 32
kai
@kaista82_twitter
Sep 13 2017 10:01
yeah I wasn't sure if it was that simple as I wanted to actually contribute hehe, I will get that latest vs and see if I can assist in these things
hmm
yeah absolute it should do it
or
just accept -32 and +32
so then the seed/input whatever its called is not modified
Juan Blanco
@juanfranblanco
Sep 13 2017 10:02
your private keys are a biginteger
kai
@kaista82_twitter
Sep 13 2017 10:02
my only concern is
Juan Blanco
@juanfranblanco
Sep 13 2017 10:02
the issue is the magic of .net and little endians
kai
@kaista82_twitter
Sep 13 2017 10:02
oh ok, i was just worreid if it was changed from - to + then if you were to do the same process somewhere else the private key would generate a different public key
but yeah if its just .net stuff its no problems
Juan Blanco
@juanfranblanco
Sep 13 2017 10:03
mainy bytes
it gets prefixed with a 00
kai
@kaista82_twitter
Sep 13 2017 10:04
yeah i remember you mentioned it did that
Juan Blanco
@juanfranblanco
Sep 13 2017 10:04
but you have to use bouncy castle big integer
kai
@kaista82_twitter
Sep 13 2017 10:05
yeah I tried to do that the other day and it was complaining i just used .net version I think i need to convert that over anyways though ideally
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 10:08
i note if you use BC Big Int as a return type tho it throws. I needed system.numerics
Juan Blanco
@juanfranblanco
Sep 13 2017 10:13
oh yes
this is very a specific use case
kai
@kaista82_twitter
Sep 13 2017 10:14
ahh yeah that was it
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 10:14
cool
kai
@kaista82_twitter
Sep 13 2017 10:14
I think I got that too
I remember referencing it then it not working
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 10:14
so this should work to send 1ETH? BigInteger ethToSend = Nethereum.Util.UnitConversion.Convert.ToWei(1,Nethereum.Util.UnitConversion.EthUnit.Ether);
so many number types
kai
@kaista82_twitter
Sep 13 2017 10:15
you dont need the second param but yeah
that should work, I use that
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 10:40
hmm, give very odd numbers
I set the 2nd param just in case
Juan Blanco
@juanfranblanco
Sep 13 2017 10:40
what odd numbers?
kai
@kaista82_twitter
Sep 13 2017 10:41
ok, i only said as i think it defaults to ether
what version of the lib are you on ?
Juan Blanco
@juanfranblanco
Sep 13 2017 10:41
yes get the latest
kai
@kaista82_twitter
Sep 13 2017 10:41
yeah there was a slight issue with towei a couple versions ago
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 10:47
Owner balance should be 600,000,000, actual -8466944500
not sure if my cast back from my test is wrong
in mist, seems correct
Juan Blanco
@juanfranblanco
Sep 13 2017 10:48
what version are you using?
ill test it
kai
@kaista82_twitter
Sep 13 2017 10:49
lucas are you using from wei for that?
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 10:49
yeah, one sec guys
so my SC buy function looks like this:
function buyTokens() payable {

    uint amountInWei = msg.value;

    uint stage = getStage();
    uint price = prices[stage];
    uint tokenAmount = price * (amountInWei / 1 ether);

    require (balances[owner] >= tokenAmount);
    require (tokenAmount < (SALE_CAP - tokensSold));

    tokensSold += tokenAmount;
    balances[owner] -= tokenAmount;
    balances[msg.sender] += tokenAmount;

    //Raise event
    TokenPurchase(msg.sender, amountInWei, tokenAmount);
}
Works in mist
.net core looks like this
    public static async Task<String> Should_Buy_1ETH_Of_Tokens_From_Buyer()
    {
        var contract = GetContract(contractName);
        var functionToTest = contract.GetFunction("buyTokens");

        Nethereum.Hex.HexTypes.HexBigInteger gas = new Nethereum.Hex.HexTypes.HexBigInteger(2000000);
        BigInteger ethToSend = Nethereum.Util.UnitConversion.Convert.ToWei(1,Nethereum.Util.UnitConversion.EthUnit.Ether);
        Object[] functionParams = new Object[0];
        return await functionToTest.SendTransactionAsync(bob, gas, ethToSend, functionParams);
    }
result is as above
Juan Blanco
@juanfranblanco
Sep 13 2017 10:52
[Fact]
    public void ShouldConvertFromWeiLucas()
    {
        var unitConversion = new UnitConversion();
        var val = BigInteger.Parse("600000000");
        var result = unitConversion.FromWei(val, 18);
        var result2 = unitConversion.ToWei(val);
    }
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 10:52
price on stage[0] == 2500
Juan Blanco
@juanfranblanco
Sep 13 2017 10:52
try that ^^ what do you get?
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 10:52
xunit isnt working :(
dont know if its cause i upgraded to .netcore 2
Ill put in console, one sec
Juan Blanco
@juanfranblanco
Sep 13 2017 10:53
sure
you might need to upgrade
xunit
from wei i got: 0.0000000006
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 10:54
ok
Juan Blanco
@juanfranblanco
Sep 13 2017 10:54
towei 600000000000000000000000000
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 10:57
with xunit, it was odd, it kept trying to restore .net mono, not .net core
but thats another issue \
Juan Blanco
@juanfranblanco
Sep 13 2017 10:58
never had that, but I am running the tests on netcore 1.0 at the moment
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 11:01
ok
still looking, now im getting a too many params exception calling the buyToken function
kai
@kaista82_twitter
Sep 13 2017 11:04
if its ERC20 compat then StandardEIPTokenService is really useful btw
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 11:05
yeah
nah, my bad. Change the signature on the send function in .net. Needs a bighex, not big int
Juan Blanco
@juanfranblanco
Sep 13 2017 11:06
ah, then it got confused on the overload
Lucas Cullen
@bitcoinbrisbane
Sep 13 2017 11:06
ja
try again
*ill
Ruben Murillo
@Ru_Murillo_twitter
Sep 13 2017 17:21
Hello guys. I'm trying to pull out the logs of my ERC20 transfer event, so that I can list an account's previours transactions in the TestRPC. I understand I can do this by applying filters, but how can I interpret the results? I recognize two of the addresses in the Topics [], but how can I tell who sent what to who?
image.png
Ruben Murillo
@Ru_Murillo_twitter
Sep 13 2017 17:45
Ruben Murillo
@Ru_Murillo_twitter
Sep 13 2017 21:01
Hello guys. Any idea how can I convert a HexBigInteger.Value to DateTime? I'm trying to convert the Block's timestamp into a readable way :/
kai
@kaista82_twitter
Sep 13 2017 23:00
I would guess it's a unix timestamp in which case probably cast to int then put through a function to convert it to a c# datetime, but I'm not totally sure its a unix timestamp, but I can't imagine it being anything else
I think maybe this will work if it is:
static DateTime ConvertFromUnixTimestamp(double timestamp)
{
DateTime _origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return _origin.AddSeconds(timestamp);
}
Ruben Murillo
@Ru_Murillo_twitter
Sep 13 2017 23:02
You're right. The Block's timestamp represents the seconds since Unix epoch
private static DateTime ConvertHexBigIntegerToDateTime(HexBigInteger hexDate)
{
var time = (int)hexDate.Value;
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var date = epoch.AddSeconds(time);
        return date;
    }
kai
@kaista82_twitter
Sep 13 2017 23:02
excellent
Ruben Murillo
@Ru_Murillo_twitter
Sep 13 2017 23:02
Great! Thanks, @kaista82_twitter
kai
@kaista82_twitter
Sep 13 2017 23:02
np ;)