0% found this document useful (0 votes)
90 views3 pages

TP2 BlockChain Transactions

This document provides instructions for creating a basic blockchain-based cryptocurrency called "NoobCoin" using Java. It involves: 1. Creating a Wallet class to generate and store public/private keys for sending and receiving transactions. 2. Creating Transaction, TransactionInput, and TransactionOutput classes to define the structure of transactions on the blockchain. 3. Testing the wallet functionality by generating transactions between wallets, signing with private keys, and verifying signatures. 4. Defining how transaction inputs and outputs work, representing ownership of currency and allowing it to be sent in new transactions. 5. Adding code to process transactions by validating inputs, generating outputs, and updating the unspent

Uploaded by

Abdo Ait Ja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views3 pages

TP2 BlockChain Transactions

This document provides instructions for creating a basic blockchain-based cryptocurrency called "NoobCoin" using Java. It involves: 1. Creating a Wallet class to generate and store public/private keys for sending and receiving transactions. 2. Creating Transaction, TransactionInput, and TransactionOutput classes to define the structure of transactions on the blockchain. 3. Testing the wallet functionality by generating transactions between wallets, signing with private keys, and verifying signatures. 4. Defining how transaction inputs and outputs work, representing ownership of currency and allowing it to be sent in new transactions. 5. Adding code to process transactions by validating inputs, generating outputs, and updating the unspent

Uploaded by

Abdo Ait Ja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

University Mohamed V of Rabat

Ecole Nationale Supérieure d'Informatique et d'Analyse des Systèmes


TP2: Creating Your First Blockchain with Java.
-Transactions-

The aim of this practical session, is to help you build a picture of how one could develop blockchain
technology. In this second part we will :
 Create a simple wallet..
 Send signed transactions using our blockchain.
Carrying on from T P , we have a basic veriable Blockchain. But currently our chain only stores
rather useless messages. In T P , you are going to replace this data with transactions ( our block will be
1

able to hold multiple transactions), allowing us to create a very simple crypto-currency. We will call our
2

new coin : "NoobCoin".


1 Settings
You need to have the following items before starting this project :
 Finished T P .
 Dependencies : You will need to import bounceycastle (here is a mini tutorial on how to do so)
1

and GSON.
2 Preparing a Wallet
In crypto-currencies, coin ownership is transfered on the Blockchain as transactions, participants have
an address which funds can be sent to and from.

1. Create a Wallet Class to hold our public key and private keys.
The public key can act as an address. It's OK to share this public key with others to receive
payment. Our private key is used to sign our transactions, so that nobody can spend our noobcoins
other than the owner of the private key. We
also send our public key along with the transaction and it can be used to verify that our signature
Users will have to keep their private key Secret !

is valid and data has not been tampered with.

1
University Mohamed V of Rabat
Ecole Nationale Supérieure d'Informatique et d'Analyse des Systèmes

2. Append a generateKeyPair() method (from the Piazza Platform) to your Wallet class and call it
in the constructor.
3 Transactions & Signatures
Each transaction will carry a certain amount of data :
 The public key(address) of the sender of funds.
 The public key(address) of the receiver of funds.
 The value/amount of funds to be transferred.
 Inputs, which are references to previous transactions that prove the sender has funds to send.
 Outputs, which shows the amount relevant addresses received in the transaction. ( These outputs
are referenced as inputs in new transactions )
 A cryptographic signature, that proves the owner of the address is the one sending this transaction
and that the data hasn't been changed. (for example : preventing a third party from changing the
amount sent )
1. Create this new Transaction class.
2. Create empty TransactionInput and TransactionOutput classes.
3. Download the new StringUtil.
4. In the Transaction, add the new functions (loaded in the Piazza Platform) generateSignature() and
veriySignature() methods.
4 Testing the Wallets and Signatures
1. Update your BlockChain class by adding new variables and replace the content in order to test
your wallet.
(a) Created two wallets, walletA and walletB
(b) Print walletA's private and public keys.
(c) Generate a Transaction and sign it using walletA's private key.
(d) Verify the Transaction.
5 Inputs & Outputs 1 : How crypto currency is owned
For you to own 1 bitcoin, you have to receive 1 Bitcoin. The ledger doesn't really add one bitcoin to you
and minus one bitcoin from the sender, the sender referenced that he/she previously received one bitcoin,
then a transaction output was created showing that 1 Bitcoin was sent to your address. (Transaction
inputs are references to previous transaction outputs.). So to some-up, Your wallets balance is the
sum of all the unspent transaction outputs addressed to you.

1. The TransactionInput class will be used to reference TransactionOutputs that have not yet been
spent. The transactionOutputId will be used to nd the relevant TransactionOutput, allowing
miners to check your ownership. Use UTXO name to refer The unspent transaction outputs.
2
University Mohamed V of Rabat
Ecole Nationale Supérieure d'Informatique et d'Analyse des Systèmes
2. Transaction outputs will show the nal amount sent to each party from the transaction. These,
when referenced as inputs in new transactions, act as proof that you have coins to send.
(a) TransactionOutput(PublicKey reciepient, oat value, String parentTransactionId) is the construc-
tor.
(b) isMine(PublicKey publicKey) checks if coin belongs to you.
6 Inputs & Outputs 2 : Processing the transaction
1. Include this code into the BlockChain class :
public static HashMap<String,TransactionOutputs> UTXOs = new HashMap<String,TransactionOutputs>();
//list of all unspent transactions.
2. In the Transaction class, add the processTransaction boolean method which returns true if new
transaction could be created. The method needs to :
(a) gather transaction inputs (Make sure they are unspent).
(b) check if transaction is valid.
(c) generate transaction outputs.
(d) add outputs to Unspent list.
(e) remove transaction inputs from UTXO lists as spent.
(f) returns sum of inputs(UTXOs) values.
(g) returns sum of outputs.
3. Update the Wallet in order to :
(a) Gather your balance ( by looping through the UTXOs list and checking if a transaction output
isMine())
(b) And generate transactions for you

You might also like