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',
  network: 'mainnet-beta',
  retry: {
    retryOn: [429, 500, 502, 503],
    retryDelayMs: 500,
    retries: 3,
    retryOnTimeout: true,
  },
});

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

await client.solana.stake({
  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.

network string, required
Network to use in all API calls by default, e.g., mainnet or testnet. See the specific methods' documentation for allowed values.

timeoutMs number
If specified, any request that takes longer than this amount of milliseconds will fail.

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 at least retryDelayMs milliseconds and attempt the same API request again. If the request fails repeatedly, the delay grows exponentially, according to formula: retryDelayMs + 2^(attempt-1) + random jitter. The client will throw an exception only if the request failed as many times as specified in the retries option.

If retryOnTimeout is set to true, the same retry behavior will be used for requests that failed according to timeoutMs. Enable with caution for non-idempotent operations like sendTransaction().

If these parameters are 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?