SlideShare a Scribd company logo
1 of 63
Node.js Blockchain Implementation
Valerii Radchenko
JS TechTalk #2
17.08.2018
The Blockchain
Wikipedia says:
A blockchain, originally block chain, is a growing list of records, called
blocks, which are linked using cryptography.
The Blockchain
Wikipedia says:
A blockchain, originally block chain, is a growing list of records, called
blocks, which are linked using cryptography.
The blockchain is a way of storing data for free access and making changes
that are safe, confirmed by most users in an open distributed network.
Examples and tools
• As an example, we will look at very simplified cryptocurrency
implementation.
• Tools and modules:
- Node.js
- Typescript
- Crypto (Node.js core module)
- Elliptic (npm package)
- Base58, big-integer(npm package)
- levelUp, levelDown (npm packages)
Agenda
1. Basic Concept
2. Persistence
3. Proof Of Work
4. Addresses
5. Transactions
6. Mining
7. More
8. Conclusion
7
Basic Concept
Blocks
• In blockchain, its blocks store valuable information.
• Besides this, a block contains some technical information, like:
- Version
- Current timestamp
- Its hash
- Hash of the previous block
Block
Schema Code
Block Hash
• One of the important thing in a blockchain is calculating hashes.
- It makes blockchain secure.
- Calculating hashes requires some time even on powerful computers.
- This is an intentional architectural design, which makes adding new blocks
difficult, thus preventing their modification after they’re added.
Block Hash
Schema Code
Blockchain
• Blockchain is a database structure: it’s an ordered, back-linked list.
• Which means that blocks are stored in the insertion order and that each
block is linked to the previous one. This structure allows to quickly get the
latest block in a chain and to get a block by its hash.
Blockchain
Genesis block
• In any blockchain, there must be at least one block.
• The first block in the chain is called the genesis block and creating a
blockchain must start by creating such block.
16
Persistence
What kind of database fit our needs?
• We need a simple serverless database to store our blocks one after another
- NoSQL
- Serverless
- Key/value or documented
- Simple and fast
Databases
• LevelDB
• LiteDB
• VelocityDB
• And many more…
BitcoinCore Database Structure
• 'l' -> 4-byte file number: the last block file number used
• 'c' + 32-byte transaction hash -> unspent transaction output record for that
transaction
• 32-byte block hash -> block record
• The full database structure description
21
Proof Of Work
Proof Of Work
• A proof of work is a piece of data which is difficult (costly, time-consuming)
to produce but easy for others to verify and which satisfies certain
requirements.
• Producing a proof of work can be a random process with low probability so
that a lot of trial and error is required on average before a valid proof of
work is generated.
Nonce and Complexity
"Hello, world!0" => 1312af178c253f84028d480a6adc1e25e81caa44c749ec81976192e2ec934c64
"Hello, world!1" => e9afc424b79e4f6ab42d99c81156d3a17228d6e1eef4139be78e948a9332a7d8
"Hello, world!2" => ae37343a357a8297591625e7134cbea22f5928be8ca2a32aa475cf05fd4266b7
...
"Hello, world!4248" =>
6e110d98b388e77e9c6f042ac6b497cec46660deef75a55ebc7cfdf65cc0b965
"Hello, world!4249" =>
c004190b822f1669cac8dc37e761cb73652e7832fb814565702245cf26ebb9e6
"Hello, world!4250" => 0000c3af42fc31103f1fdc0151fa747ff87349a4714df7cc52ea464e12dcd4e9
26
Addresses
Bitcoin Address
• 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa This is the very first Bitcoin
address
• Addresses are not something that identifies you as the owner of a “wallet”
• Address is a public key
• In Bitcoin, your identity is a pair of private and public keys stored on your
computer
Public-key Cryptography
• Digital Signatures guarantee:
- Data wasn’t modified while being transferred from a sender to a recipient
- Data was created by a certain sender
- The sender cannot deny sending the data
• In order to sign data we need:
- Data to sign
- Private key
• In order to verify a signature:
- Data that was signed
- The signature
- Public key
33
Demo Time
34
Transactions
Transactions
• No accounts
• No balances
• No addresses
• No coins
• No senders and receivers
Miners
• Miners are nodes are run on powerful or specialized hardware (like ASIC),
and their only goal is to mine new blocks as fast as possible. Miners are
only possible in blockchains that use Proof-of-Work
The Coinbase Transaction
• In Bitcoin, outputs come before inputs.
• When a miner starts mining a block, it adds a coinbase transaction to it. A
coinbase transaction is a special type of transactions, which doesn’t require
previously existing outputs. It creates outputs out of nowhere.
• Every block must store at least one
transaction and it’s no more possible to mine
blocks without transactions.
Storing Transactions in Blockchain
Change
• Each output might be used only once. This means that once an input got a
reference to an output the output cannot be used again even if its value is
higher then needed to create a transaction. In this case, we create
additional output in which value we place a difference between transaction
amount and referenced output value. It is a change.
Unspent Transaction Outputs (Balance)
• Unspent means that these outputs weren’t referenced in any inputs
- tx0, output 1
- tx1, output 0
- tx3, output 0
- tx4, output 0
• When we check balance, we need only those that can be unlocked by the
key we own.
Sending Coins
• We want to send some coins to someone else. For this, we need to create
a new transaction, put it in a block, and mine the block.
• Before creating new outputs, we first have to find all unspent outputs and
ensure that they store enough value.
The UTXO Set
• Cause, we could have tons of blocks, we do not want to iterate through all
of them. And UTXO Set can help us avoid this.
Merkle Tree
• The full Bitcoin database (i.e., blockchain) takes more than 282 Gb of disk
space
• Because of the decentralized nature of Bitcoin, every node in the network
must be independent and store a full copy of the blockchain
Merkle Tree And Simplified Payment Verification (SPV)
• SPV is a light Bitcoin node that doesn’t download the whole blockchain and
doesn’t verify blocks and transactions. Instead, it finds transactions in
blocks (to verify payments) and is linked to a full node to retrieve just
necessary data. This mechanism allows having multiple light wallet nodes
with running just one full node.
55
Mining
56
Demo Time
57
More…
Important things
• Networking
• Mining on GPU
• Smart contracts (P2PKH)
59
Conclusion
Conclusion
• Node.js is a great platform for creating P2P networks, easy coding your
blockchain applications and a big amount of various crypto functions.
• But there are some cons:
- Very slow mining performance
- There is no ability to use GPU without workarounds
Helpful Links
• BitcoinCore Wiki
• Blockchain on Go
• Bitcoin Explorer
• GitHub ValeriyRadchenko
Thank you
Node.js Blockchain Implementation

