To use the Pharos API you'll need to create a free Alchemy account first!
Pharos is a high-performance, EVM-compatible Layer 1 blockchain that combines modular architecture and deep-parallel execution to deliver sub-second finality and high throughput, designed to unify Web2 and Web3 assets and liquidity.
The Pharos API allows interaction with the Pharos network through a set of JSON-RPC methods. Its design is familiar to developers who have worked with Ethereum's JSON-RPC APIs, making it intuitive and straightforward to use.
Select a package manager to manage your project's dependencies. Choose between npm and yarn based on your preference or project requirements.
# Begin with npm by following the npm documentation
# https://docs.npmjs.com/downloading-and-installing-node-js-and-npmOpen your terminal and execute the following commands to create and initialize your project:
mkdir pharos-api-quickstart
cd pharos-api-quickstart
npm init --yesThis creates a new directory named pharos-api-quickstart and initializes a Node.js project within it.
Install Axios, a popular HTTP client, to make API requests:
npm install axiosCreate an index.js file in your project directory and paste the following code:
const axios = require('axios');
const url = 'https://pharos-mainnet.g.alchemy.com/v2/your-api-key';
const payload = {
jsonrpc: '2.0',
id: 1,
method: 'eth_blockNumber',
params: []
};
axios.post(url, payload)
.then(response => {
console.log('Latest Block:', response.data.result);
})
.catch(error => {
console.error(error);
});Remember to replace your-api-key with your actual Alchemy API key that you can get from your Alchemy dashboard.
Execute your script to make a request to the Pharos network:
node index.jsYou should see the latest block information from Pharos's network outputted to your console:
Latest Block: 0x...Congratulations! You've made your first request to the Pharos network. You can now explore the various JSON-RPC methods available on Pharos and start building your dApps on this innovative platform.