Skip to content

chainstacklabs/express-rest-api-proxy-server

Repository files navigation

Labs

Chainstack is the leading suite of services connecting developers with Web3 infrastructure

         

HomepageSupported protocolsChainstack blogChainstack docsBlockchain API referenceStart for free

Proxy server for REST API keys using Express

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

Project details

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.

Quickstart

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 a clean install of the dependencies, this will install the same version as in the package.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!

Prerequisites

About

This project shows how you can protect your Etherscan API key by creating your own back-end server where you store the API key

Topics

Resources

License

Stars

Watchers

Forks