"Request-Rate Exceeded for default API keys" even though I'm using my own API key

========= NOTICE =========
Request-Rate Exceeded (this message will not be repeated)

The default API keys for each service are provided as a highly-throttled,
community resource for low-traffic projects and early prototyping.

While your application will continue to function, we highly recommended
signing up for your own API keys to improve performance, increase your
request rate/limit and enable other perks, such as metrics and advanced APIs.

For more details: Provider API Keys

==========================

I receive this notice regularly, even though I am using my personal Infura Project ID. I know for sure it’s using it because I see my requests getting charted in the Infura dashboard.

Since it says using your own API keys will improve performance etc, I want to get this working right.
What could be the reason that I’m getting this notice?

I’m using this code:

require("dotenv").config()
const Web3 = require('web3');
const web3 = new Web3(
  new Web3.providers.WebsocketProvider(process.env.INFURA_URL)
);

And I have this line in .env:

INFURA_URL = wss://mainnet.infura.io/ws/v3/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

where xxxxxxxxxxxxxxxxxxxxxxxxxxx is my project ID.

Hi @James - if you’re using JS, it looks like your string interpolation may be incorrect - you would need to wrap your process.inv.INFURA_URL inside backticks and the ${ } string interpolation syntax like so:

const web3 = new Web3(new web3.providers.WebsocketProvider(`${process.env.INFURA_URL}`);

Let us know if you’re still running into this issue after trying that!

Hi, thanks. I tried it and it makes no difference. Still getting the notice.

Hmm. What method are you calling on the WebSocket? If you can provide the whole block of code, I may be able to better assist you.

I suspect it is being caused by this:

require("dotenv").config()
const Web3 = require('web3');
const web3 = new Web3(
  new Web3.providers.WebsocketProvider(process.env.INFURA_URL)
);
const { ChainId, Token, TokenAmount, Pair } = require('@uniswap/sdk');

const [dai, weth] = await Promise.all(
  [addresses.tokens.dai, addresses.tokens.weth].map(tokenAddress => (
    Token.fetchData(ChainId.MAINNET, tokenAddress)
)));

The call to the Uniswap SDK method ‘Token.fetchData’ here doesn’t specify the provider.

I just figured out from the SDK code that you can pass a provider as the third argument. If you don’t, it sets its own defaultProvider which will not use any personal API key.

However, when I pass web3.currentProvider (or web3.eth.currentProvider?) as the 3rd argument to Token.fetchData, I get an error “invalid signer or provider (argument=“signerOrProvider”, value=”[object Object]", code=INVALID_ARGUMENT,", so it is unclear to me how to do this.

Okay, we’re taking a look. In the meantime, can you provide me with some context for what you’re trying to do with this block of code?

Thanks.
It’s for trading DAI vs WETH on Uniswap.
To do that it first needs to get the Tokens (code above) and then the Pair, like this:

const daiWeth = await Pair.fetchData(dai, weth);

Pair.fetchData can also take a provider as a 3rd argument.

According to the Uniswap docs, it should accept an ethers web3 provider as an argument, but your error is indicating it isn’t accepting that. I would double-check that you’re passing the correct type of object, and if that doesn’t work, it may be an SDK bug.

Ok, I will take a look. Thank you.

I’m seeing the same issue, I tried passing in web3.provider and it’s not throwing any errors, but still occasionally seeing the warning about default keys when i’m using my own api key

Hi @sterling000, and welcome to the Infura community!

How frequently are you seeing this warning message? Not sure why that would be happening when you’re using your own API keys, but want to know the frequency so we can figure out how to best figure out what’s going on :slight_smile:

It happens roughly 90 seconds after I launch my app which polls for some token prices with each newBlockHeaders.data.

Got the same warning when I try to use UNISWAP/SDK