More Related Content

What's hot

Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Ontico
 
Ускоряем загрузку картинок вебсокетами
Ускоряем загрузку картинок вебсокетамиУскоряем загрузку картинок вебсокетами
Ускоряем загрузку картинок вебсокетами
2ГИС Технологии
 

What's hot (20)

Vault
VaultVault
Vault
 
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
 
Ускоряем загрузку картинок вебсокетами
Ускоряем загрузку картинок вебсокетамиУскоряем загрузку картинок вебсокетами
Ускоряем загрузку картинок вебсокетами
 
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
 
Openstack Keystone
Openstack Keystone Openstack Keystone
Openstack Keystone
 
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
 
Azure Blockchain Workbench
Azure Blockchain WorkbenchAzure Blockchain Workbench
Azure Blockchain Workbench
 
Altitude SF 2017: Logging at the edge
Altitude SF 2017: Logging at the edgeAltitude SF 2017: Logging at the edge
Altitude SF 2017: Logging at the edge
 
WILD microSERVICES v2 (JEEConf Edition)
WILD microSERVICES v2 (JEEConf Edition)WILD microSERVICES v2 (JEEConf Edition)
WILD microSERVICES v2 (JEEConf Edition)
 
Microservices with Spring
Microservices with SpringMicroservices with Spring
Microservices with Spring
 
Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...
Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...
Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...
 
DockerCon Live 2020 - Securing Your Containerized Application with NGINX
DockerCon Live 2020 - Securing Your Containerized Application with NGINXDockerCon Live 2020 - Securing Your Containerized Application with NGINX
DockerCon Live 2020 - Securing Your Containerized Application with NGINX
 
Resource slides for blockchain related question
Resource slides for blockchain related questionResource slides for blockchain related question
Resource slides for blockchain related question
 
Reactive Architectures
Reactive ArchitecturesReactive Architectures
Reactive Architectures
 
