HackerNoon.com
Published in

HackerNoon.com

Building Blockchain Web API Using Swift and Vapor

http://media2.govtech.com/images/940*464/shutterstock_blockchain.jpg

Implementing Models

  • index — The position of block in the blockchain. Index of 0 means that the block is the first block in the blockchain. Index of 1 means it is the second block in the blockchain.. you get the idea right!
  • dateCreated — The date when the block was created
  • previousHash — The hash value of the previous block
  • hash — The current hash of the block
  • message — Memo attached to each block. This is just for our purposes
  • nonce — Auto incremented number which plays an important role for mining the hash
  • transactions — An array of transactions. Each transaction represents a transfer of goods/value
  • key — This is a computed property which is passed to the hashed function

Implementing Web API Using Vapor

  • Mining: This endpoint will initiate the mining proess. Mining will allow us to satisfy the proof of work and add the block to the Blockchain.
  • Transaction: This endpoint is used to add a new transaction. The transaction will contain information about sender, receiver and the amount.
  • Blockchain: This endpoint returns the complete blockchain.
Mining a New Block
New Transaction
Blockchain

Adding Nodes to Blockchain

Register a New Node
Fetching All Nodes

Resolving Conflicts Between Nodes

vapor run serve -— port=8090
Blockchain on Port 8080
Blockchain on Port 8090
Registering a Node
Resolve End Point Returning Larger Blockchain

--

--

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mohammad Azam

iOS Developer, speaker and educator. Top Udemy and LinkedIn instructor. Lead instructor at DigitalCrafts. https://www.udemy.com/user/mohammad-azam-2/