Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proxy server for RPC endpoint using Express

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 Solana getBalance method via the @solana/web3.js library.

Read the full guide on the Chainstack developer portal:

Quickstart

Clone the repository:

git clone https://github.com/akegaviar/express-proxy-server.git

Edit the .env.sample file to include your node RPC URL key and rename it to .env.

SOLANA_RPC_URL="YOUR_CHAINSTACK_SOLANA_NODE_URL"
PORT=4000

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":"52C9T2T7JRojtxumYnYZhyUmrN7kqzvCLc4Ksvjk7TxD"}'

You will also find a basic front end in the src directory. You can run it in your browser and test the proxy server.

  1. Insert the address you want to query in the input field.
  2. 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!

Prerequisites

Deploy a node with Chainstack:

  1. Sign up with Chainstack.
  2. Deploy a node.
  3. View node access and credentials.

About

This project is a simple express.js proxy server to send post requests to a blockchain using the Solana web3.js library, hiding your endpoint URL

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages