Helping developers to build high-performance DApps quickly

What is Quiknode?

With the evolution of Web3, developers are rapidly building decentralized applications on Ethereum. Building Dapps on Ethereum is cool, though they come with some infrastructure setup drawbacks. You need to set up an ethereum node to interact with the blockchain and this setup needs time, infra and skills. QuikNode solves this problem by providing Ethereum node as Service.

As QuikNode website quotes:

“The fastest and easiest way to run your own Ethereum node.”

Why you should use QuikNode?

Running your own private Ethereum node is cumbersome. There are three problems with that:

  • Infra — Blockchains are distributed Ledgers and a full node means the entire copy of the ledger, that maybe not possible on the home computer anymore as ethereum blockchain size is around 4TB now, even fast/full sync is around 300 GB.
  • Time — First time syncing takes time and syncing Ethereum MainNet can take days, depending on the internet speed.
  • Skills — Node clients are cranky, you'll need to tune your environment and keep a close eye on them. You'll also need to consider the security of your node. You need to have some cybersecurity skills to secure your node.

What QuikNode provides?

QuikNode solves this problem by providing you a full node on a click of a button. Instead of using shared public nodes, QuikNode provides you a dedicated node. QuikNode is optimized for performance, speed, and flexibility. Let's see how QuikNode achieves this.

Dedicated Node- With the use of dedicated nodes helps you increase performance for your blockchain queries as it’s only taking queries for your DApp.

Multiple Zones- QuikNode supports 8 different Zones. That helps in optimizing networks call time which boosts speed and performance for your DApp.

Multiple Testnet support — QuikNode support almost all famous ethereum testnets. That gives immense flexibility to a developer by testing application on their preferred testnet.

Archive Nodes — QuikNode provide Parity archive nodes too. An archive node keeps full copy of blockchain ledger in comparison to full nodes who may do pruning for obvious infra reasons. This is very important feature for businesses benefit from blockchain analysis and research. You can learn more about QuikNode archive nodes here.

Also, QuikNode support Parity and Geth both client. Isn’t it cool? 😃

Signing up with QuikNode

Let’s sign up for the QuikNode. Once you have completed  registration, you can configure your node. You can choose Network, Zone, Client, and Synchronization mode. After launch, you will see your nodes and status for each in your dashboard:

Connecting with QuikNode

I have created a Kovan Testnet and my zone is Bangalore (India). Remember, your node has to be in READY, otherwise, it will not work. You can rebuild your node or contact QuikNode team if you face any problem.

Connection URI

QuikNode supports both HTTPProvider and Websockets (we will see them later). You can find these links at the top of the Node dashboard:

Now Let’s deep dive in some code.

Sending Ethereum transaction using web3js and QuikNode

Let's test QuikNode and see how it works. To start, let’s broadcast a raw transaction with QuikNode using web3js.

Let’s create a node js project and install Web3js. Create a project directory and run below commands.

mkdir quiknode
cd quiknode
npm init
npm install web3

Setup Web3 using QuikNode

Let’s create an Index.js file and setup web3. As you can see we add using QuikNode HttpProvider link. We will connect to our node using this link. Now all the commands we will run will be going through this node and will use Kovan Network.

const Web3 = require('web3')
const httpProvider = "https://mistakenly-smart-jay.quiknode.io/86d9e35e-8cdb-47ad-80a4-84f9e9537afa/C0_tKUunhUc0rM_i1HMxHA==/"
var web3 = new Web3(new Web3.providers.HttpProvider(httpProvider));
To test the network add these line and check the network id, Kovan network Id is 42.
web3.eth.net.getId(function(err, data){console.log(data);})

Creating an account

Let’s create a new ethereum account on Kovan network.

web3.eth.getBalance('0x75E18d32f2DbEEfaF4055aD709BDe98eCB57C379', (err, wei) => {
balance = web3.utils.fromWei(wei, 'ether')console.log(balance);});

This will give us a private key and address, using which we will create a raw transaction.

You can check the balance using below

web3.eth.getBalance('0x75E18d32f2DbEEfaF4055aD709BDe98eCB57C379', (err, wei) => {
balance = web3.utils.fromWei(wei, 'ether')console.log(balance);});