HashiCorp Vault Workshop:幫 Credentials 找個窩
HashiCorp Vault Workshop:幫 Credentials 找個窩HashiCorp Vault Workshop:幫 Credentials 找個窩
HashiCorp Vault Workshop:幫 Credentials 找個窩
 
Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTP
 
Issuing temporary credentials for my sql using hashicorp vault
Issuing temporary credentials for my sql using hashicorp vaultIssuing temporary credentials for my sql using hashicorp vault
Issuing temporary credentials for my sql using hashicorp vault
 
Developing Business Blockchain Applications on Hyperledger
Developing Business  Blockchain Applications on Hyperledger Developing Business  Blockchain Applications on Hyperledger
Developing Business Blockchain Applications on Hyperledger
 
Altitude SF 2017: Optimizing your hit rate
Altitude SF 2017: Optimizing your hit rateAltitude SF 2017: Optimizing your hit rate
Altitude SF 2017: Optimizing your hit rate
 
Managing secrets at scale
Managing secrets at scaleManaging secrets at scale
Managing secrets at scale
 

Similar to Node.js Blockchain Implementation

Similar to Node.js Blockchain Implementation (20)

A Quick Start To Blockchain by Seval Capraz
A Quick Start To Blockchain by Seval CaprazA Quick Start To Blockchain by Seval Capraz
A Quick Start To Blockchain by Seval Capraz
 
BlockchainConf.tech - Build a private blockchain workshop
BlockchainConf.tech - Build a private blockchain workshopBlockchainConf.tech - Build a private blockchain workshop
BlockchainConf.tech - Build a private blockchain workshop
 
BLOCKCHAIN EXPLAINED
BLOCKCHAIN EXPLAINEDBLOCKCHAIN EXPLAINED
BLOCKCHAIN EXPLAINED
 
Blockchain - Presentacion Betabeers Galicia 10/12/2014
Blockchain - Presentacion Betabeers Galicia 10/12/2014Blockchain - Presentacion Betabeers Galicia 10/12/2014
Blockchain - Presentacion Betabeers Galicia 10/12/2014
 
Basics of Block Chain
Basics of Block ChainBasics of Block Chain
Basics of Block Chain
 
Blockchain, working [blockchain vs bitcoin] pros and cons
Blockchain, working [blockchain vs bitcoin] pros and consBlockchain, working [blockchain vs bitcoin] pros and cons
Blockchain, working [blockchain vs bitcoin] pros and cons
 
blockchain class 3.pdf
blockchain class 3.pdfblockchain class 3.pdf
blockchain class 3.pdf
 
Blockchain Technology
Blockchain TechnologyBlockchain Technology
Blockchain Technology
 
Architecture and operations.pptx
Architecture and operations.pptxArchitecture and operations.pptx
Architecture and operations.pptx
 
Blockchain 101 - public, tokenized blockchains
Blockchain 101 - public, tokenized blockchainsBlockchain 101 - public, tokenized blockchains
Blockchain 101 - public, tokenized blockchains
 
Block chain
Block chainBlock chain
Block chain
 
20190606 blockchain101
20190606 blockchain10120190606 blockchain101
20190606 blockchain101
 
Blockchain and bitcoin fundamentals (usages and applications)
Blockchain and bitcoin fundamentals (usages and applications)Blockchain and bitcoin fundamentals (usages and applications)
Blockchain and bitcoin fundamentals (usages and applications)
 
Blockchain and bitcoin
Blockchain and bitcoinBlockchain and bitcoin
Blockchain and bitcoin
 
Blockchain (1).pptx
Blockchain (1).pptxBlockchain (1).pptx
Blockchain (1).pptx
 
Blockchain Fundamental_KIPMI_2022.02.26.pdf
Blockchain Fundamental_KIPMI_2022.02.26.pdfBlockchain Fundamental_KIPMI_2022.02.26.pdf
Blockchain Fundamental_KIPMI_2022.02.26.pdf
 
PSU CSE 541 Project Idea
PSU CSE 541 Project IdeaPSU CSE 541 Project Idea
PSU CSE 541 Project Idea
 
Introduction to Blockchain & development
Introduction to Blockchain & developmentIntroduction to Blockchain & development
Introduction to Blockchain & development
 
Blockchain Ecosystem and Cryptocurrency Regulations
Blockchain Ecosystem and Cryptocurrency RegulationsBlockchain Ecosystem and Cryptocurrency Regulations
Blockchain Ecosystem and Cryptocurrency Regulations
 
