To use the Stable API you'll need to create a free Alchemy account first!
Stable is a high-performance, EVM-compatible Layer 1 blockchain with USDT as the native gas token, designed for stablecoin payments and settlements with ultra-low fees and instant finality.
The Stable API lets you interact with the Stable network through a set of JSON-RPC methods. If you've worked with Ethereum's JSON-RPC APIs, the design will feel familiar.
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-npmRun the following commands to create and initialize your project:
mkdir stable-api-quickstart
cd stable-api-quickstart
npm init --yesThis creates a new directory named stable-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://stable-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);
});Replace your-api-key with your actual Alchemy API key from the Alchemy Dashboard.
Run your script to make a request to the Stable network:
node index.jsYou should see the latest block information from Stable's network outputted to your console:
Latest Block: 0x...You've made your first request to the Stable network. You can now explore the various JSON-RPC methods available on Stable and start building your dApps.