StakingApiClient

The object for accessing all network-specific methods of P2P.ORG Staking SDK.

A StakingApiClient object is initialized with a base URL and an authentication token that will be used by various methods.

import { StakingApiClient } from '@p2p/staking-api';

const client = new StakingApiClient({
  baseUrl: 'https://api.p2p.org',
  token: 'eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9',
  retry: {
    retryOn: [429, 500, 502, 503],
    retryDelayMs: 500,
    retries: 3,
  },
});

The methods for each supported network can be accessed via a specific field in the StakingApiClient object. For example:

await client.solana.stake({
  network: 'mainnet-beta',
  feePayer: '9i5cTqci1W6DHdYfT7WbiNhP5DXvnPNTXvS9fTBFfuSw',
  fromPublicKey: '9i5cTqci1W6DHdYfT7WbiNhP5DXvnPNTXvS9fTBFfuSw',
  amount: 1002282880,
});

Currently, the following networks are supported:

More networks will be added in future versions.

Parameters

baseUrl string, required
The base URL for all P2P.ORG API endpoints:

  • https://api.p2p.org for production,
  • https://api-test.p2p.org for testing.

token string, required
The authentication token for accessing P2P.ORG API.

retry object
Parameters that affect how the API client handles HTTP errors.

If the client encounters one of HTTP response codes listed in retryOn, it will wait for retryDelayMs milliseconds and attempt the same API request again. The client will throw an exception only if the request failed as many times as specified in the retries option.

If this parameter is not provided, the client will never retry failed requests and will fail immediately.

logger object
An optional object for accepting log messages. Any console-compatible logger object can be provided: console, pino, winston, etc.

If the object is not provided, Staking SDK will not log any messages.

What's next?