stoway / TronNet

.net sdk of tron
MIT License
69 stars 43 forks source link

How do I get TRX balance of an address? #11

Closed daustany closed 3 years ago

stoway commented 3 years ago
using TronNet;

namespace TronNetTest
{
    class Class1
    {
        private readonly IWalletClient _walletClient;

        public Class1(IWalletClient walletClient)
        {
            _walletClient = walletClient;
        }

        public async Task<decimal> GetBalanceAsync()
        {
            var protocol = _walletClient.GetProtocol();
            var address = "TGehVcNhud84JDCGrNHKVz9jEAVKUpbuiv";
            var addr = _walletClient.ParseAddress(address);

            var account = await protocol.GetAccountAsync(new TronNet.Protocol.Account
            {
                Address = addr
            });

            var balance = Convert.ToDecimal(account.Balance) / 1_000_000L;

            return balance;
        }
    }

}