public async Task <string> GetBalance(string scriptHash, string decimals)
        {
            string balance = string.Empty;

            var result = await GetTokenBalance.SendRequestAsync(scriptHash);

            if (result != null)
            {
                balance = result.Stack[0].Value.ToString();
                var supplyValueArray = balance.HexToBytes().Reverse().ToArray(); // todo, add explanation for this
                balance = BitConverter.ToString(supplyValueArray).Replace("-", "");
                balance = GetDecimal(HexToBigInteger(balance), (int)DecimalStringToBigInteger(decimals));
            }
            return(balance);
        }
예제 #2
0
        public async Task <decimal> GetBalance(string tokenScriptHash, string addressScriptHash, int decimals = 0)
        {
            var result = await GetTokenBalance.SendRequestAsync(addressScriptHash, tokenScriptHash);

            if (result.State == "FAULT, BREAK")
            {
                throw new RpcResponseException(new RpcError(0, "RPC state response: FAULT, BREAK "));
            }

            var balanceBigInteger = new BigInteger(result.Stack[0].Value.ToString().HexStringToBytes());

            if (decimals.Equals(0))
            {
                return((decimal)balanceBigInteger);
            }

            var balance = Nep5Helper.CalculateDecimalFromBigInteger(balanceBigInteger, decimals);

            return(balance);
        }
예제 #3
0
        public async Task <string> GetBalance(string addressScriptHash)
        {
            var result = await GetTokenBalance.SendRequestAsync(addressScriptHash).ConfigureAwait(false);

            return(result.Stack[0].Value.ToString());
        }