Search code examples
bitcoinbitcoinj

Bitcoinj - create temporary walllet


I'm new in bitcoin.

I need to create something like a temporary bitcoin wallet for the currency exchange app. The wallet should be alive just one exchange transaction or 2 days(if the transaction wouldn't confirmed) and then should be removed. But as I understand right from bitcoin docs - I cannot remove a wallet, because it is sort a "public key".

Any suggestions?


Solution

  • A 'wallet' doesn't actually really exist. All it is, is a collection of private keys (or just one private key that can be used to derive other keys from, like HD wallets do). These private keys allow you to spend the unspent output (UTXO), thus make a transaction.

    These private keys are used to generate public keys, and from those the addresses are generated. You can't remove these addresses because they just exist. In fact, every address already exists, you just need the private key to access them.

    Removing things from the blockchain wouldn't make sense anyway, the blockchain is literally a chain of blocks, each block being a container filled with transactions. If you would remove a transaction from a block, all the following blocks would become invalid because the hash of your block's merkle tree would no longer add up.


    That being said, you may want to look into HD wallets. You could do something like this (see BIP44):

    m / purpose' / coin_type' / account' / change / address_index
    

    Here you can use an incrementing ID for account, so that each use has his own account. You can then create a new address for each incoming payment (change = 0 for inbound external transactions, change 1 = for change coming from your own wallet).

    This means that each payment/whatever will have its own address. Because it's a HD wallet you can still access all the addresses with the master key if you like.