Signing an Ethereum transaction

Let’s get some Test ethers using Kovan network faucet and sign a transaction. Ethier, you can generate a new address as a recipient or just use any address from Kovan block explorer.

web3.eth.accounts.signTransaction({    
    from: address, // our address     
    to: address2,  // any other kovan network address you want to send
    value: '2000000000000000',    
    gas: '8000000'},privateKey, function(err, data) {    	      console.log(data);
 });

Sending transaction

Now let’s broadcast this signed transaction using QuikNode.

web3.eth.accounts.signTransaction({
    from: address,
    to: address2,
    value: '2000000000000000',
    gas: '8000000'
}, privateKey, function(err, data) {
    web3.eth.sendSignedTransaction(data.rawTransaction, function(err, receipt) {
        console.log("receipt", receipt);
        web3.eth.getTransaction(receipt, function(err, data) {
            console.log("transaction", data);
        })
    });
});

We have successfully sent a transaction using QuikNode on Kovan network, you can check this transaction on Kovan block explorer.

Using WebSockets with QuikNode

QuikNode supports WebSockets too. You can find a web socket connection link under Dev Tools. Either you can use it with HTTPs Auth or Token Auth. Token auth link will look like something below.

- Token auth: wss://mistakenly-smart-jay.quiknode.io/86d9e35e-8cdb-47ad-80a4-84f9e9537afa/C0_tKUunhUc0rM_i1HMxHA==/

WebSockets allow both the server and the client to push messages at any time without any relation to a previous request as opposed to HTTP where the client creates a connection with the server every time. In WebSocket connection get created once, server and client push messages using the connection. Websockets are best for an event-based system. Websockets are supported by almost every browser.

Subscribing pending Transaction events

Let’s subscribe pending transaction of Ethereum blockchain. You can see we are passing QuikNode WebSocket URI while initializing web3.

const Web3 = require('web3') const webSocket = "wss://mistakenly-smart-jay.quiknode.io/86d9e35e-8cdb-47ad-80a4-84f9e9537afa/C0_tKUunhUc0rM_i1HMxHA==/"
var web3 = new Web3(webSocket);
var subscription = web3.eth.subscribe('pendingTransactions', function(error, result) {
    if (!error) console.log(result);
}).on("data", function(transaction) {
    console.log(transaction);
});

QuikNode with Truffle

Let’s see how we’ll use QuikNode with Truffle and deploy smart contracts. So for that lets download Truffle Petshop. We will simply unbox it and deploy it using QuikNode.

truffle unbox pet-shop

We will use truffle-HD-wallet to deploy our pet-shop smart contracts. So you need to install it too.

npm install truffle-hdwallet-provider

Now let’s see the configuration of our Truffle’s config. We will simply add HttpProvider URI to use QuikNode as mentioned below.

var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "YOUR_MEMONICS"; // use a funded wallet
module.exports = {
    networks: {
        development: {
            host: "127.0.0.1",
            port: 7545,
            network_id: "*" // Match any network id        
        },
        kovan: {
            provider: function() {
                return new HDWalletProvider(mnemonic, "https://mistakenly-smart-jay.quiknode.io/86d9e35e-8cdb-47ad-80a4-84f9e9537afa/C0_tKUunhUc0rM_i1HMxHA==/")
            },
            network_id: 42
        }
    }
};

QuikNode Stats Features

So now let's talk about QuikNode’s Stat feature which gives you visibility what's happening with your Dapp.

  • Stats / Node Peers / Node Logs — QuikNode provides different types of stats, by which you can measure your Dapps Usage. You can check the number of requests, Load on your node and WebSocket messages other things. QuikNode also provides peers contacted your node and the logs.
QuikNode Metrics

Conclusion

QuikNode is an awesome and useful addition to the Ethereum ecosystem. It’s fast and completely private. Many high performances DApps will end up running their own node for better performance. Now they don’t need to set up the node. QuikNode’s team is awesome and you can reach them via Slack.

Note: Mentioned QuikNode links will not work, my QuikNode subscription is expired.