These are chat archives for Nethereum/Nethereum

22nd
Oct 2018
Pistol Star
@PistolStar_twitter
Oct 22 2018 05:16

Hello,

I’m trying to transfer Ether one account to another on Unity.

I’ve got following logs for this

{"jsonrpc":"2.0","id":1,"result":"0x6118"}
gasEstimate: 24856
{"jsonrpc":"2.0","id":1,"result":"0x0"}
{"jsonrpc":"2.0","id":1,"result":"0xaf9fa21e29c3c2b5ac379b6b2ed7d09d2990cf01130c71b251b92790496e77d2"}
Transfered tx created: 0xaf9fa21e29c3c2b5ac379b6b2ed7d09d2990cf01130c71b251b92790496e77d2

It seems works fine ,but The TxHash does not appear on EtherScan and no transfer happens with these accounts.

Can you please give some hints for this? I’m new to Nethereum integration.

Here is my code i’m using.

'''
public IEnumerator Exec(string fromKey,string toAddr, string sendNum, System.Action<string> callback)
 {

 PingTokenContractService pingTokenContractService = new PingTokenContractService(toAddr);
 string accountAddress = Nethereum.Signer.EthECKey.GetPublicAddress(fromKey);

 var transactionSignedRequest = new TransactionSignedUnityRequest("https://mainnet.infura.io", fromKey, accountAddress);

 //Estimate gas price
 BigInteger gas;

 Function function = pingTokenContractService.contract.GetFunction ("transfer");
 var input = function.CreateTransactionInput (accountAddress, toAddr, sendNum);
 var gasRequest = new EthEstimateGasUnityRequest ("https://mainnet.infura.io");
 yield return gasRequest.SendRequest (input);
 if (gasRequest.Exception == null) {
 gas=gasRequest.Result.Value;

 Debug.Log ("gasEstimate: " + gasRequest.Result.Value);
 } else {
 callback(gasRequest.Exception.ToString());
 yield break;
 }


 var transactionInput = pingTokenContractService.CreateTransferInput(
 accountAddress,
 toAddr,
 new HexBigInteger(gas), 
 new HexBigInteger(190),
 new HexBigInteger(Nethereum.Util.UnitConversion.Convert.ToWei(sendNum))
 );

 yield return transactionSignedRequest.SignAndSendTransaction(transactionInput);

 if (transactionSignedRequest.Exception == null)
 {
 callback(transactionSignedRequest.Result);
 Debug.Log("Transfered tx created: " + transactionSignedRequest.Result);

 }
 else
 {
 callback(transactionSignedRequest.Exception.Message);
 }
 }
'''

Thank you and sorry for my poor english.

Twilight Punkster
@twilightpunkster
Oct 22 2018 06:53
how do I do web3.eth.abi.encodeParameter in Nethereum (using Unity)
Twilight Punkster
@twilightpunkster
Oct 22 2018 07:14
This is super frustrating. I get for the same string using ab.encodeParameter(x) and SoliditySha3 with web3 and get: 0x2db70b196729038e05061a1460db2790ce16bb543e39c73253d349dd15fa3535, yet with Unity using StringTypeEncoder I get 0xb81ff6c12fea029986f602c1a63a434a5918c5197c23241cf47a148a40360cae, with Nethereum.Util.Sha3Keccack.CalculateHash(x).ToHex()
And I have to prefix it with a 0x
Juan Blanco
@juanfranblanco
Oct 22 2018 08:15
@twilightpunkster can you put a sample of the actual string you are encoding?
and the code?
also what are you trying to so with an sha3 and abi parameter encode?
@PistolStar_twitter are you trying to trasfer Ether or a token?
this is a sample for token transfer
and this this a sample for Ether transfer
hopefull that helps
Juan Blanco
@juanfranblanco
Oct 22 2018 08:33
on the cryptokitties is yet another experiment https://medium.com/@simondlr/radical-markets-in-the-arts-13c27d3b7283
but IMHO some experiments are so far from reality that kind of not make sense
Twilight Punkster
@twilightpunkster
Oct 22 2018 08:38
@juanfranblanco I am trying to port:
const hashParam = (value, type) => soliditySha3(abi.encodeParameter(type, value));
const hashParams = (values, types) => values.map((value, index) => hashParam(value, types[index]));
Juan Blanco
@juanfranblanco
Oct 22 2018 08:39
so what are the values
there was an issue already discussed for this..
Twilight Punkster
@twilightpunkster
Oct 22 2018 08:40
I've to work with a 3rd party library that requires that part.
    StringTypeEncoder abiStrEnc = new StringTypeEncoder();
    AddressTypeEncoder abiAddrEnc = new AddressTypeEncoder();
    IntTypeEncoder abiUintEnc = new IntTypeEncoder();
    DynamicArrayTypeEncoder abiDATEnc = new DynamicArrayTypeEncoder(Nethereum.ABI.ABIType.CreateABIType("bytes32"));

    byte[] name = abiStrEnc.Encode(asset.name); 
    byte[] desc = abiStrEnc.Encode(asset.desc); 
    byte[] image = abiStrEnc.Encode(asset.image); 
    byte[] cap = abiUintEnc.Encode(asset.cap);
    byte[] rarity = abiUintEnc.Encode(asset.rarity);
    byte[] addr = abiAddrEnc.Encode(asset.gameAddr);
    byte[] nonce = abiUintEnc.Encode(asset.nonce);

    var sha3 = new Nethereum.Util.Sha3Keccack();
    var s1 = "0x" + sha3.CalculateHash(name).ToHex(); 
   // ...
