Category: Javascript

Blockchain technology using Javascript

Hello People. This article is about Blockchain technology using Javascript. As you already know, a blockchain is an open, digital, and duplicated ledger of transactions. Every new transaction history is recorded and stored in an encrypted way that is very difficult to modify. A copy of this recorded information is sent a cross the blockchain network. This makes it highly secure.

Blockchains are blocks of transaction data growing increasingly to create a chain of transaction occurrences. Valid transaction data is logged into the blockchain network following the peer-to-peer rule laid down by participants. Normally, the data in the databases are centralized. This means we operate based on only one server. Chances of risk are high due to failures of the system. Alternatively, decentralization allows data to be stored everywhere, thus making it faster, more secure and a better way of storing data.

We need to first install the crypto library using the command:

npm install --save crypto-js

We’ll use this library to import modules in our project.

We can start by creating a class BlockCypto as shown below:

const SHA256 = require('crypto-js/sha256');
class BlockCypto{
    constructor(index, current_time, info, nextHash=" "){
    this.index = index;
    this.current_time = current_time;
    this.info = info;
    this.nextHash = nextHash;
    this.hash = this.computeHash();     
    }
    computeHash(){
        return SHA256(this.info + this.nextHash + this.current_time + JSON.stringify(this.info)).toString();
    }   
}

Let us see each part of the code here:

We have created the class BlockCrytpo for our block and added a constructor just like any other JavaScript class.

In the constructor, we initialize its properties and assign parameters to it, as follows:

  • crypto-js/sha256: This is the module we’ve imported to calculate the hash of each block. We converted it to string using toString() method as the module will return the object.
  • index: This is a distinctive number tracking the index of every block in the blockchain.
  • current_time: As the name states, it keeps a record of the time when each transaction is completed.
  • info: All completed transactions data are recorded and stored by this method.
  • nexthash: It is pointing to the hash_key of the next block in the network chain. It’s mainly used to keep and maintain the integrity of the blockchain.
  • computeHash: Based on properties passed to this method, it is used to calculate the hashkey of the next block in the chain.
Blockchain technology using Javascript

What is blockchain theorem?

It is a type of database that stores a collection of data together in groups, with certain capacity of storage. The blocks are connected to the already created blocks, this forms a chain of a data tree.

The chain is irreversible as the system is decentralized. Here, each block is assigned a timestamp when added to the chain.

Now, let’s create a class Blockchain that will maintain this operation:

class Blockchain{
    constructor(){
        this.block1chain = [this.startGenesisBlock()];     
    }
    initGenesisBlock(){
        return new BlockCrypto(0, "06/04/2021", "Initial Block in the Chain", "0");
    }
    latestBlock(){
        return this.block1chain[this.block1chain.length - 1];
    }
    addNewBlock(newBlock){
        newBlock.nextHash = this.latestBlock().hash;
        newBlock.hash = newBlock.computeHash();        
        this.block1chain.push(newBlock);
    }
}

Let’s understand the code snippet above.

As usual, we have our constructor which instantiates the blockchain.

But this time, we passed it to the initGenesisBlock() method, which initializes the block in the chain. This property refers to an array of blocks in our case.

  • initGenesisBlock(): This is the first block created in the peer-to-peer network and has not been linked to any other. To our knowledge of indexing it’s at index 0.
  • latestBlock: As named, we use it for finding the last block added in the chain. As explained earlier, it helps to ensure the hash of the current block and map it to the hash of the previous block to ensure the chain integrity.
  • addNewBlock: A new block is added to the chain using this method. The previous hash block is matched to the current hash block to ensure minimal or no tampering with the chain.

Now that our blockchain is ready to work. We are missing something that is a core blockchain principle, the blockchain integrity.

Let’s see how to verify it and test our app.

Verifying blockchain integrity

The main characteristic of a blockchain is that once a block has been added to the network, it can’t be changed without invalidating the entire blockchain integrity.

To perform this, we use digital security or cryptographic hash, which ensures the securing and validation of the blockchain by producing a new hash every time a change is made in the block.

We’ll loop over the entire blockchain to check whether any hash has been tampered with, taking into account the exception of the first block, which is hardcoded.

