How to set Referer Whitelist http header in solana web3, web3js, ethers

Last updated: April 4, 2025

You may have encountered an error like this 401 Unauthorized: {"error":"2 errors occurred:\\n\\t* validator: ProInstanceRequestValidateToken, token not found in path /8d0365a9ff0d9117d8797af14a50a5694b1c7fcc/\\n\\t* validator: ProInstanceRequestValidateReferer, null referer not permitted\\n\\n","instance":"twilight-maximum-gadget","request-id":""}

This means you have a Referer Whitelist url set but didn’t pass it correctly. Let’s take a look at how to do this in various SDKs.

Solana

When using the Solana Web3 Javascript SDK, you’ll have to pass a second parameter in a JSON object form like so

const web3 =  require("@solana/web3.js");

(async () => {
  // Connect to cluster
  const connection = new web3.Connection(
    'https://<QUICKNODE-ENDPOINT-NAME>.solana-mainnet.quiknode.pro/<TOKEN>/',
    {
        httpHeaders: {
            'Content-Type': 'application/json',
            'Referer': '<http://example.com>' // set your Referer url here
        }
    }
  );
  
  // Uncomment the below command to test your connection to your node
  // console.log(await connection.getEpochInfo())

  let currentSlot = await connection.getSlot();
  console.log(`Current slot: ${currentSlot}`);
})();

Have a look into the sdk code here, you’ll see all the configs that can be defined in that code block.

Web3js

const { Web3 } = require('web3');

async function main() {
    const url = "https://<QUICKNODE-ENDPOINT-NAME>.quiknode.pro/<TOKEN>/'";
    const httpOptions = {
        providerOptions: {
            headers: {
                'Content-Type': 'application/json',
                'Referer': '<https://qn-test.com>',
            },
        }
    }
    const web3 = new Web3(new Web3.providers.HttpProvider(url, httpOptions))
    const block = await web3.eth.getBlock(12232253);
    console.log(block);
}

main()

You can view other configuration params here

Web3py

from web3 import Web3, HTTPProvider
import requests

# Set up a web3 instance using an HTTP provider
session = requests.Session()
session.headers.update({'Referer': '<http://example.com>'})
web3 = Web3(HTTPProvider('https://<QUICKNODE-ENDPOINT-NAME>.quiknode.pro/<TOKEN>/', session=session))

# Get the current block number
block_number = web3.eth.block_number

# Print the current block number to the console
print("Current block number:", block_number)

Vanilla JS (No SDK)

async function main() {
  let headersList = {
    "Content-Type": "application/json",
    "Referer": "<http://example.com>"
  }

  let bodyContent = JSON.stringify({ "method": "getSlot", "params": [], "id": 1, "jsonrpc": "2.0" });

  let response = await fetch("https://<QUICKNODE-ENDPOINT-NAME>.quiknode.pro/<TOKEN>/", {
    method: "POST",
    body: bodyContent,
    headers: headersList
  });

  let data = await response.text();
  console.log(data);
}

main();

EthersJS

In ethers.js, you can set the Referer Whitelist HTTP header as follows:

const { ethers } = require("ethers");

const provider = new ethers.providers.StaticJsonRpcProvider({
    url: "https://<QUICKNODE-ENDPOINT-NAME>.quiknode.pro/<TOKEN>/",
    headers: { "Referer": "<http://example.com>" }
});

(async () => {
    // Example usage
    const blockNumber = await provider.getBlockNumber();
    console.log("Current block number:", blockNumber);
})();

You can find more information about configuring the provider here.

 

If there are any questions, please feel free to reach out to support.