"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: https://docs.ethers.io/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.