7 Useful NPM libraries for the blockchain developers
A curated list for the beginners.
Nowadays, we can see a high rate in the adoption of blockchain technology and cryptocurrencies in particular. As a result, these technologies are transforming into an irreplaceable part of our day-to-day life. However, blockchain has reserved its place almost for the next decade because of its wide range of applicability.
Lack of trust and need for privacy paved the way for cryptocurrencies to become a trillion-dollar industry. Several projects and innovations in technology are emerging every day. For any technology to attain such a high adoption rate and usability, there must be a bridge that allows any normal person to interact with the underlying system.
And that bridge is nothing but the applications. Hence, it is clear that the developer community plays a vital role in the growth of technology. They must be confident enough to start a project idea from scratch and deploy it to production. During the development phase, it will be easier for the developers to have some helper tools/libraries that implement the generic and common logic, allowing them to focus on building the application’s core logic. Today, we will glance at some useful npm modules that we can use on both client-side and server-side applications.
The below list is not sorted on any criteria. I’m not going to dive deep into any of the modules. The goal is to provide an overview of each of the modules. Let’s begin!
1.) Web3.js:
Web3.js is one of the most popular and well-known libraries used to interact with the EVM-compatible blockchain networks like Ethereum, Binance Smartchain, etc.. It provides a wide range of APIs used to connect and interact with the local or remote nodes.
For example, we can retrieve the balance of an Ethereum address using web3.js
like:
For more information, please check their official documentation.
2.) Ipfs-core:
The ipfs-core
library is used to interact with the ipfs
. It’s a very simple package to use. We can easily upload and retrieve files to the ipfs
network using this module.
What is IPFS?
IPFS is a distributed system for storing and accessing files, websites, applications, and data.
Example:
3.) Bitcoinjs-lib:
The bitcoinjs-lib
is an excellent package for developing bitcoin-based applications using NodeJS. It provides APIs for address generation and helps us build simple to complex transactions for almost all the types of addresses like P2KH
, P2SH
and P2WPKH
.
The following snippet will generate a random Segwit
address:
4.) Coingecko-api:
This is one of my favorite libraries. It is simple and straightforward to use. It is a very useful module and can be used for various use cases for example, to get the real time prices of coins/tokens, fetch the exchange rates of an asset, retrieve token details and a lot more.
Example code to fetch the price of Bitcoin
in USD.
5.) Ethers.js:
ethers.js
is similar to the web3.js
package discussed above. But ethers.js
is light-weighted and more compact when compared with web3.js
. Hence it is suitable to be used in the frontend applications. Also it has a very good documentation hence ethers.js is definitely a beginner-friendly package
You can learn more about the difference between the web3.js
and ethers.js
here.
The example code demonstrates the wallet instance creation from the Private Key
and transfer of ETH
to the recipient wallet.
6.) Truffle:
Truffle is a complete framework that can be used in the development and testing of smart contracts written on Solidity.
One can easily compile,test and deploy contracts on the EVM-compatible live networks using this module.
Some useful commands:
truffle init
— Initializes a new truffle projecttruffle compile
— Compiles all the smart contracts of the project.truffle test
— Runs the unit tests specified under thetest
directory of the projecttruffle migrate --network <network_name>
— Deploys the compiled contracts (bytecode) to the specified network.
7.) CCXT:
CCXT is an another interesting module which can be used to connect and trade with cryptocurrency/altcoin exchanges and payment processing services worldwide.
According to their documentation:
It provides quick access to market data for storage, analysis, visualization, indicator development, algorithmic trading, strategy backtesting, bot programming, webshop integration and related software engineering. It is intended to be used by coders, developers, technically-skilled traders and financial analysts to build trading algorithms on top of it.
You can find the usage examples here.
Note: Some of the above mentioned modules may get deprecated later in the future. So please look out for deprecation warnings/vulnerabilities during installation of the npm modules.
Happy coding!