Blockchain Fundamentals
Blockchain FundamentalsBlockchain Fundamentals
Blockchain Fundamentals
 

More from GlobalLogic Ukraine

GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Ukraine
 

More from GlobalLogic Ukraine (20)

GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
GlobalLogic Embedded Community x ROS Ukraine Webinar "Surgical Robots"
 
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
GlobalLogic Java Community Webinar #17 “SpringJDBC vs JDBC. Is Spring a Hero?”
 
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
GlobalLogic JavaScript Community Webinar #18 “Long Story Short: OSI Model”
 
Штучний інтелект як допомога в навчанні, а не замінник.pptx
Штучний інтелект як допомога в навчанні, а не замінник.pptxШтучний інтелект як допомога в навчанні, а не замінник.pptx
Штучний інтелект як допомога в навчанні, а не замінник.pptx
 
Задачі AI-розробника як застосовується штучний інтелект.pptx
Задачі AI-розробника як застосовується штучний інтелект.pptxЗадачі AI-розробника як застосовується штучний інтелект.pptx
Задачі AI-розробника як застосовується штучний інтелект.pptx
 
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptxЩо треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
Що треба вивчати, щоб стати розробником штучного інтелекту та нейромереж.pptx
 
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
GlobalLogic Java Community Webinar #16 “Zaloni’s Architecture for Data-Driven...
 
JavaScript Community Webinar #14 "Why Is Git Rebase?"
JavaScript Community Webinar #14 "Why Is Git Rebase?"JavaScript Community Webinar #14 "Why Is Git Rebase?"
JavaScript Community Webinar #14 "Why Is Git Rebase?"
 
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
GlobalLogic .NET Community Webinar #3 "Exploring Serverless with Azure Functi...
 
Страх і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic EducationСтрах і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic Education
 
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
 
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
 
“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?
 
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
 
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
 
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
 
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
 
GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"
 
