Categories
Web3

What is Web3? Is it the future?

Web3 derives its name from Web3.js – a JavaScript library to interact with Ethereum blockchain. But of course, Web3 is not just about Web3.js or Ethereum. It’s a utopian idea about open and decentralised Internet, no intermediaries, and no central authorities. Users controlling their own data on a trustless networks.

Web 1.0 and 2.0 is all about giant companies controlling the internet and its various applications, collecting users’ data, and selling it to advertisers for profit. In web 2.0, a company can kick out the president of the United States from its platform for using the platform to spread misinformation. In the world of Web3, the companies don’t control the platforms. Platforms are decentralised. They are called dapps – Decentralised Apps.

In the world of Web3, applications are not hosted on a central server owned by a giant hosting company like Amazon, Microsoft, Google or Rackspace. The dapps are spread across several nodes (servers). You can also become a node simply by getting a virtual server on Amazon, Microsoft, Google or Rackspace.

The web 2.0 companies need to raise venture capital and have to give away a part of their company to investors. In the ideal world of Web3, creators don’t have to sell stake to VCs, they can instead sell tokens (DeFi – Decentralised Finance) to hundreds of backers who now vote on how the project proceeds, what features get built and how it is marketed. Democracy for the win! banks are dead, here comes DeFi.

One of the core principals of Web3 is trustless network. With the magic of permissionless public blockchain, anyone in the world can transfer value instantly to anyone else in the world with very low fees and in a fraction of a second, all without a middleman. All you need is altruistic miners who will contribute immense processing power and electricity to authenticate the transactions for the good of humanity.

Another important aspect is privacy. Today, when you do anything online you have to share your data with large organisations. You have to share your name, email and much more. You have no control over how that data is used by those companies. With Web3, you don’t have to share any data. Everyone is authenticated with secret keys. As long as the government agencies do not mind, you can do anything on the internet without revealing anything about yourself.

Imagine a Twitter like service built on Web3. It’s built on top of blockchain, so no central server. You don’t have to give your email to sign up. You sign up using your secret key. You can post anything, except each post costs hundreds of dollars equivalent of that network’s crypto. Why does it cost? Well, the node operators have to be incentivised to keep the node up and running. There are no VCs or ads to fund the show. But hey, no one can delete your account!

A shopping site on Web3. Down with Amazon. Since no personal data is shared, the shopping network has no clue what you like and what you might be interested in purchasing. So, it shows you everything that is there on the network. You like something, but you don’t know what other people think about it. There are no reviews because token holders voted against the idea of adding product reviews. This shopping network is also on a public blockchain for the sake of decentralisation. Each sale costs hundreds of dollars in commission to record the sale on the chain, no matter the price of the merchandise sold. Government agencies have no issues in network allowing anyone to sell anything and not collecting any data about who the buyers and sellers are. A true laissez-faire market.

Web3 is the answer to the evils of capitalism and profit seeking companies. Its goal is to dismantle the monopolies of large corporations and give the power back to end users. It’s about eliminating the rent seeking intermediaries and connect buyers and sellers of various services over internet directly. If it sounds too good to be true, you are a cynic who doesn’t understand the future of technology. 20 years ago, people couldn’t imagine we would be sharing photos of our lunch online, so how can we imagine the wonderful products of Web3? There is no way we will not have the decentralised utopia of Web3.

Down with centralisation. Here comes Web3!

Cover image credit: Joshua Sortino on Unsplash

Categories
Uncategorized

India Mutual Fund NAV API

I have built an API for my personal use for fetching latest NAV of Indian Mutual fund schemes.

The API is at https://yash.info/mfnav/get_mf_nav.php?c={SchemeCode}

The list of all schemes and their codes can be found at https://yash.info/mfnav/list.php

As of today, there are 13,549 mutual fund schemes in India!

AMFI publishes a daily list of latest NAVs in a text file at https://www.amfiindia.com/spages/NAVAll.txt

I have written a script to download this file and parse and enter data into a table. A cron job runs it at 5 AM every day. Then I have built an API to fetch the latest NAV for a single scheme which I use in an Excel Macro to update the latest value of my various MF investments.

If you are building a portfolio tracking tool or just trying to get latest NAV of a scheme, you can use this API. It is free, no registration is required.

Categories
Blockchain

Problems with cryptocurrency and limitations of blockchain

Cryptocurrency was supposed to eliminate middlemen like banks and card networks and reduce transaction time and cost. At present, it is not doing any of that. The middlemen (miners) are still required to authenticate and add the transactions to the blockchain. Since that operation is computationally expensive and there is limited processing capability, miners have to be incentivised to pick up your transaction for validating. It means huge transaction fees (gas fees) and if you want to pay less, your transaction can take anywhere from hours to days to process. It is a highly inefficient system.

