2

How can I get balance instantly when I have blockchain data synchronized and with the spend and view secret keys on hand.

  • Are you using somekind of wallet? normally there is a balance function... or do you want to know how to find outputs directly for your private view key? – onefox Aug 30 '18 at 10:01
  • I am reading cryptonote code, but I found it is very tricky to get balances for a certain address. I want to know how can I get balances for every address with secret keys. – Bai Lee Aug 30 '18 at 10:17
1

In CryptoNote you can't just get a balance for an address since CryptoNote uses one time addresses or stealth addresses.

Because of that, in order to get your balance you have to scan all transactions on the blockchain. You need to check each output if you can access it with your private view key.

Because of that, there is no easy way to get the whole balance without such scanning.

What you have to do is basically create a view wallet with your private view key and let it scan the whole blockchain for you. After the scan is done you can access the balance via a JSON RPC. In order to speed up the process you can also give the wallet a starting height. For example, the scanning should start at the block where you sent your first coins to the address.

This is how it works for Monero and it should be true for some other CryptoNote coins.

What the simplewallet does (wallet2.cpp) is it gets all the blocks and pruned transaction data and starts generating a key derivation for each transaction and checks whether the transaction belongs to it.

If you want to go even more in to detail, I would read the follwing blog post: https://steemit.com/monero/@luigi1111/understanding-monero-cryptography-privacy-part-2-stealth-addresses

  • thanks. but wallet2.cpp is greatly different from cryptonote/simplewallet.cpp now. I would like to fork from monero, but it would be hard for me right now. – Bai Lee Aug 30 '18 at 19:50
  • but i think the concept is still very simular if you look at: github.com/cryptonotefoundation/cryptonote/blob/… – onefox Aug 30 '18 at 21:42
  • thank you. what does parameter out mean? in bool findOutputsToAccount(const CryptoNote::TransactionPrefix& transaction, const AccountPublicAddress& addr, const SecretKey& viewSecretKey, std::vector<uint32_t>& out, uint64_t& amount) and how can i get the transaction ? – Bai Lee Aug 31 '18 at 9:26
  • out is just a pointer to a object that is giving into the function. It modifies the object, you could think of it as another way of returning something. The function findOutputsToAccount is only a TransactionUtils and not called in the code exept from the test. It is going a little bit deep. github.com/cryptonotefoundation/cryptonote/blob/… I think this is the real function that is used for the output check.You have to follow the trace up from there. It does almosed the same as wallet2 from monero. – onefox Sep 2 '18 at 0:11
  • thank you @onefox. I have read through the simplewallet source code. but I found the amount is saved in the cache, And I don't know how to create the cached is there is no cache only with keys. Is there a way to retrieve balances from the blockchain by provide a view key? – Bai Lee Sep 2 '18 at 14:06

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.