public async Task <decimal> GetTotalSupply(string tokenScriptHash, int decimals = 8) { var result = await GetTokenTotalSupply.SendRequestAsync(tokenScriptHash); if (result.State == "FAULT, BREAK") { throw new RpcResponseException(new RpcError(0, "RPC state response: FAULT, BREAK ")); } var totalSupplyBigInteger = new BigInteger(result.Stack[0].Value.ToString().HexStringToBytes()); if (decimals.Equals(0)) { return((decimal)totalSupplyBigInteger); } var totalSupply = Nep5Helper.CalculateDecimalFromBigInteger(totalSupplyBigInteger, decimals); return(totalSupply); }
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); }