When you move money from one account of a bank to another account of the same bank, all the bank has to do is change numbers against two accounts in its database. Since the bank owns and controls the database – there is no incremental cost involved. And often it is free and instant for the customers. Even when you move money across banks, banks have worked out authentication mechanisms and again, all they do is change numbers in their respective databases.

Things are different in the case of a blockchain. Since no central authority owns it, extensive computations are required before blocks of transactions can be added to the chain. That makes it expensive, slow and power-intensive. It is neither sustainable nor scalable.

Crypto-tokens are currently hot because people are buying them with the anticipation of selling them at a much higher price in the future. It’s just another speculative asset. If a government or a central bank issues crypto-tokens then it is no different than fiat currency. Ideologically, a centralised crypto is not what Satoshi Nakamoto had envisioned.

Blockchain is another buzzword. It is touted as a cure to everything from poverty to climate change to alien invasion. First it was cloud, then it was AI now it is Blockchain and Web3. Why does a start-up need blockchain? What does it intend to store in a blockchain which it cannot store in a more traditional relational database? Is it decentralisation? If there is really one entity controlling the blockchain and making all the entries, it is not decentralised. A private blockchain is really pointless.

Blockchain is a very socialistic concept. Which is why it looks good in principle, but when you try to use it in real world, it turns out to be inefficient. Capitalists are in it to make a quick buck rather than actual usage. Capitalism is all about making money from anything, be it Che Guevara t-shirts or blockchain.

So, what are you planning to solve with blockchain?

Categories
Products

Building MagikBanner an AI assisted banner image generator for marketers

I am starting a new project called MagikBanner. An AI assisted banner image generator. I asked a few marketers about where do they get banners and other graphics for their work. Some get it from in-house graphic designers, but most create it themselves using various online and offline tools. Learning those tools can be tricky and it’s also not a marketer’s primary function to create graphics. Especially when you need to create same kind of images for various platforms in various sizes, it can be a real time sink.

Hence, MagikBanner. You can just enter a few words, upload your logo if you wish and press a button and the service will generate a bunch of banner images automatically. It will automatically pick an image or pattern to be used as background, place the caption and logo where it sees fit and add a bunch of other effects and filters. You can select one of the options or generate more banners. Then whatever design you liked you can either tweak it more to your liking or get the design delivered in various sizes.

What kind of banners can be generated with MagikBanner?

  • Facebook and Twitter preview images
  • Facebook and Twitter profile cover images
  • Instagram stories
  • Apple App store and Google Play Store preview images
  • YouTube video thumbnails
  • Blog post featured image
  • Ad banners
  • Pinterest images
  • WhatsApp status images

And more.

Where does the AI come in? I plan on using GPT3 to detect the core theme of the banner and the theme will decide the colors, the fonts, placement of the objects, the image, the pattern. A banner for a CRM tool will have sophisticated business like look and feel, a banner for a cake shop will have informal and pleasing feel to it. Possibilities are endless.

If this sounds interesting, head out to MagikBanner.com and join the wait list to get updates on the progress and get notified when it launches.

Categories
Web Development

WebSocket uses cases and how to implement them with minimal code

I recently built webhooktest.com, it’s a free service to view and inspect the data posted to a webhook URL by a third-party API or service. The website gives you a unique URL which you can use as a webhook and gives you another URL where you can view the data being posted to the webhook URL in real time.

Webhook URL – https://webhooktest.com/some-unique-code

View URL – https://webhooktest.com/some-unique-code/view

The view URL needs to be updated in real time whenever a request is received on the webhook URL. How can we achieve this? The webhook URL makes an entry into a database whenever it receives a request. How can it inform the view URL to fetch the new entry and display it?

One way to do is to have the view URL constantly check the database for any new entries. This is called polling. It is inefficient and resource consuming for obvious reasons. An efficient option is to have the webhook URL notify the view URL about a new request so it can fetch and display the new entry. This can be achieved using WebSocket.

WebSocket is a two way communication protocol and it is natively supported by all modern browsers.

WebSocket is capable of two way communication, so a client can send a message to a server and server can send a message to the client. In my case I just needed the server to intimate the client which in my case is the view page, about the new request that had come.

I have previously implemented WebSocket in ASP.Net, this time since I was working on a Linux server, I have implemented the same in NodeJS.

Whether you are using Node or ASP.Net or any other language, to implement WebSocket you need to handle 4 events – open, close, message and error. Events are same on both the client which is implemented in JavaScript and server which can be in your favorite server side programming language.