abi.encodeParameter() does the magic for me, with Nethereum it seems I have to pick the encoder
Juan Blanco
@juanfranblanco
Oct 22 2018 08:48
this might help
and yes you do need pick the encoder in Nethereum
feel free to create an issue
if you do ToHex(true) that will include the prefix
Juan Blanco
@juanfranblanco
Oct 22 2018 08:56
in a similar way you have done ...
Nethereum.ABI.ABIType.CreateABIType("bytes32")
you can do Nethereum.ABI.ABIType.CreateABIType("bytes32").Encode()
so the shortcuts are nearly the same..
Twilight Punkster
@twilightpunkster
Oct 22 2018 10:32
web3.eth.accounts.sign ( with the message and signature ), is this something else than the MessageSigner?
Juan Blanco
@juanfranblanco
Oct 22 2018 10:32
that is the message signer of the client itself
the other is Nethereum providing the same offline functionality
Twilight Punkster
@twilightpunkster
Oct 22 2018 10:36
I mean more like, whats the Nethereum version of web3.eth.accounts.sign
the web3.eth.accounts.HashAndSign can take two strings
EthereumMessageSigner.cs has only HashAndSign(byte[] plainMessage, EthECKey key)
Juan Blanco
@juanfranblanco
Oct 22 2018 10:40
You have one with the prefix and another without it. EtheremSigner is the one with the prefix
I don't know about the javascript one
just follow the spec
you have EthereumSigner.. with prefix
and MessageSigner without prefix
for Ethereum Web3.Personal.Sign you will use your message and password to unlock your private key
Twilight Punkster
@twilightpunkster
Oct 22 2018 10:44
found it
thanks
Juan Blanco
@juanfranblanco
Oct 22 2018 10:44
cool :D
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:12
Nethereum.Signer.EthereumMessageSigner with EncodeUTF8AndSign() creates a signature, but it differs from web3.eth.accounts.sign()
that might help you
see without a full sample it is a bit hard to see what you are doing :), but I assume that is your issue
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:28
the whole sample is web3.eth.accounts.sign(), taking a message (nothing more than a hash from a bunch of byte arrays) and the private key, both as strings.
Juan Blanco
@juanfranblanco
Oct 22 2018 11:28
i mean your .net code
so if you have a hash
you don't want to utf8 encode it
it is a string
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:29
Nethereum.Signer.EthereumMessageSigner signer = new Nethereum.Signer.EthereumMessageSigner();
        var sig = signer.EncodeUTF8AndSign(hashedAsset.hash.ToString(), new EthECKey("0x4894388438439543895438834fake"));
