Skip to content

Proof of concept of how to use Bitcoinj (bitcoin client) and Bitcoin cash variant

License

Notifications You must be signed in to change notification settings

Zurvarian/bitcoin-java-101

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to run

Run mvn spring-boot:run in your terminal

How to see the api

Type http://localhost:8080/swagger-ui.html in your browser

Testing accounts

I've included a testing wallet with Testnet funds to allow people to try out-of-the-box.

To utilize them, use PUT /wallet/unlock to load them into the in-memory map.

Mind it is a testing account in a Test network, i.e.: there is no point in stealing those funds :P

Api Usage

Transaction Send

  1. Use GET /wallet/mnemonic to get a new Mnemonic seed, try to save those, as they will help you to recover the wallet in case of need.
  2. Use POST /wallet to register a new Wallet (It requires the mnemonics from previous step)
  3. Use PUT /wallet/{walletId}/transaction/send to create and send a new Transaction.
  4. Check the logs to see if the transaction is confirmed by a block, or just do polling on GET /transaction/{transactionId} until it contains blockHash and blockNumber attributes

Transaction Create and Broadcast

An alternative to the previous way of creating transactions is via GET /wallet/{walletId}/transaction/create that will return a valid transaction, in case the user wants to verify the Fee cost.

Once it has been validated, the transaction can be send with PUT /wallet/{walletId}/transaction/broadcast

Unfortunately, BitcoinJ won't accept this transaction directly, only the outputs of it, so as much you can use Broadcast with the outputs of the transaction and, finger-crossed, the inputs will be the same :X

Wallet with Mnemonics

  1. Use GET /wallet/mnemonic to obtain a list of mnemonic words.
  2. Use POST /wallet to create a Wallet using the mnemonic words.
  3. Use GET /wallet/{walletId} to get details of a wallet.

Wallet Unlock

  1. Use PUT /wallet/unlock/{walletId} to unlock an existing Wallet.

    Unlock allows you to load an existing wallet file from the file system, could be any wallet created by this tool or created by any other tool using BitcoinJ.

  2. Use GET /wallet/{walletId} to get details of a wallet.

Wallet's balance

  1. Use GET /wallet/mnemonic to obtain a list of mnemonic words.
  2. Use POST /wallet to register a new Wallet
  3. Use GET /wallet/{walletId}/balance to see the wallet's balance in ETHER

Payment Protocol

This tool includes a self-contained (Client and Server present) example of how to use Payment-Protocol.

  1. Use GET /wallet/mnemonic to obtain a list of mnemonic words.

  2. Use POST /wallet/mnemonic to create a Wallet using the mnemonic words.

    Or, alternatively, unlock an existing wallet with PUT /wallet/unlock/{walletId}

  3. Fetch a payment request from your wallet using POST /payment-client/payment-request

    Hint: Use http://localhost:8080/payment-server/ to get a payment request meant for your wallet. You can set the amount to pay by adding the query parameter: ?amount=; mind that amount is expected in Bitcoin, not in Satoshis

  4. Once Payment-Request has been fetched, use POST /payment-client/payment/{walletId} with the data coming from the previous endpoint.

    Mind that from the Transaction data you only need to set the Output part, not the entire transaction, I plan to improve this if I have time to do so...

Payment Protocol is meant for you to pay your providers in a safe way (PaymentClient*) and/or to allow your users to use the platform in a safe way (PaymentServer*)

About

Proof of concept of how to use Bitcoinj (bitcoin client) and Bitcoin cash variant

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages