The Stable-Pi-Core API Gateway is a modular and extensible API gateway designed to facilitate interactions with various blockchains, including Ethereum and Bitcoin. It provides a unified interface for fetching blockchain data, sending transactions, and querying prices.
- Modular Architecture: Easily extendable to support additional blockchains and services.
- RESTful and GraphQL APIs: Provides both RESTful endpoints and a GraphQL interface for flexible data retrieval.
- Authentication: Supports JWT-based authentication for secure access to protected routes.
- Logging and Error Handling: Centralized logging and error handling for better monitoring and debugging.
-
Clone the repository:
git clone https://github.com/KOSASIH/stable-pi-core.git cd stable-pi-core
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the root directory and add the following variables:PORT=4000 ETHEREUM_API_URL=https://api.etherscan.io/api BITCOIN_API_URL=https://api.blockcypher.com/v1/btc/main JWT_SECRET=your_jwt_secret
-
Start the server:
npm start
The API Gateway will be running at
http://localhost:4000
.
-
Ethereum Endpoints:
GET /api/ethereum/block/:blockNumber
: Fetch Ethereum block data by block number.GET /api/ethereum/transaction/:transactionHash
: Fetch Ethereum transaction data by transaction hash.POST /api/ethereum/contract/:contractAddress/call
: Call a method on a smart contract (requires authentication).
-
Bitcoin Endpoints:
GET /api/bitcoin/block/:blockHeight
: Fetch Bitcoin block data by block height.GET /api/bitcoin/transaction/:transactionHash
: Fetch Bitcoin transaction data by transaction hash.POST /api/bitcoin/send
: Send a Bitcoin transaction (requires authentication).GET /api/bitcoin/price
: Fetch the current Bitcoin price.
The GraphQL API is available at http://localhost:4000/graphql
. You can use the following queries:
-
Ethereum Queries:
query { ethereumBlock(blockNumber: "0x10d4e") { number hash transactions { hash from to value } } ethereumTransaction(transactionHash: "0x5c69b...") { hash from to value } }
-
Bitcoin Queries:
query { bitcoinBlock(blockHeight: "100000") { number hash transactions { hash from to value } } bitcoinTransaction(transactionHash: "0x5c69b...") { hash from to value } bitcoinPrice }
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your branch to your forked repository.
- Create a pull request describing your changes.
This project is licensed under the MIT License. See the LICENSE file for details.