Alchemy Logo

Avalanche P-Chain API Quickstart

How to get started with the Avalanche Platform Chain (P-Chain) using Alchemy

Don't have an API key?

Build faster with production-ready APIs, smart wallets and rollup infrastructure across 70+ chains. Create your free Alchemy API key and get started today.

The Avalanche Platform Chain (P-Chain) is the metadata chain on Avalanche that coordinates validators, manages staking, and handles creation of subnets and blockchains. Unlike the Avalanche C-Chain (EVM), the Avalanche P-Chain uses the platform.* JSON-RPC API for validator set management, delegations, and subnet operations.

The Avalanche P-Chain is now live on both Mainnet and Fuji. Use the same Alchemy base URLs as Avalanche C-Chain and append /ext/bc/P after your API key in the path.

Select a package manager to manage your project's dependencies. The choice between npm and yarn depends on your preference or project requirements.

npmyarn
Follow the npm documentation.Refer to yarn's installation guide.

Open your terminal and run:

mkdir avalanche-p-api-quickstart
cd avalanche-p-api-quickstart
npm init --yes

This creates a new directory and initializes a Node.js project.

Create an index.js file in your project directory. The following example uses native fetch (Node.js 18+), so no extra dependencies are needed. Replace YOUR_ALCHEMY_API_KEY with your Alchemy API key.

(async () => {
  const API_KEY = 'YOUR_ALCHEMY_API_KEY';
  const url = `https://avax-mainnet.g.alchemy.com/v2/${API_KEY}/ext/bc/P`;
 
  try {
    const response = await fetch(url, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'platform.getHeight',
        params: {}
      })
    });
 
    if (!response.ok) {
      throw new Error(`HTTP ${response.status}: ${await response.text()}`);
    }
 
    const data = await response.json();
    if (data.error) {
      throw new Error(data.error.message || 'RPC error');
    }
    console.log('P-Chain height:', data.result?.height ?? data);
  } catch (error) {
    console.error('Error fetching P-Chain height:', error.message);
  }
})();

Run the script:

node index.js

You should see the current P-Chain height in the console (e.g. P-Chain height: 35000000).

You can also call the API with curl from the terminal. Example for Mainnet (platform.getHeight):

curl -X POST https://avax-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY/ext/bc/P \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"platform.getHeight","params":{}}'

Example for Fuji (platform.getTimestamp):

curl -X POST https://avax-fuji.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY/ext/bc/P \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"platform.getTimestamp","params":{}}'

curl -X POST https://avax-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY/ext/bc/P \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"platform.getCurrentValidators","params":{}}'

To filter by subnet or specific node IDs, pass optional params:

curl -X POST https://avax-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY/ext/bc/P \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"platform.getCurrentValidators","params":{"subnetID":"11111111111111111111111111111111LpoYY"}}'

curl -X POST https://avax-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY/ext/bc/P \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"platform.getMinStake","params":{"subnetID":"11111111111111111111111111111111LpoYY"}}'

curl -X POST https://avax-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY/ext/bc/P \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"platform.getSubnets","params":{}}'
Was this page helpful?