2

I am trying to develop a simple program where I am able to generate an address successfully using a public key and a stake key. The network type is TestNet.

How can I check the balance of the generated address?

Code snippet is as follow:

var existingaddresses = _Addresses.Find(x => x.WalletId == wallet.Id).ToList().Count;
            var user = _users.Find(x => x.Id == wallet.UserId).FirstOrDefault();
            NetworkType net;
            if (IsMainNet)
            {
                net = NetworkType.Mainnet;
            }
            else
            {
                net = NetworkType.Testnet;
            }
            Mnemonic mnc = keyService.Restore(wallet.Words, WordLists.English);
            PrivateKey masterKey = mnc.GetRootKey(user.Password);
            string PaymentPath = $"m/1852'/1815'/0'/0/"+ existingaddresses;
            PrivateKey paymentPrv = masterKey.Derive(PaymentPath);
            PublicKey paymentPub = paymentPrv.GetPublicKey(false);
            string stakePath = $"m/1852'/1815'/0'/2/"+existingaddresses;
            PrivateKey stakePrv = masterKey.Derive(stakePath);
            PublicKey stakePub = stakePrv.GetPublicKey(false);

            Address address = addressService.GetAddress(paymentPub, stakePub, net, AddressType.Base);

Now I want to check the balance of the generated address.

1 Answer 1

1

You can use the Blockfrost.io API to get information about the address. I'd recommend using the blockfrost-dotnet package for this.

4
  • I have tried it but i am getting content not found exception which means this Address doesnot exist on test net. Isnt it? What can be the reason? Oct 12, 2021 at 5:23
  • I think this happens if the address has never been used.
    – eddex
    Oct 12, 2021 at 6:31
  • agreed. as address is never used. Any idea what can be done to activate the address on testnet? Oct 13, 2021 at 7:32
  • 1
    Send some tADA to that address: testnets.cardano.org/en/testnets/cardano/tools/faucet
    – eddex
    Oct 13, 2021 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.