Juan Blanco
@juanfranblanco
Oct 22 2018 11:29
you just want to use HexToByteArray()
so your other option will be...
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:30
burn everything
I can't be the only one who uses web3.eth.accounts.sign
maybe the problem is the options :)
var sig = signer.Sign(hash.HexToByteArray(), "privateKey");
or if you wan to have it hashed for you
mainly Javascript does some magic, a hex string is treated as a byte array
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:35
yes, I read that on the page you posted earlier.
I make games, so this is far out of my comfort zone
Juan Blanco
@juanfranblanco
Oct 22 2018 11:36
don't get me started with Go and its magic :)
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:36
I love Go.
:)
translate to that to Go, well backwards
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:38
I can look at all those parts, but I'm fried :) but those are mostly the meds and sleep deprivation.
Juan Blanco
@juanfranblanco
Oct 22 2018 11:38
sorry just confusing you
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:38
no worries. This is the last difficult part I need to get working
Juan Blanco
@juanfranblanco
Oct 22 2018 11:38
mainly just use signer.Sign()
with your byte array
from the hash
that will be probably it
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:39
I have to follow guidelines for a SDK
Juan Blanco
@juanfranblanco
Oct 22 2018 11:39
var sig = signer.Sign(hash.HexToByteArray(), "privateKey");
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:39
the signing part is essential for trading :)
Juan Blanco
@juanfranblanco
Oct 22 2018 11:39
yeah
i got you
once you got the format right, you are sorted anyway
if you are using hashes, use the byte array
if you are using strings use UTF8
and get the byteArray
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:41
I am using strings, the hash is from a json
Juan Blanco
@juanfranblanco
Oct 22 2018 11:42
but you are still hashing it first and then signing it
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:44
Unity is angry
'string' does not contain a definition for 'HexToByteArray'
Juan Blanco
@juanfranblanco
Oct 22 2018 11:45
that is an extension for string
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:45
var sig = signer.Sign(hashedAsset.hash.HexToByteArray(), "0xPrivateKey");
Juan Blanco
@juanfranblanco
Oct 22 2018 11:45
using Nethereum.Hex.HexConvertors.Extensions;
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:46
got that one already.
Juan Blanco
@juanfranblanco
Oct 22 2018 11:46
so you should have that for string
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:58
finallllly
Juan Blanco
@juanfranblanco
Oct 22 2018 11:58
:)
Twilight Punkster
@twilightpunkster
Oct 22 2018 11:59
the culprit was dynamic
Juan Blanco
@juanfranblanco
Oct 22 2018 11:59
you used dynamics?
Twilight Punkster
@twilightpunkster
Oct 22 2018 12:00
I have to
Juan Blanco
@juanfranblanco
Oct 22 2018 12:00
for signing?
Twilight Punkster
@twilightpunkster
Oct 22 2018 12:00
99.9% is not my code
no, to get stuff back :) long complex story
Juan Blanco
@juanfranblanco
Oct 22 2018 12:00
sure.. don't worry.. but I see how things could get messed up quickly
also if you use dynamics if you are using AOT compilation you will get into problems
Twilight Punkster
@twilightpunkster
Oct 22 2018 12:03
AOT is for phones right?
afaik, I am not using it.
Juan Blanco
@juanfranblanco
Oct 22 2018 12:03
yeah most ly
Twilight Punkster
@twilightpunkster
Oct 22 2018 12:03
No IL2CPP
Juan Blanco
@juanfranblanco
Oct 22 2018 12:03
webgl
Twilight Punkster
@twilightpunkster
Oct 22 2018 12:03
no WebGL
Juan Blanco
@juanfranblanco
Oct 22 2018 12:04
yep IL2CPP
Twilight Punkster
@twilightpunkster
Oct 22 2018 12:04
just Desktop, Playstation, Xbox and Switch
Juan Blanco
@juanfranblanco
Oct 22 2018 12:04
cool :)
Twilight Punkster
@twilightpunkster
Oct 22 2018 12:04
and Playstation works fine :P
Juan Blanco
@juanfranblanco
Oct 22 2018 12:04
awesome!!! :D
Sergio Piedrahita
@spied001
Oct 22 2018 18:04
@juanfranblanco is there a way to compile contracts through nethereum?
Juan Blanco
@juanfranblanco
Oct 22 2018 21:23
used to be by it has been removed from the clients, I have some interop with the compiled solidity but is not in a good state yet
so no / not yet.. although it won't be very portable, would need some work to work on mobiles
Sergio Piedrahita
@spied001
Oct 22 2018 22:08
ok, I have been running into some weird exceptions, this is what I am doing, I compile the contracts through visual studio code, I then read the ABI and Bytecode from the .abi and .bin file, I am able to deploy the contracts calling web3.Eth.DeployContract.SendRequestAsync(contractAbi, contractByteCode, contractOwnerAddress), but then when I try to interact with the contracts at the time when I calculate the gas before sending a transaction I get gas required exceeds allowance or always failing transaction. If I compile and deploy through truffle and then try to interact with the contracts everything works fine.
if I compile with truffle and the try to deploy by calling web3.Eth.DeployContract.SendRequestAsync(contractAbi, contractByteCode, contractOwnerAddress) I get the same exception but this time I get it when trying to deploy the contract not when trying to interact with the contract after deployment