Ejemplo n.º 1
0
        public async Task <HttpResponseMessage> GetBalance(string address)
        {
            EtherAccount currentAccount = new EtherAccount()
            {
                publicAddress = address, balance = "-1"
            };

            try
            {
                // Connect to Web3
                var web3Client = new Web3(blockchainRPCEndpoint);

                var hexBalance = await web3Client.Eth.GetBalance.SendRequestAsync(address);

                currentAccount.balance = Convert.ToString(((hexBalance.Value) / (System.Numerics.BigInteger)Math.Pow(10, 18)));
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.StackTrace);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
            return(Request.CreateResponse <EtherAccount>(currentAccount));
        }
Ejemplo n.º 2
0
        public async Task <HttpResponseMessage> GetNewAccount(string password)
        {
            EtherAccount newAccount = new EtherAccount()
            {
                balance = "-1"
            };

            try
            {
                // Connect to Web3
                var web3Client     = new Web3(blockchainRPCEndpoint);
                var web3GethClient = new Web3Geth(web3Client.Client);

                newAccount.publicAddress = await web3GethClient.Personal.NewAccount.SendRequestAsync(password);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.StackTrace);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }

            return(Request.CreateResponse <EtherAccount>(newAccount));
        }