
Explore blockchain concepts by building a complete blockchain and cryptocurrency from scratch, including core code, an API, a peer-to-peer server, proof of work, and transactions, with tests.
Explore how blockchain forms a distributed, decentralized ledger publicly shared across nodes, linking blocks with hashes and enabling trustless, secure peer-to-peer exchanges.
Explore how blockchain enables cryptocurrencies through cryptography, digital signatures, and wallet-based key pairs, ensuring data integrity and secure transactions, including mining concepts.
Miners solve the proof-of-work puzzle to confirm unconfirmed transactions, add blocks to the chain, and earn rewards that regulate block creation. Bitcoin and other cryptocurrencies are discussed.
Explore how the bitcoin white paper guides building a blockchain and cryptocurrency, covering private-key signatures, timestamped blocks, sha-256 proof-of-work, a miner network with incentives, and multi-input/output transactions.
Learn to set up the Windows Subsystem for Linux and Visual Studio Code, enabling a Unix-like command line with Ubuntu on Windows and a ready-to-use code editor for the course.
Explore a pragmatic overview of JavaScript essentials for newcomers. Learn browser and Node.js environments, primitives, objects, arrays, let and const, console.log, loops, conditionals, and equality with undefined.
Master JavaScript basics by defining and calling functions, using callbacks, and building classes with constructors and methods. Explore a Line class that creates lion objects with properties, illustrating object-oriented programming.
Set up a blockchain project by configuring a Node.js environment, creating the sf-chain directory, initializing package.json with npm init -y, and adding nodemon as a dev dependency for live reloads.
Create the block class as the blockchain’s fundamental unit, including timestamp, lastHash, hash, and data, with an ES6 constructor. Provide a toString for debugging.
Define the genesis block as the blockchain origin with a static genesis function that returns a block with dummy timestamp, lastHash, hash, and empty data, enabling the chain to start.
Define a static mineBlock function to create a new block from a last block and data, using Date.now for the timestamp and lastHash, with a placeholder hash.
Demonstrate computing a sha-256 hash for each block from its timestamp, lastHash, and data using the crypto-js module, enabling tamper detection and blockchain linkage.
Set up a robust test environment with Jest to validate the block class, create unit tests, and verify data and lastHash against the genesis block.
Create a blockchain class that maintains a chain of blocks with a genesis block, supports adding blocks from the last block, and mines new blocks to extend the chain.
Write jest tests to verify a blockchain starts with the Genesis block and that addBlock appends new blocks. Configure test files, require modules, and assert block data.
Learn how a blockchain with multiple contributors validates new blocks by accepting the longest chain and verifying hashes to resolve forks and prevent tampering.
Create the is valid chain function to verify incoming chains by checking the genesis block, then validate each block's last hash and hash with a static block hash.
Develop and validate the blockchain is valid chain method by writing unit tests that confirm a valid chain, detect genesis corruption, and flag non-genesis block tampering.
Learn to add a replace chain function that replaces the current blockchain with a longer, valid incoming chain, resolving forks and ensuring integrity via the is valid chain check.
add unit tests to verify the replace chain function with a valid chain. ensure shorter or invalid chains do not replace the current chain and review console logs.
Organize the project by moving blockchain files into a blockchain folder and renaming them to index.js and index.test.js, then create an app folder with its index.js and keep tests passing.
Build an Express api to interact with a blockchain, exposing a get /blocks endpoint to view the chain and a mining endpoint to add blocks.
Send a json post request to /mine to add a new block to the blockchain using body parser middleware in an express app, returning the updated chain.
Set up a peer-to-peer server with WebSockets to connect multiple blockchain nodes, broadcasting blocks and updating ledgers across peers.
Create a peer-to-peer WebSocket server to synchronize blockchain across multiple instances, implementing a P2P Server class, environment-configured ports and peers, and real-time block updates.
Add a connect to peers function in the P2P server to auto-connect later instances via websockets and allow peers to share the same blockchain using the longest, most up-to-date chain.
Handle messages from peers by sending the blockchain as stringified json. Receive them with a message handler, parse json, and update the chain across sockets.
Synchronize the blockchain across peers by replacing a shorter chain with a longer, valid one and broadcasting updates to all connected sockets after every new block.
Explore the proof of work, where miners solve hash puzzles with a nonce to add blocks, deter dishonest actors, and adjust difficulty to prevent 51% attacks.
Implement a nonce-driven proof of work by integrating a nonce into block hashes, using a four-digit difficulty, a do-while mining loop, and genesis default nonce to zero.
Develop and test nonce functionality for proof-of-work by validating hashes with leading zeros, sharing a difficulty setting via config, and exploring dynamic difficulty in a blockchain.
Explore dynamic block difficulty by adding a per-block difficulty and a 3-second mine rate, then adjust difficulty up or down using the previous block's timestamp.
Demonstrates how the adjust difficulty function modulates block mining speed by last block timestamps. Tests raise and lower difficulty, and validate a ten-block proof-of-work sequence.
Discover how digital wallets, private and public keys, and transactions secure a cryptocurrency on the blockchain, with signatures and verifications guiding balances and addresses.
Develop a wallet module for a blockchain and cryptocurrency project, implementing a wallet class with balance, key pair, and public key, initialized to 500.
Install elliptic and build a chain util class to generate key pairs. Create wallet public keys, encode them in hex, and enable signing and verifying transactions.
Build a cryptocurrency transaction system by implementing a transaction class with a uuid v1 id, input and outputs, and a static new transaction method that validates the sender's balance.
Learn to sign transactions by creating a signed input object with timestamp, sender's balance, public key, and signature using the wallet's sign method, hashing the transaction outputs.
Add a test to confirm that a transaction's input object carries an amount equal to the wallet balance, validating input creation before moving to signature verification.
Verify transaction inputs by checking signatures with the public key and data hash, enabling miners to include only valid transactions.
Add unit tests for the new transaction verification method to confirm that a valid transaction passes verification while a corrupt one fails, demonstrating proper signature generation for transaction objects.
Explore how to update an existing transaction by adding new outputs, recalculating the sender's balance, and resigning the input to preserve transaction validity.
Learn how to update transactions with new outputs and recipients, test the update flow, and prepare transactions for inclusion in blocks and the transaction pool.
Create a real-time transaction pool to hold unconfirmed transactions, then miners group them into blocks to confirm and store a decentralized blockchain history.
Create a transaction pool to collect pending transactions and implement an update-or-add method that replaces existing entries with the same id or adds new ones for the blockchain.
Test the transaction pool's ability to add and update transactions by id, ensuring updates replace existing entries, and prepare a wallet method to create and add transactions.
Implement wallet transactions by updating an existing pool entry or creating a new one for a recipient and amount, after balance validation.
Develop and test wallet transactions by implementing and validating the create transaction function, updating the transaction pool, and enabling real-time sharing across a blockchain-based cryptocurrency network.
Create a cryptocurrency experience by provisioning wallets and a transaction pool, exposing a transactions API, and enabling users to post and view transfers across a peer-to-peer blockchain.
Add a post endpoint /transact to create a wallet transaction with recipient and amount, then redirect to /transactions to view the updated pool and prepare pool synchronization across peers.
Synchronize the transaction pool across users by integrating it into the peer-to-peer server and broadcasting transactions with explicit types to all sockets.
Learn to implement a peer-to-peer server that broadcasts transactions and synchronizes the transaction pool via a switch-based message handler that routes chain and transaction messages.
Expose a wallet's address with a new public key endpoint using get /public-key, returning a json containing the public key for others to send transactions.
Miners take transactions from the pool, perform the work to discover and store a block, earn cryptocurrency rewards, and cause transactions to shift from unconfirmed to confirmed, updating wallet balances.
Learn to implement a valid transactions function in the transaction pool, verifying that outputs sum to the input amount and signatures, and filter invalid entries with clear logging.
Test valid transactions in the transaction pool by creating a mix of valid and corrupt transactions with wallet.createTransaction, and verify the validTransactions function returns only the valid ones.
Define a mining reward of 50 and implement reward transactions with a single output paid to the miner, signed by the blockchain wallet.
This lecture demonstrates testing reward transactions in the test suite, creating a reward transaction with the wallet, and validating the mining reward for the miner's wallet before building a block.
Fetch valid transactions from the pool, create a reward transaction for the miner, and include both in a new block on the blockchain, then sync chains via the p2p server.
Add a clear_transactions message type to broadcast to peers and clear transactions. Implement broadcast_clear_transactions to send this type to all sockets and wire it into the miner's mine function.
Compute wallet balance by summing outputs to a user's public key since the last transaction, updating on each new transaction to prevent double counting and ensure accuracy.
Implement a calculate balance function in the wallet class to compute balance from the blockchain using only outputs after the most recent wallet input transaction.
Recalculate the wallet balance before every transaction by passing a blockchain instance to the calculate balance function, update create transaction calls, and adjust tests to verify wallet balances.
Validate the calculate balance function by simulating wallet transactions on the blockchain, verifying recipient gains and sender deductions across initial and recent transactions.
Run and connect two cryptocurrency app instances, execute transactions, mine blocks, and verify balances to gain hands-on understanding of a blockchain and cryptocurrency.
Announcement! There is a full-stack remastered version of this course! This course builds the backend. But if you're interested in building a frontend and deploying the project, check out the remastered version!
Search for "Build a Blockchain & Cryptocurrency | Full-Stack Edition" under my list of courses!
***
This course will get you to build a blockchain and cryptocurrency from scratch.
The blockchain is a revolutionary technology that allows for the secure, distributed, decentralized storage of information. Over the past few years, the blockchain has taken the engineering landscape by storm. Many people in the industry predict that the blockchain will disrupt the ways we interact with technology on the same way the Internet did in the early 2000s.
The blockchain is the main technology behind Bitcoin, Ethereum, and the other prominent cryptocurrencies that we read about in the news today. By leveraging the blockchain, cryptocurrencies create a system of “trustless”ness. This cuts the need for middle men like banks and traders in economic systems.
Do you want to enter this young market, and become a highly sought-after blockchain engineer? The industry is starving for people who understand, and even better, can build blockchains. The supply is low, but the demand is high. So having a blockchain project under your belt will open doors and jobs for you.
For engineers, coders, and software developers, the best way to truly understand the revolutionary technologies of blockchain and cryptocurrencies, is to build a blockchain and cryptocurrency yourself. Therefore, this course will take you through implementing a blockchain and cryptocurrency - discovering the underlying techniques and concepts.
The course is designed into sections that introduce the main concepts of the blockchain one-by-one. By the end of the course, you will have a respectable blockchain project in your repertoire.
Some of the main course highlights:
Build a Blockchain in the object-oriented programming style
Generate hashes for blocks in the chain
Unit Test Components of the Blockchain
Create an API around the Blockchain
Create a real-time connected peer-to-peer server
Implement a proof-of-work algorithm
Sign Transactions with cryptography and digital signature
Create a Transaction Pool for a real-time list of incoming data
Include transactions in core blocks of the chain
We’ll use NodeJS to implement this project. Don’t worry if you’re not familiar with JavaScript. This course explains the purpose behind every line and keyword. So, while JS experience will help, it’s not an absolute requirement.
Written summaries supplement each tutorial. That way, you can move along at your own pace, either watching the more thorough filmed tutorial, or reading the summary.
Ultimately, knowledge of the Blockchain will set you up for success in the future, as an engineer in a blockchain-dominated world. So what are you waiting for? Let’s get started building a blockchain!