These are chat archives for Nethereum/Nethereum

2nd
May 2018
Enigmatic
@EnigmaticUnreal_twitter
May 02 2018 03:24
@Pzixel - Use CallDeserializingToObjectAsync. Something like this.
multipleReturns = Await contract.GetFunction("getStatusUpdate").CallDeserializingToObjectAsync(Of StatusUpdateStruct)(index)
Example in VB*
Kirankumar
@kiranbasvaraj
May 02 2018 06:20
hi juan,
i tried this for converting the string to hex string and i passed the hex string as input to the abi but again i am getting same exception
as {System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds}
my abi inputs is this ""inputs"": [
{
""name"": ""WalletAddres"",
""type"": ""address""
},
{
""name"": ""Name"",
""type"": ""bytes32""
}]
Psilon
@Pzixel
May 02 2018 06:57
@EnigmaticUnreal_twitter ty, it works
Juan Blanco
@juanfranblanco
May 02 2018 08:27
@Pzixel try the code generator it will help you lots
and thanks @EnigmaticUnreal_twitter you are a star
@kiranbasvaraj no the idea is to use a byte[] instead
that will be the 32 bytes if you are passing a hash that will fit in the 32 byte array (that is what bytes32 is)
Enigmatic
@EnigmaticUnreal_twitter
May 02 2018 11:22
Ah... You're welcome Juan. Just sharing what I've learnt from you with others. =)
nibirc
@nibirc
May 02 2018 12:28
Hi, I am facing problem with Token Transfer using nethereum.
Here is my code:

public static Web3 web3 = new Web3("https://rinkeby.infura.io/u0m3xwaBzAXaImwFpigV");
public static string abi = "";//contains actual abi in code
public static string contractAddress = "";//contains actual address in code
public static string Account1 = "";//contains actual address in code
public static string Account1PK = "";//contains actual PK in code
public static string Account2 = "";//contains actual address in code
static void main()
{
Account ac = new Account(Account1PK);
TokenService.web3= new Web3(ac,"https://rinkeby.infura.io/u0m3xwaBzAXaImwFpigV");
TokenService.abi = abi;
TokenService.contractAddress = contractAddress;
TokenService.Initialize();

TransferFunction tf = new TransferFunction()
{
FromAddress=Account1,
To = Account2,
TokenAmount = 100
};

var res = TokenService.TransferAsync(tf).Result;
}

TarrahArshad
@TarrahArshad
May 02 2018 12:29
@juanfranblanco how to we can reject Ether in payable contractor contract ?
nibirc
@nibirc
May 02 2018 12:29
And here is my Token Service Class and other classes:

using System.Numerics;
using System.Threading.Tasks;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using Nethereum.Contracts.CQS;
using Nethereum.Hex.HexTypes;
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Web3;

namespace NethereumAPI
{
public static class TokenService
{
public static Web3 web3 { get; set; }
public static string abi { get; set; }
public static string contractAddress { get; set; }
static Contract contract { get; set; }
static ContractHandler contractHandler { get; set; }
static TokenService()
{

    }

    public static void Initialize()
    {
        contract = web3.Eth.GetContract(abi, contractAddress);
        contractHandler = web3.Eth.GetContractHandler(contractAddress);
    }

    #region Total Supply
    public static async Task<TNumber> GetTotalSypplyAsync<TNumber>()
    {
        var function = GetTotalSupplyFunction();
        return await function.CallAsync<TNumber>();
    }
    static Function GetTotalSupplyFunction()
    {
        return contract.GetFunction("totalSupply");
    }
    #endregion

    #region BalanceOf
    public static async Task<T> GetBalanceOfAsync<T>(string address)
    {
        var function = GetBalanceOfFunction();
        return await function.CallAsync<T>(address);
    }
    static Function GetBalanceOfFunction()
    {
        return contract.GetFunction("balanceOf");
    }
    #endregion

    #region Allowance
    public static async Task<T> GetAllowanceAsync<T>(string addressOwner,string addressSpender)
    {
        var function = GetAllowanceFunction();
        return await function.CallAsync<T>(addressOwner, addressSpender);
    }
    static Function GetAllowanceFunction()
    {
        return contract.GetFunction("allowance");
    }
    #endregion

    #region Transfer
    public static async Task<string> TransferAsync<T>(string addressFrom, string addressTo, T value)
    {
        var function = GetTransferFunction();
        var gas = await function.EstimateGasAsync(addressFrom, null, null, addressTo, value);
        return await function.SendTransactionAsync(addressFrom, gas, null, addressTo, value);
    }

    static Function GetTransferFunction()
    {
        return contract.GetFunction("transfer");
    }        

