How to add Custom RPC to Phantom and Solflare
3 min read
Using a non-custodial wallet is a necessity when interacting with web3 dApps. Phantom and Solflare are the most widely used Solana non-custodial wallets.
Most non-custodial wallets (including Phantom and Solflare) come with default RPC nodes set up. Using these wallets with default networks is acceptable for the majority of applications most of the time. However, suppose the operations you are performing require transactions to reach the chain faster or updating a balance where the latest information is crucial - in that case, a fast, reliable RPC node can come in handy. Sometimes the nodes behind these wallets may experience some downtime or lag as these wallets are public and a lot of people are accessing them at the same time. During such times, having a custom RPC node can come in handy.
What You Will Do
In this guide, we will see how to add a custom RPC to Phantom and Solflare.
What You Will Need
- Nodejs installed (version 16.15 or higher)
- Phantom Wallet or Solflare extension installed
- HTTP Proxy installed
- A text editor
- npm or yarn installed (We will be using npm to initialize our project and install the necessary packages. Feel free to use yarn instead if that’s your preferred package manager)
Booting a Solana Node
The purpose of setting up a custom RPC in these wallets is to have a fast, reliable RPC node behind the wallet, which is why we will use QuickNode for this. So just grab a free QuickNode and head over to the next step.
You'll need the HTTP Provider link later, so copy it and save it.
Adding Solana Node to Phantom and Solflare
Now that we have a QuickNode Solana RPC, let us use it to power our wallets:
Step 1: Go to your Phantom wallet and click on the settings icon on the bottom right. Then scroll down and click on 'Change Network'.
Step 2: Select the fourth option, 'Localhost,' and return to the wallet home screen. Now, you must see a message 'Failed to get assets' because we still have not set up our RPC to work with Phantom.
Step 3: Currently, there is no way to add a custom RPC in Phantom directly, so we will use a Node.js proxy server to listen to a port that Phantom wallet listens on and resolve to our QuickNode RPC.
First, make a directory and install http-proxy using npm(Node Package Manager), which comes with Node.js:
npm i http-proxy
Now, create a server.js file in the directory and copy-paste the following code snippet into it:
var http = require('http'),
httpProxy = require('http-proxy');
console.log("listening on: 8899");
Replace ADD_YOUR_QUICKNODE_HTTPS_URL_HERE with your QuickNode Solana node's HTTP Provider URL we got in the previous step and save the file.
Explanation of the code above:
Lines 1-2: Importing http and http-proxy packages/libraries.
Line 3: Creating a proxy server to listen on localhost port number 8899 and resolving to our QuickNode Solana node.
Line 4: Printing a text when the server is listening.
Now, run the file by entering the following in your terminal:
Open your Phantom wallet, and now it should load all your assets successfully with a banner on top saying, "You are currently on Localhost".
Congrats! You have connected your Phantom Wallet to your QuickNode HTTP Endpoint. Now, let's configure Solflare.
Step 1: Go to your Solflare wallet and click on the setting logo on the bottom right. Then click on Network.
Step 2: Click on ADD CUSTOM NODE. Enter a name for your node (QuickNode RPC in this example) and then paste your QuickNode Solana Node's RPC URL in the second field. Click Save and then click Proceed. Your QuickNode RPC is set up in Solflare now.
In this tutorial, we learned about setting up custom RPC in Phantom and Solflare wallets. To learn more, check out some of our other Solana tutorials or subscribe to our newsletter.
We ❤️ Feedback! If you have any feedback or questions on this guide, please let us know.
Also, feel free to reach out to us via Twitter or our Discord community server. We’d love to hear from you!