C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"
 
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Node.js Blockchain Implementation

  • 1.
  • 2. Node.js Blockchain Implementation Valerii Radchenko JS TechTalk #2 17.08.2018
  • 3. The Blockchain Wikipedia says: A blockchain, originally block chain, is a growing list of records, called blocks, which are linked using cryptography.
  • 4. The Blockchain Wikipedia says: A blockchain, originally block chain, is a growing list of records, called blocks, which are linked using cryptography. The blockchain is a way of storing data for free access and making changes that are safe, confirmed by most users in an open distributed network.
  • 5. Examples and tools • As an example, we will look at very simplified cryptocurrency implementation. • Tools and modules: - Node.js - Typescript - Crypto (Node.js core module) - Elliptic (npm package) - Base58, big-integer(npm package) - levelUp, levelDown (npm packages)
  • 6. Agenda 1. Basic Concept 2. Persistence 3. Proof Of Work 4. Addresses 5. Transactions 6. Mining 7. More 8. Conclusion
  • 8. Blocks • In blockchain, its blocks store valuable information. • Besides this, a block contains some technical information, like: - Version - Current timestamp - Its hash - Hash of the previous block
  • 10. Block Hash • One of the important thing in a blockchain is calculating hashes. - It makes blockchain secure. - Calculating hashes requires some time even on powerful computers. - This is an intentional architectural design, which makes adding new blocks difficult, thus preventing their modification after they’re added.
  • 12. Blockchain • Blockchain is a database structure: it’s an ordered, back-linked list. • Which means that blocks are stored in the insertion order and that each block is linked to the previous one. This structure allows to quickly get the latest block in a chain and to get a block by its hash.
  • 14. Genesis block • In any blockchain, there must be at least one block. • The first block in the chain is called the genesis block and creating a blockchain must start by creating such block.
  • 15.
  • 17. What kind of database fit our needs? • We need a simple serverless database to store our blocks one after another - NoSQL - Serverless - Key/value or documented - Simple and fast
  • 18. Databases • LevelDB • LiteDB • VelocityDB • And many more…
  • 19. BitcoinCore Database Structure • 'l' -> 4-byte file number: the last block file number used • 'c' + 32-byte transaction hash -> unspent transaction output record for that transaction • 32-byte block hash -> block record • The full database structure description
  • 20.
  • 22. Proof Of Work • A proof of work is a piece of data which is difficult (costly, time-consuming) to produce but easy for others to verify and which satisfies certain requirements. • Producing a proof of work can be a random process with low probability so that a lot of trial and error is required on average before a valid proof of work is generated.
  • 23. Nonce and Complexity "Hello, world!0" => 1312af178c253f84028d480a6adc1e25e81caa44c749ec81976192e2ec934c64 "Hello, world!1" => e9afc424b79e4f6ab42d99c81156d3a17228d6e1eef4139be78e948a9332a7d8 "Hello, world!2" => ae37343a357a8297591625e7134cbea22f5928be8ca2a32aa475cf05fd4266b7 ... "Hello, world!4248" => 6e110d98b388e77e9c6f042ac6b497cec46660deef75a55ebc7cfdf65cc0b965 "Hello, world!4249" => c004190b822f1669cac8dc37e761cb73652e7832fb814565702245cf26ebb9e6 "Hello, world!4250" => 0000c3af42fc31103f1fdc0151fa747ff87349a4714df7cc52ea464e12dcd4e9
  • 24.
  • 25.
  • 27. Bitcoin Address • 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa This is the very first Bitcoin address • Addresses are not something that identifies you as the owner of a “wallet” • Address is a public key • In Bitcoin, your identity is a pair of private and public keys stored on your computer
  • 28.
  • 29. Public-key Cryptography • Digital Signatures guarantee: - Data wasn’t modified while being transferred from a sender to a recipient - Data was created by a certain sender - The sender cannot deny sending the data • In order to sign data we need: - Data to sign - Private key • In order to verify a signature: - Data that was signed - The signature - Public key
  • 30.
  • 31.
  • 32.
  • 35. Transactions • No accounts • No balances • No addresses • No coins • No senders and receivers
  • 36.
  • 37.
  • 38. Miners • Miners are nodes are run on powerful or specialized hardware (like ASIC), and their only goal is to mine new blocks as fast as possible. Miners are only possible in blockchains that use Proof-of-Work
  • 39. The Coinbase Transaction • In Bitcoin, outputs come before inputs. • When a miner starts mining a block, it adds a coinbase transaction to it. A coinbase transaction is a special type of transactions, which doesn’t require previously existing outputs. It creates outputs out of nowhere.
  • 40.
  • 41. • Every block must store at least one transaction and it’s no more possible to mine blocks without transactions. Storing Transactions in Blockchain
  • 42. Change • Each output might be used only once. This means that once an input got a reference to an output the output cannot be used again even if its value is higher then needed to create a transaction. In this case, we create additional output in which value we place a difference between transaction amount and referenced output value. It is a change.
  • 43. Unspent Transaction Outputs (Balance) • Unspent means that these outputs weren’t referenced in any inputs - tx0, output 1 - tx1, output 0 - tx3, output 0 - tx4, output 0 • When we check balance, we need only those that can be unlocked by the key we own.
  • 44.
  • 45. Sending Coins • We want to send some coins to someone else. For this, we need to create a new transaction, put it in a block, and mine the block. • Before creating new outputs, we first have to find all unspent outputs and ensure that they store enough value.
  • 46. The UTXO Set • Cause, we could have tons of blocks, we do not want to iterate through all of them. And UTXO Set can help us avoid this.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51. Merkle Tree • The full Bitcoin database (i.e., blockchain) takes more than 282 Gb of disk space • Because of the decentralized nature of Bitcoin, every node in the network must be independent and store a full copy of the blockchain
  • 52. Merkle Tree And Simplified Payment Verification (SPV) • SPV is a light Bitcoin node that doesn’t download the whole blockchain and doesn’t verify blocks and transactions. Instead, it finds transactions in blocks (to verify payments) and is linked to a full node to retrieve just necessary data. This mechanism allows having multiple light wallet nodes with running just one full node.
  • 53.
  • 54.
  • 58. Important things • Networking • Mining on GPU • Smart contracts (P2PKH)
  • 60. Conclusion • Node.js is a great platform for creating P2P networks, easy coding your blockchain applications and a big amount of various crypto functions. • But there are some cons: - Very slow mining performance - There is no ability to use GPU without workarounds
  • 61. Helpful Links • BitcoinCore Wiki • Blockchain on Go • Bitcoin Explorer • GitHub ValeriyRadchenko