Closed ashrhmn closed 2 years ago
Hey @ashrhmn.
useDApp is automatically quering for block number, and quering for new state for every new block, in order to keep the state up-to-date.
You can configure this behaviour using refresh
in your useDApp config, to make the requests less frequently, for example every 5 blocks.
However, the amount of calls to eth_chainId
is wrong - in version 1.0.8
, we made some changes to address this, but apparently they still exist. We should not continiously query for the chain Id that is known.
There is something weird, because on an example app, I reproduced the reporting in Infura with a lot of eth_chainid
calls, BUT - I do not see them in browser devtools network inspector, just at the beginning which is expected.
I took another whack at it yesterday and today.
So it does not seem like I have a large number of eth_chainid
calls - just 1-3 at the beginning, and none later (which is the expected behaviour).
So @ashrhmn there must be something wrong with your setup, that it racks up so many eth_chainid
calls. Is your list of readOnlyUrls
a list of strings? Internally it will create a StaticJsonRpcProvider
which knows not to query for chainId - this is since useDapp 1.0.8 I think.
As for other networks - do you not have any hooks using the other chains? It might be just requests to keep the block number up-to-date.
I am not sure what I am doing wrong here. This is just all for the config.
function MyApp({ Component, pageProps }: AppProps) {
const config: DAppProviderProps["config"] = {
readOnlyUrls: RPC_URLS,
};
return (
<DAppProvider config={config}>
<Component {...pageProps} />
<Toaster position="top-right" />
</DAppProvider>
);
}
export const RPC_URLS: { [chainId: number]: string } = {
1: `https://mainnet.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_KEY}` as string,
3: `https://ropsten.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_KEY}` as string,
4: `https://rinkeby.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_KEY}` as string,
5: `https://goerli.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_KEY}` as string,
42: `https://kovan.infura.io/v3/${process.env.NEXT_PUBLIC_INFURA_KEY}` as string,
56: `https://bsc-dataseed.binance.org/`,
43114: `https://api.avax.network/ext/bc/C/rpc`,
97: `https://data-seed-prebsc-1-s1.binance.org:8545/`,
80001: `https://matic-mumbai.chainstacklabs.com`,
4002: `https://rpc.testnet.fantom.network`,
43113: `https://api.avax-test.network/ext/bc/C/rpc`,
137: `https://polygon-rpc.com`,
};
@ashrhmn Ok looks good
I am being rate limited on my infura.io account for doing more than 100k requests a day. I checked the dashboard about what were the requests and found these.
So what kind of usage do you have? Do you have the app deployed and used?
Also I see some (faling) requests for net_version
- That I don't think comes from useDApp.
I previously had the useDapp hooks set up, but after the issue, I switched to this approach for fetching. Still, the problem is not fixed. Is there anything wrong with getDefaultProvider
?
useEffect(() => {
try {
(async () => {
if (!projectAddress || !projectChainId || !RPC_URLS[projectChainId])
return;
const contract =
collectionType === "721"
? Collection721__factory.connect(
projectAddress,
getDefaultProvider(RPC_URLS[projectChainId])
)
: Collection1155__factory.connect(
projectAddress,
getDefaultProvider(RPC_URLS[projectChainId])
);
setFeeAddressBgProc((v) => v + 1);
setMaxMintInTotalPerWalletBgProc((v) => v + 1);
setBaseURIBgProc((v) => v + 1);
const [
feeToAddress,
baseURI,
maxMintInTotalPerWallet,
revealTime,
] = await Promise.all([
contract.feeDestination().catch((e) => {
console.log("Error getting feeDestination : ", e);
return "";
}),
contract.baseURI().catch((e) => {
console.log("Error getting baseURI : ", e);
return "";
}),
contract.maxMintInTotalPerWallet().catch((e) => {
console.log("Error getting maxMintInTotalPerWallet : ", e);
return 0;
}),
contract.revealTime().catch((e) => {
console.log("Error getting revealTime : ", e);
return BigNumber.from(0);
}),
]);
setConfigSet((c) => ({
...c,
feeToAddress,
baseURI,
maxMintInTotalPerWallet: +maxMintInTotalPerWallet.toString(),
revealTime: revealTime.toNumber(),
}));
setFeeAddressBgProc((v) => v - 1);
setBaseURIBgProc((v) => v - 1);
setMaxMintInTotalPerWalletBgProc((v) => v - 1);
})();
} catch (error) {
setMaxMintInTotalPerWalletBgProc((v) => v - 1);
setBaseURIBgProc((v) => v - 1);
setFeeAddressBgProc((v) => v - 1);
console.log("Error fetching : ", error);
}
}, [collectionType, projectAddress, projectChainId]);
@ashrhmn It might be. Instead, try:
import { providers } from 'ethers'
const { StaticJsonRpcProvider } = providers
new StaticJsonRpcProvider(RPC_URLS[projectChainId])
I tested for a day. Using StaticJsonRpcProvider drastically reduced network calls. The last 24h reporting says a total of around 5k calls to the API.
Still, I am having a lot of chainId requests but that is negligible I guess.
Doing Multiple Request automatically to the readonlyUrls passed in the config
To Reproduce
const config: DAppProviderProps["config"] = { readOnlyUrls: RPC_URLS };
Here RPC_URLS is of type{ [chainId: number]: string }
with all the RPC URLs.Software versions
useDapp
version (installed version of@usedapp/core
) : 1.0.15node --version
) : 16.15.0Additional context
I am being rate limited on my infura.io account for doing more than 100k requests a day. I checked the dashboard about what were the requests and found these.
As I am not doing these requests manually, is the useDapp module sending requests at this rate automatically?
As you can see, networks other than rinkeby was also used to request to the provider but I was doing the dev testing using only rinkeby. So, why are these requests spiking up automatically?