• Homepage • Supported protocols • Chainstack blog • Chainstack docs • Blockchain API reference • Start for free •
This project shows how to protect your RPC URL by creating a back-end server where you store the endpoint. Then, when you click the button to check the balance, the front end will send a request to the back-end server using the eth_getBalance
method via the web3.js
library.
Read the full guide on the Chainstack developer portal:
For this use case, we built a simple app that allows you to input an Ethereum address and returns the address balance by sending an eth_getBalance
request to an Ethereum node.
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-proxy-server-to-protect-your-rpc-url-endpoint.git
Edit the .env.sample
file to include your node RPC URL key and rename it to .env
.
ETHEREUM_RPC_URL="YOUR_CHAINSTACK_NODE_URL"
Install dependencies:
npm install
Run the server in dev mode with:
npm run dev
The server is now running on http://localhost:4000/
. You can send balance requests to your server with the following:
curl --location 'http://localhost:4000/balance' \
--header 'Content-Type: application/json' \
--data '{"address":"0xc457C11e2d7b6Ed68516CdED897c2Ab9F41e022C"}'
You will also find a basic front end in the src
directory. You can run it in your browser and test the proxy server.
- Insert the address you want to query in the input field.
- Click Check balance to send a request to your RPC node and retrieve the address' balance.
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
- A node RPC endpoint.
Deploy a node with Chainstack: