• Homepage • Supported protocols • Chainstack blog • Chainstack docs • Blockchain API reference • Start for free •
This project shows how you can protect your Etherscan API key by creating your own back-end server where you store the API key.
Read the full guide on the Chainstack developer portal
For this example, we built a simple app that uses the Etherscan API to retrieve the latest block from the Ethereum network and then display it on the screen.
It is built using the Express.js
framework, and the main server code is in the index.js
file that you can find in the root directory.
Clone the repository:
git clone https://github.com/soos3d/node-api-proxy-server.git
Edit the .env.sample
file to include your Etherscan API key and rename it to .env
.
ETHERSCAN_API_KEY_VALUE="YOUR_API_KEY"
Install dependencies:
npm ci
Use
npm ci
to launch aclean install
of the dependencies, this will install the same version as in thepackage.json
file.
Run page in dev mode with:
npm run dev
The server is now running on http://localhost:4000
. You can send a request to it with:
curl --location 'http://localhost:4000/api'
You will also find a basic front end in the src
directory. You can run it in your browser and test the proxy server.
If you check the source code from the browser, you won't be able to find the API key used!
- Node.js: ^16.17.0— install Node
- Etherscan API key