Implementing WebSocket server in ASP.Net

If you are working with IIS, you have to make sure WebSocket support is enabled under Turn Windows features on or off.

In .Net you have to implement the Microsoft.Web.WebSockets namespace. Following is the implementation of the WebSocket class in C#.

public class MyWebSocketHandler : WebSocketHandler
{
  public static WebSocketCollection clients = new WebSocketCollection();

  public override void OnOpen()
  {
    clients.Add(this);}

  public override void OnClose()
  {
    clients.Remove(this);
  }

  public override void OnMessage(string message)
  {
    clients.Broadcast(message);
  }

  public static void BroadcastMessage(string message) {
    clients.Broadcast(message);
  }
}

We are maintaining a collection of connected clients. We add to the collection when a new client joins, and we remove the client from the collection when it disconnects. When a message is received from the client, the OnMessage method is called. You can use the Broadcast method of the WebSocketCollection object to send a message to all clients. In the above class I have also created a static broadcast method to be called by external code to broadcast a message to all the connected clients.

Implementing WebSocket server in NodeJS

There are 2 popular packages in NodeJS that implement WebSocket – websocket and ws. I have used ws.

const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 8000 });

wss.on('connection', function connection(ws) {
  ws.on('open', function() {
    console.log('new client connected');
  });

  ws.on('message', function incoming(message) {
    console.log('received: %s', message);
  });

  ws.on('close', function() {
    console.log('a client disconnected');
  });
});

Client side implementation of WebSocket is also very easy.

var ws = new WebSocket("ws://websocket-url");

ws.onopen = function () {
  
}

ws.onmessage = function (e) {
  alert(e.data.toString());
}

ws.onclose = function () {
  
}

When a message is received from the server, the onmessage event is called and you can retrieve the message from the event object and handle it as per your business logic.

This is a very short primer on WebSocket. There are many more detailed tutorials available on WebSocket on the web. WebSocket are useful for building real time collaborative apps like live chat, collaborative editing applications like a white board or something like Google sheets. It can be used for one way messaging from server to client like updating prices, numbers or location on the client.

Categories
Web Development

Running multiple websites on your local development machine

There’s no place like 127.0.0.1 or localhost. You know that you can run only one website on localhost. But what if you have multiple projects and while developing you want to run more than one at the same time? One way you can do is by using a different port for each of them so you can access your projects on
http://localhost
http://localhost:8080
http://localhost:8081 etc.

But there’s another way. You can access your web projects like real websites, which they actually are. So you can have http://mywebsite.local
http://local.mywebsite.com
http://mysecondwebsite.yash
or anything that catches your fancy.

This is possible using hosts file.

You see, when you type any URL in your browser’s address bar, the browser runs a DNS query and fetches IP address for the entered domain. Every computer has a local file called hosts file in which you can specify the IP address for a domain and if the browser (actually OS) finds a domain there, it won’t query the global name servers for the IP of the domain. So if you tell your OS that http://local.mywebsite.com is located at 127.0.0.1 then it won’t look for that domain on the world wide web and instead route the requests for that website to your local computer.

In fact, if you are using local.somesite.com – or any valid global TLD (Top Level Domain), then you can simply add an A record for the local subdomain in the domain’s DNS records and point it to 127.0.0.1.

The location of the hosts file
Windows 10 – C:\Windows\System32\Drivers\etc\hosts
Mac and Linux – /etc/hosts

Open this file in any text editor with administrator/root privileges and enter the entry for your local domain in the following format

127.0.0.1 mywebsite.local

Save the file. Now we need to purge the OS’s DNS cache.

On Windows, open a new command prompt and run
ipconfig /flushdns

On Mac, open terminal and run
sudo killall -HUP mDNSResponder

On Linux, depending on which DNS service your distro is running the command is different.
See this post for more details

This is half the work done, you have just pointed the domain to your local machine. Now you need to prepare your local web server – IIS, Apache or Nginx to handle the request.

IIS
If you have already created the website, right click on the website, select Edit bindings. Click on Add.
Select Type = http, IP Address = All Unassigned and Port= 80. Add your local domain in Host name like mywebsite.local or local.mywebsite.com and click on OK to save it.

If you have not created a website in IIS yet, create a website and specify mywebsite.local as host name while creating.

Apache/Nginx
Create a website in Apache/Nginx using their respective config files. Make sure you specify the host name as mywebsite.local. Save the config and restart apache/nginx.

Now your local webserver is ready to serve requests to http://mywebsite.local

Open http://mywebsite.local in your favourite browser and check it out.