    public static async Task<string> TransferAsync(TransferFunction transferMessage)
    {
        return await contractHandler.SendRequestAsync(transferMessage).ConfigureAwait(false);
    }
    #endregion
    public static async Task<TransactionReceipt> TransferAndWaitForReceiptAsync(TransferFunction transferMessage)
    {
        return await contractHandler.SendRequestAndWaitForReceiptAsync(transferMessage).ConfigureAwait(false);
    }

    #region Transfer From
    public static async Task<string> TransferFromAsync<T>(string addressFrom, string addressTransferedFrom, string addressTransferedTo, T value, HexBigInteger gas)
    {
        var function = GetTransferFromFunction();
        return await function.SendTransactionAsync(addressFrom, gas, null, addressTransferedFrom, addressTransferedTo, value);
    }

    static Function GetTransferFromFunction()
    {
        return contract.GetFunction("transferFrom");
    }
    #endregion

    #region Approve
    public static async Task ApproveAsync<T>(string addressFrom, string addressSpender, T value, HexBigInteger gas = null)
    {
        var function = GetApproveFunction();
        await function.SendTransactionAsync(addressFrom, gas, null, addressSpender, value);
    }

    static Function GetApproveFunction()
    {
        return contract.GetFunction("approve");
    }
    #endregion
This is the error I am getting: {"Response status code does not indicate success: 405 (Method Not Allowed)."}
I am able to retrieve total balance and balance of individual account using the functions defined in TokenService Class
Pari Hoxha
@phoxha
May 02 2018 12:34
What is the best test environment for my development with Nethereum? I tried running the testchain using latest geth and other versions as well but could not make it work. Now I am using metamask but want to be more independent. Any suggestions?
Juan Blanco
@juanfranblanco
May 02 2018 12:36
@TarrahArshad where you connecting and how are you initialising Web3? Mainly are you using an Account(privateKey) ?
@phoxha we personally use any of the test chains in here https://github.com/Nethereum/TestChains
depends on your needs
Pari Hoxha
@phoxha
May 02 2018 12:40
@juanfranblanco thank you. Will I need to download anything else to run the test chain? Do I need Parity (dont even know what it supposed to do lol)?
Juan Blanco
@juanfranblanco
May 02 2018 12:55
the chain executables are included
but it is recommend you replace them with the official ones (as they might be out of date)
nevertheless they are there
pick your client implementation
ie geth
open the folder
and run the batch file
Pari Hoxha
@phoxha
May 02 2018 12:56
just did
seems to work ok now
nibirc
@nibirc
May 02 2018 12:56
@juanfranblanco , Sir can you please comment on the issue I am facing?
Juan Blanco
@juanfranblanco
May 02 2018 12:56
there yo ugo
Pari Hoxha
@phoxha
May 02 2018 12:57
thank you
Juan Blanco
@juanfranblanco
May 02 2018 12:57
@nibirc sorry the comment was meant for you "where are you connecting to? and how are you initialising Web3? Mainly are you using an Account(privateKey) ?
nibirc
@nibirc
May 02 2018 12:58
@juanfranblanco , Sir, I am connecting to Rinkeby test chain.
Juan Blanco
@juanfranblanco
May 02 2018 12:59
ok are you using your private key to create an Account?
nibirc
@nibirc
May 02 2018 12:59
Yes
Juan Blanco
@juanfranblanco
May 02 2018 12:59
is your Account part of Web3?
nibirc
@nibirc
May 02 2018 12:59
yes.
Account ac = new Account(Account1PK);
Juan Blanco
@juanfranblanco
May 02 2018 13:00
ie.. new Web3(new Account(PrivateKey), "https://...ecte");
nibirc
@nibirc
May 02 2018 13:00
TokenService.web3= new Web3(ac,"https://rinkeby.infura.io/u0m3xwaBzAXaImwFpigV");
I am able to do the transfer of my token using Ethereum wallet.
Ethereum wallet app i mean
And using my code as written in the TokenService class, I am able to get the total supply and Token balance of individual account also.
Juan Blanco
@juanfranblanco
May 02 2018 13:03
I don't see anything wrong with the code at plain sight
a part from all the static stuff that should not be an issue
you should not get the 405 method not allowed
if you are creating the Account
using your private key
it would be an issue if you are trying to unlock your account
or something like that using your password
or using a ManagedAccount
mainly personal stuff
nibirc
@nibirc
May 02 2018 13:13
I have tried with ManagedAccount and Account with private key. Both are giving me same error.
Juan Blanco
@juanfranblanco
May 02 2018 13:13
you don't need the ManagedAccount
nibirc
@nibirc
May 02 2018 13:14
OK, sir. Can I share my whole VS solution with you?
I am using the nethereum package from Nuget V2.4
Juan Blanco
@juanfranblanco
May 02 2018 13:16
this is related to rinkeby
and infura
the method not allowed it is an ethereum rpc method that you are using that is not allowed
those are normally personal stuff
as infura does not have your keys
your current api
will do a simple send raw transaction
signing with your private key
so it should be fine
nibirc
@nibirc
May 02 2018 13:18
Sir, please point me to some code example.
Juan Blanco
@juanfranblanco
May 02 2018 13:19
there is no code example
it is the same
fyi
nibirc
@nibirc
May 02 2018 13:22
OK, Sir. Thank you so much. Just one more question, if I use Geth to make my development system as a node for Rinkeby and connect to local host in my c# code, will the problem be solved?
Juan Blanco
@juanfranblanco
May 02 2018 13:22
you could do that
it will be more decentralised
but.. it will be better to understand what method you are using that is not allowed
nibirc
@nibirc
May 02 2018 13:24
Yes, I am going through the link you have provided and the corresponding allowed function list there.
Enigmatic
@EnigmaticUnreal_twitter
May 02 2018 13:37

@nibirc - Assuming iweb3 is initialised properly, you could refer to the below code (in VB though) which I've just tested over Rinkeby.

Does your code trigger any form of transaction onto Rinkeby?

Dim value = New HexBigInteger(0)
Dim gas = New HexBigInteger(3000000)
contract = iweb3.Eth.GetContract(TokenAbi, contractAddress)

Dim amtToSend As BigInteger = 0
BigInteger.TryParse("100000000000000000000", amtToSend)
Dim transferFunction = contract.GetFunction("transfer")
Dim transactionHash = Await transferFunction.SendTransactionAsync(account.Address, gas, value, "0x6458EaFC3076F104a25492552DDF98f224813348", amtToSend)
'Dim transactionHash = Await transferFunction.SendTransactionAndWaitForReceiptAsync(account.Address, gas, value, , "0x6458EaFC3076F104a25492552DDF98f224813348", amtToSend)
nibirc
@nibirc
May 02 2018 13:40
@EnigmaticUnreal_twitter Yes, I am using similar code in c#
But I am not using my own node, rather have used one url provided by infura
TarrahArshad
@TarrahArshad
May 02 2018 13:50
@juanfranblanco this is my contract
 /**
    * Fallback function which receives ether and created the appropriate number of tokens for the 
   * msg.sender.
   */
function() external isUnderLimitation payable {
    //If we can not purchase tokens presale then try purchase them normally
    if ( now < start ) {
        purchaseTokensPreSale(msg.sender);
    } else {
        purchaseTokens(msg.sender);
    }
}
how to reject ether client sent to this contract ?
Steven
@code-sergeant
May 02 2018 17:59
Has anyone run into the error when trying to send rpc requests and the HttpRequestException says that the Response status code does not indicate success: 405 (method not allow)
Output is as follows:
The thread 0x6604 has exited with code 0 (0x0).
Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll
Exception thrown: 'Nethereum.JsonRpc.Client.RpcClientUnknownException' in Nethereum.JsonRpc.RpcClient.dll
Exception thrown: 'Nethereum.JsonRpc.Client.RpcClientUnknownException' in mscorlib.dll
Exception thrown: 'Nethereum.JsonRpc.Client.RpcClientUnknownException' in mscorlib.dll
Exception thrown: 'Nethereum.JsonRpc.Client.RpcClientUnknownException' in mscorlib.dll
Exception thrown: 'Nethereum.JsonRpc.Client.RpcClientUnknownException' in mscorlib.dll
An unhandled exception of type 'Nethereum.JsonRpc.Client.RpcClientUnknownException' occurred in mscorlib.dll
Error occurred when trying to send rpc requests(s)
Stack trace is as follows:
at Nethereum.JsonRpc.Client.RpcClient.<SendAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Nethereum.JsonRpc.Client.RpcClient.<SendInnerRequestAync>d__12`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Nethereum.JsonRpc.Client.ClientBase.<SendRequestAsync>d__4`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at OldConsoleProjectReference.Program.<DemoDeployContract>d__2.MoveNext() in C:\Sabio\Blockchain\Nethereum\NewConsoleAppSample\ConsoleAppNethereumSample\OldConsoleProjectReference.cs\Program.cs:line 137
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at OldConsoleProjectReference.Program.Main(String[] args) in C:\Sabio\Blockchain\Nethereum\NewConsoleAppSample\ConsoleAppNethereumSample\OldConsoleProjectReference.cs\Program.cs:line 25
Psilon
@Pzixel
May 02 2018 18:18
Parity guys suggested to upgrade my network to byzantium
is Nethereum ok with it?
Enigmatic
@EnigmaticUnreal_twitter
May 02 2018 19:17
@Pzixel - Yes it works. Had been developing on Ropsten/Rinkeby which were already byzantium compatible.
Psilon
@Pzixel
May 02 2018 19:19
Nice to hear it
I'l try to upgrade tomorrow then