In this project, we will cover the following topics:
- Creating a simple wallet.
- Sending signed transactions using our blockchain.
- Feeling extra cool.
In cryptocurrencies, coin ownership is transferred on the Blockchain as transactions. Participants have an address to which funds can be sent to and from. Wallets can store these addresses and make new transactions on the Blockchain.
Each transaction carries the following 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 show the amount relevant addresses received in the transaction.
- A cryptographic signature that proves the owner of the address is the one sending this transaction and that the data hasn’t been changed.
Signatures allow only the owner to spend their coins and prevent others from tampering with their submitted transaction before a new block is mined. The private key is used to sign the data, and the public key can be used to verify its integrity.
We are almost halfway done. Let’s test if everything is working. In the EchoChain class, let’s add some new variables and replace the content of our main method.
To own cryptocurrency, you must receive it. The ledger references previous transactions, showing that cryptocurrency was sent to your address.
Blocks in the chain may receive many transactions, and the blockchain might be very long. To get around this, we keep an extra collection of all unspent transactions that can be used as inputs.
We need to implement the transaction system into our blockchain. We should replace the useless data in our blocks with an ArrayList of transactions.
We should test sending coins to and from wallets and update our blockchain validity check. But first, we need a way to introduce new coins into the mix. We will release all the coins we wish to have in the first block (the genesis block).
- A Genesis block that releases 100 EchoCoins to WalletA.
- An updated chain validity check that takes into account transactions.
- Some test transactions to ensure everything is working.
You have successfully created your own cryptocurrency (sort of!). Your blockchain now:
- Allows users to create wallets with
new Wallet();
- Provides wallets with public and private keys using Elliptic-Curve cryptography.
- Secures the transfer of funds using a digital signature algorithm to prove ownership.
- Finally, allows users to make transactions on your blockchain with
Block.addTransaction(walletA.sendFunds(walletB.publicKey, 20));
bouncy castle bcprov-jdk15on-159.jar
gson gson-2.8.2.jar
![echocoin](https://private-user-images.githubusercontent.com/110540811/303919881-1154023b-c031-4298-b822-06e5a903cc93.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4MjgxMzYsIm5iZiI6MTcyMzgyNzgzNiwicGF0aCI6Ii8xMTA1NDA4MTEvMzAzOTE5ODgxLTExNTQwMjNiLWMwMzEtNDI5OC1iODIyLTA2ZTVhOTAzY2M5My5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE2JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxNlQxNzAzNTZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05YzcwNmRkMDFhYjUyYTg3ZWEwNGY4N2MzNGVmYjRkZGFiMTE1MzM2NGI2YmE3NmFjMDE4ODI5NWI4M2JmMDJkJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.c94znNLM_ST8Xvl0unRRxfBC3z4o4eWxogUeTtyeUpo)
You can download these project files on Github.
Meet me 😉 echoaditya
Contact me:
- Email: [email protected]
- Linktree