So the thing is, by using React I see no way not to expose my API KEY. Is there any best practices on how to store it? Is it dangerous if someone will inspect my code and find this API key? How people solving this problem?
2 Answers
Is it dangerous if someone will inspect my code and find this API key? How people solving this problem?
There is no way around this problem and your API keys will always leak.
If you want to mitigate the issue you can create your special server that proxies requests to Alchemy and then manually control IP bans and such.
-
1
-
Yes, it is trivial ,because any one can check the API key from Web developer tools directly in Networks tab. There is no point to obfuscate. Jun 29 at 11:14
-
1Almost all RPC API providers have a Domain restrictions, just set Domain(s) in the admin panel (Alchemy, Infura … etc) and you will not need to hide your KEY.– ArchiJun 29 at 18:32
-
Note that domain restriction does not help much, as the most of the API key abuse is server-side and server-side clients can set the domain to any value they wish. Jun 30 at 7:25
make a .env file and store in it, never push your env file to any git repo or anywhere
-
this is not an answer, that's not how env works in browser. env will be hidden in nodejs env only– PaulJun 29 at 7:57