Besides, this method verifies if the cryptographic-key of each two blocks in series are pointing to one another. If the integrity of the blockchain has been compromised, it returns false; otherwise, in case no anomalies are encountered, it returns true.

We’ll create this method inside the Blockchain class:

checkValidity(){
    // Checking validity
    for(let i = 1; i < this.block1chain.length; i++) {
        const currentBlock = this.block1chain[i];
        const nextBlock= this.blockchain[i-1];
    // Checking current blcok hash
    
    if(currentBlock.hash !== currentBlock.computeHash()) {
        return false;
    }
    // Comparing current block hash with the next block

    if(currentBlock.nextHash !== nextBlock.hash) {
        return false;
    }
    return true;
}

Now, we can test our app and see the results:

But, before we dive into running the code, let’s create a new instance of the Blockchain class and name it thecoin, and add some blocks in the blockchain using random values.

let thecoin = new Blockchain();

thecoin.addNewBlock(new BlockCrypto(1, "06/04/2021", {sender: "Rabin Yitzack", recipient: "Loyd Eve", quantity: 20}));

thecoin.addNewBlock(new BlockCrypto(2, "07/04/2021", {sender: "Anita Vyona", recipient: "Felix Mush", quantity: 349}));

console.log(JSON.stringify(thecoin, null, 4));

Hope this article on Blockchain technology using Javascript is useful to you. Please read Child Tracker IOT project architecture

Took Too Long to Respond error

Hello People. This article discusses about the “took too long to respond error”. Sometimes you might encounter the ‘website took too long to respond’ error when you try to access a particular website. This error indicates that there is a communication problem between the target server and the client. In this case your web browser. It must be understood that the targeted server is taking a long time to send a response to the client. The error appears if the client cannot get a response within 30 seconds. The connection attempt is then terminated.

Reasons for the ‘took too long to respond’ error?

Here are the reasons.

Internet connection problem

If you do not have an internet connection, this error occurs. Check that your device is connected to internet via a LAN or Wi-Fi. If you use a LAN, you need to check your LAN settings. You also need to make sure that your TCP/ipv4 protocols are correctly configured.

Much load on the server

If you are using shared hosting, there is a possibility that there is not enough memory to allow for a connection between your client and server. When using shared hosting, memory allocation is not equally distributed. There might be sites that use a lot of memory, leaving others with little memory available. Contact your service provider about your memory limit. If you are using WordPress, you can check your memory limit in the ‘Site Health Tool’ on your dashboard.

You may also want to change your hosting plan to a VPS (Virtual Private Server) package, where memory is shared equally among users.

There are also other reasons that may cause your site to be overwhelmed. Increase in site traffic, or code and scripts that have not been deferred to load only after your site fully loads.


Took Too Long to Respond error

Antivirus is blocking site access

Sometimes Your antivirus might block access to some sites or even all of them. You may need to temporarily disable it and see whether the ‘taking too long’ error is resolved.

DNS cache

The DNS (Domain Name System) is what converts domain names to IP addresses. DNS results are usually cached in order to make sure that subsequent requests are handled faster. If there was a communication problem between client and server, it may be cached, resulting in the ‘website took too long to respond’ error. Clearing the DNS cache should solve the error.

Outdated extensions

Extensions may not be as frequently updated for compatibility with web browsers. On Chrome, virus scanning extensions, for example, Symantec, outdated or not, tend to be ‘heavy’, which slows down your browser.

Browsing history

Stored data from browsing sessions such as saved passwords, cookies, site names, and URLs, as well as cache can contribute to client-server communication problems.

Chrome’s default profile folder issues

There is always a folder named ‘Default’ on your local machine which store’s your ‘Chrome Profile’ (your bookmarks, saved passwords, apps, browser settings, and extensions). If there is corrupted content in the folder, it may affect communication between client and server. You may need to edit or rename this file in order to fix ‘taking too long’ issues.

Windows hosts file

The hosts file is what maps domains to IP addresses. If you want to see for example how your site would look if you hosted on a different server, you would need to edit the hosts file.  If you have blocked website URLs or IP addresses in your hosts file, they might cause other sites to be blocked too, resulting in the page taking too long to load error.

The network adapter is not installed or is out of date

Drivers are very important for seamless communication between software and hardware. If your network driver is not up to date it may result in broken client-server communication.

Your browser contains corrupted files

Your browser may contain corrupted files. By reinstalling the web browser might solve this problem.

Theme incompatibility

If you are using WordPress, your theme incompatibility issues could be the reason for the ‘took too long to respond’ error. The only way to know whether it is your theme that is causing the issues is to change it to a default theme. If the error gets fixed, then you need to reinstall your theme.

Too much data in your database

If your database contains a lot of data, your site may take too long to retrieve all that data from your site.

Hope this article on Took Too Long to Respond error is useful to you. Please read about Power supply to Arduino boards


Arduino boards power supply

Hello People. This article is about Arduino boards power supply. There are several power pins on an arduino board.

The different power pins are as follows:

  • VIN. This pin can take input voltage to the Arduino board when it’s using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.
  • 5V. This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 – 12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your board. We don’t advise it.
  • 3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.
  • GND. Ground pins.

The Arduino Uno can be powered via the USB connection or with an external power supply. The power source is selected automatically.

External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery. The adapter can be connected by plugging a 2.1mm center-positive plug into the board’s power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER connector.

The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts.

Arduino boards power supply

Summary

There are mainly three methods of supplying power to arduino board. The Vin, 5V, 3.3V, and GND pins are Arduino power pins. You can use the Vin pin to Power your Arduino with an unregulated 7 to 12-volt power source. Like a 9V battery or a wall adapter that is in the range of 7 to 12 volts. Alternatively, you can power your Arduino through the 5V pin with an external regulated 5V power supply. It can be a wall adapter that gives out constant 5V or a DC-DC converter that is connected to a battery or a set of batteries. You can use both the 5V pin and the 3.3V pin to provide power to modules that are connected to the Arduino. But you can’t use the 3.3V pin to power your Arduino Uno/Nano.

Hope this article on Arduino boards power supply is useful to you. Please read Arduino UNO Pins explained

Arduino UNO Pins explained

Hello People. This article is titled Arduino UNO Pins explained. Arduino Uno is one of the most popular microcontroller. It has the development board based on 8-bit ATmega328P microcontroller. In addition to ATmega328P MCU IC, it consists other components such as crystal oscillator, serial communication, voltage regulator, etc. to support the microcontroller.

Arduino Uno has 14 digital input/output pins (6 of them can be used as PWM outputs), 6 analog input pins, a USB connection, A Power barrel jack, an ICSP header and a reset button.

How to use Arduino UNO Pins

As explained above, the 14 digital input/output pins can be used as input or output pins by using pinMode(), digitalRead() and digitalWrite() functions in arduino programming. Each pin operates at 5V and can provide or receive a maximum of 40mA current, and has an internal pull-up resistor of 20-50 KOhms which are disconnected by default.  Out of these 14 pins, some pins have specific functions as listed below:

  • Serial Pins 0 (Rx) and 1 (Tx): Rx and Tx pins are used to receive and transmit TTL serial data. They are connected with the corresponding ATmega328P USB to TTL serial chip.
  • External Interrupt Pins 2 and 3: These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value.
  • PWM Pins 3, 5, 6, 9 and 11: These pins provide an 8-bit PWM output by using analogWrite() function.
  • SPI Pins 10 (SS), 11 (MOSI), 12 (MISO) and 13 (SCK): These pins are used for SPI communication.
  • In-built LED Pin 13: This pin is connected with an built-in LED, when pin 13 is HIGH – LED is on and when pin 13 is LOW, its off.
Arduino UNO Pins explained

Along with 14 Digital pins, there are 6 analog input pins. Each of them provide 10 bits of resolution, i.e. 1024 different values. They measure from 0 to 5 volts but this limit can be increased by using AREF pin with analog Reference() function.  

  • Analog pin 4 (SDA) and pin 5 (SCA) also used for TWI communication using Wire library.

Arduino Uno has two other pins as explained below:

  • AREF: Used to provide reference voltage for analog inputs with analogReference() function.
  • Reset Pin: Making this pin LOW, resets the microcontroller.

Hope this article titled Arduino UNO Pins explained is useful to you. Please read Install PIP for Python on Windows

Blockchain Technology explained

Hello People. This article makes you Blockchain Technology explained. A blockchain is a distributed database that is shared among the nodes of a computer network. It stores information electronically in digital format.

Blockchains are used in cryptocurrency systems, such as Bitcoin, for maintaining a secure and decentralized record of transactions. It guarantees the fidelity and security of a record of data and generates trust without the need for a trusted third party.

Main Features

  • Blockchain is a shared database. It differs from a typical database in the way that it stores information.
  • Blockchains store data in blocks that are then linked together via cryptography.
  • When data comes in, it is entered into a fresh block. Once the block is filled with data, it is chained onto the previous block, which makes the data chained together in chronological order.
  • Most common use of blockchain so far has been as a ledger for transactions. 
  • In Bitcoin, blockchain is used in a decentralized way so that no single person or group has control. All users collectively retain control.
  • Data entered is irreversible. Transactions are permanently recorded and viewable to anyone.
Blockchain Technology explained

Blockchain working process

The purpose of blockchain is to allow digital information to be recorded and distributed, but not edited. In this way, a blockchain is the foundation for immutable ledgers, or records of transactions that cannot be altered, deleted, or destroyed. This is why blockchains are also known as a distributed ledger technology (DLT).

Blockchain’s first widespread application in use was Bitcoin in 2009. In the years since, the use of blockchains has exploded via the creation of various cryptocurrencies, decentralized finance (DeFi) applications, non-fungible tokens (NFTs), and smart contracts.

Blockchain has three important concepts: blocks, nodes and miners.

Blocks

Every chain consists of multiple blocks and each block has three basic elements:

  • The data in the block.
  • A 32-bit whole number called a nonce. The nonce is randomly generated when a block is created, which then generates a block header hash. 
  • The hash is a 256-bit number wedded to the nonce. It must start with a huge number of zeroes (i.e., be extremely small).

When the first block of a chain is created, a nonce generates the cryptographic hash. The data in the block is considered signed and forever tied to the nonce and hash unless it is mined.  

Miners

Miners create new blocks on the chain through a process called mining.

In a blockchain every block has its own unique nonce and hash, but also references the hash of the previous block in the chain, so mining a block isn’t easy, especially on large chains.

Miners use special software to solve the incredibly complex math problem of finding a nonce that generates an accepted hash. Because the nonce is only 32 bits and the hash is 256, there are roughly four billion possible nonce-hash combinations that must be mined before the right one is found. When that happens miners are said to have found the “golden nonce” and their block is added to the chain. 

Making a change to any block earlier in the chain requires re-mining not just the block with the change, but all of the blocks that come after. This is why it’s extremely difficult to manipulate blockchain technology. Think of it as “safety in math” since finding golden nonces requires an enormous amount of time and computing power.

When a block is successfully mined, the change is accepted by all of the nodes on the network and the miner is rewarded financially.

Nodes

One of the most important concepts in blockchain technology is decentralization. No one computer or organization can own the chain. Instead, it is a distributed ledger via the nodes connected to the chain. Nodes can be any kind of electronic device that maintains copies of the blockchain and keeps the network functioning. 

Every node has its own copy of the blockchain and the network must algorithmically approve any newly mined block for the chain to be updated, trusted and verified. Since blockchains are transparent, every action in the ledger can be easily checked and viewed. Each participant is given a unique alphanumeric identification number that shows their transactions.

Combining public information with a system of checks-and-balances helps the blockchain maintain integrity and creates trust among users. Essentially, blockchains can be thought of as the scalability of trust via technology. 

Hope this article on Blockchain Technology explained is useful to you. Please read about Printed Circuit Board designing business

Clients for Mobile app development

Hello People. This article discusses how to get clients for Mobile app development. Finding clients is a major problem for IT startups and entrepreneurs. Here are few useful tips to get clients for app development companies.

Firstly highlight the skill you are expert in. For example we have good command over android development so what we would do is that we find websites which have no apps yet in the playstore. We will drop a mail to owner on that website that you are lacking much audience because this era is of app users and there are trillions of folks using smart phone. We can build your app at a very reasonable price. In this scenario if client gets ready you could be able to build up portfolio.

You can also try getting business through LinkedIN. Visit your profile page on LinkedIN from your mobile app or desktop, and if business feature is turned on for you, you’ll see a box under your profile photo/headline that talks about how to showcase the services you provide. Click “Add Services,” and then fill out the form to provide details about the services you provide. Be as detailed as possible so members who view this section have a good sense for what you provide. Click “continue” and this will automatically be added to your profile.

Clients for Mobile app development

For finding clients on linkedIn, you must have a good connection with your targeted audience. You can search clients by their posted requirement like: “Looking for the freelancer designer or developer”. Once you type a statement like this one in the search box you will get the list of a result as you have to sort the list by “Content”. Then you can able to view all the posts related to that “keyword/requirement”. You have to pitch to that Author who has posted the requirement. You can simply comment or you can connect with him for further discussion.

Hope this article on how to get clients for Mobile app development is useful to you. Please read about Optical Character Recognition in React

Optical Character Recognition in React

Hello People. This article discusses about Optical Character Recognition in React. OCR is very useful when you want to extract text from a scanned document on a browser. Applying OCR technology through a React application, you can upload your images in various formats and can apply OCR to extract text content so easily. 

How to achieve Optical Character Recognition in React?

We’ll use two third party libraries for different purposes. The first one is “tesseract.js”. It’ll allow us to run OCR easily with just a couple of lines of code. The second one is “react-images-upload”, it’ll allow us to upload images to the browser and access their locations easily.

Here we do a couple of new things and you may want to follow them carefully. We should put the code snippet above the return we need to create 3 states here to achieve different goals. The first state we have here is to take the image URLs from our ImageUploader component and save it for further processing, the second state is the one that we keep our OCR applied texts, and the third one is the one for loading logic.

Optical Character Recognition in React

onDrop function is called whenever a change happened in our ImageUploader component . So whenever a change happens like adding or removing the photos in our component this function will be fired up. It’ll take the argument we need in the second position after the onChange event is fired so we can simply bypass the first argument by putting “_” and take the second one. It has link/links for our images in it and it’ll bring the full latest list of links so whenever we get a list from our function we can safely put that in our array.

runOcr function seems tricky but in fact, it’s quite simple, we take our URLs state and run the following recognition script for each element. Tesseract recognize function takes at least 2 arguments, first is the URL and the second one is the target language, tesseract.js supports over 100 languages. After the requests resolve we take output text and add it to our current array. After we fire runOcr command we can setIsLoading to true so we can display our spinner.

Hope this article on Optical Character Recognition in React is useful to you. Please read What is Node Red and its application

Node Red and its application

Hello People. This article explains you What is Node Red and its application. Node-RED is a programming tool for wiring together hardware devices, APIs and online services. At the core of Node-RED is Node.js, which (as you know) is a JavaScript runtime that has an active community.

Because of its ease of use, node-red is ideally suited for building IOT and Home control dashboards and automations as well as many other applications.

Node-Red IOT and Home Automation

Industrial IOT and home automation applications will generally use one or more of the following protocols.

  • MQTT
  • HTTP

Nodes for these protocols are part of the core nodes.

Node Red and its application

Various platforms

Node-RED can be used on various platforms. That’s because Node-RED itself is a Node.js application. If you have a runtime environment for Node.js, you can run it. It is mostly used on Edge devices, cloud services, and in embedded formats.

The perfect starting point for Node-RED applications is the ADAM-6700 series modules that come complete with Node-RED installed, plus onboard I/O and an extensive built in library to assist with utilising the ADAMs functions. Other functions and sample code can be added from other Node-RED users or by building your own applications and importing them into other projects you may do in the future.

An example of an application using Node-RED could be for a specific signalling arrangement for alarm monitoring. This could include analogue, serial, or ethernet devices all covered in a single unit that provides email and SMS support via a network. It could also include a dashboard on the local network with raw data that the alarms are based on, with logging on board using an SD Card.

A router using Node-RED can provide monitoring of 4G signal reception, alerts for signal loss, network performance and data usage just to name a few. As with modern equipment, Node-RED can provide benefits to make products intuitive to the user’s requirements whether for additional features or just using the dashboard function for service acknowledgement or fault reporting.

Hope this article on What is Node Red and its application is useful to you. Please read Software Development company for IoT projects

Software Development company for IoT projects

Hello People. This article discusses how to choose a software development company for IOT projects. The Internet of Things is a concept in which many everyday appliances and consumer electronics are computerized and connected to the Internet. Choosing an IoT developer today is very difficult.

IoT development cost

IoT development is very complex and therefore cannot be cheap. Immediately eliminate companies that offer their services 2-3 times cheaper. You will probably end up with a low-quality product if you choose them.

Blog posts and social media

Regular posts on social networks and a blog by a company indicate that the company has something to share with the audience. It is a great way to understand IoT’s level of expertise and company scale. It is enough to read a few articles to understand the material’s relevance and cultural level.

Plan for long-term

When it comes to the corporate, planning for the long term is the best. As it is a far-reaching, well thought, and comprehensive strategy that has the capability to change your life completely, the former applies to it too. 

Additionally, there’s always a level of uncertainty associated with this dynamic and disruptive technology, that may lead to unpredictable consequences in the future. This calls for the need for long-term planning that allows you to stay prepared for or unexpected events and take actions based on the ever-changing business environment and changing technologies.

Software development company for IOT projects

Figure out the basics

While your business might be successful with the adoption of this smart technology, relying on mere data collection may lead to failure in the next phase of a project. IoT is more than just collecting data with the help of connected devices, and you must consider several other factors to make your IoT project successful. 

It’s worth brainstorming how you are supposed to gain profitable business values from your internet-connected assets. Moreover, while you are collecting data, you need to make sure that it is driven by the real-world needs of a business and is organized properly. 

Secure IoT Private Networking

Protecting and securing your data is a serious business regardless of what industry you’re in. To have secure networking it’s better to create different ways for customers to build and own their IoT private network from end to end.

Regardless of whether you’re utilizing AWS VPC peering, AWS Direct Connect or IoT LANs, the IOT development company should plan to scale their customer’s business without compromising on their data.

Hope this article on software development company for IOT projects is useful to you. Please read Cost of developing an IOT app

IoT application in the Environmental Sector

Hello People. This article discusses about IoT application in the Environmental Sector. Using IoT, we can monitor and control our environment closely. We can also use this technology to predict environmental disasters. In that way we can implement damage-control early-on.

We can use real-time data sets to spot substantial contamination early on. Using IoT-enabled technology, such as drones, GPS sensors, animals can be detected and tracked in real-time. A potential outbreak on infectious diseases can be prevented much more efficiently. Livestock can be equipped with RFID chips, and RFID scanners. 

We can develop an IoT-system that monitors wastewater and provides a system-wide reporting solution for potential sewer overflow or discharge. It depends on water level sensors located inside manholes. These IoT-sensors relay information to a server that alerts users via an App or SMS about the potential spill-over and overflow.

IoT application in the Environmental Sector

Businesses can implement IoT systems and AI technology, to monitor their hardware. If a part has turned faulty, the IOT system may redirect the consumer to the nearest authorized repair shops.

Using IoT technology, different servers and data centers can be connected. Data centers connected through IoT technology will be able to monitor their servers in real-time . As a result money and energy can be saved, whenever the server load is lower than usual.

Many drivers in congested cities waste a considerable amount of time and money trying to find a parking space. Cities can employ IOT systems that automatically alert nearby drivers of empty parking spaces.

IoT technology can play a crucial role in smart agriculture. By attaching different sensors to crops and trees, one can gain insightful data on hydration level, nutrient levels, diseases etc. This may also decrease the use of chemical fertilizers and pesticides.

Hope this article on IoT application in the Environmental Sector is useful to you. Please read about What is an SMTP server application

Navigation

× Contact Us