Solana
How to stake tokens in Solana network using P2P.ORG Staking SDK.
- Initialize the API client object via the
StakingApiClientconstructor.
const client = new StakingApiClient({
baseUrl: 'https://api.p2p.org',
token: 'eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9',
});- Retrieve the staking accounts from your P2P.ORG profile with
getStakingAccounts().
var result = await client.solana.getStakingAccounts({
'network': 'mainnet-beta',
'status': 'active',
});
const account = result.accounts[0];- Create a new stake transaction with
stake(). The result will contain a base64-encoded unsigned transaction which you can convert to a SolanaTransactionobject.
var result = await client.solana.stake({
network: 'mainnet-beta',
feePayer: account.stakeAccount,
fromPublicKey: account.stakeAccount,
stakeAuthority: account.stakeAuthority,
withdrawAuthority: account.withdrawAuthority,
amount: 1002282880,
});
var transaction = client.solana.decodeTransaction(result.unsignedTransaction);- Sign the transaction using the dedicated wallet software. P2P.ORG Staking SDK provides a simple method
signWithKeypairs(), though it is intended for testing and development only. In production, replace it with the software or hardware wallet integration or a dedicated signing service integration.
const key = process.env.SOLANA_PRIVATE_KEY;
client.solana.signWithKeypairs(transaction, [key]);- Verify the signed transaction with
verifyTransaction(). This ensures that the transaction was not modified by external software before signing.
client.solana.verifyTransaction({
tx: transaction,
expectedFeePayer: account.stakeAuthority,
expectedStakeAuthority: account.stakeAuthority,
expectedWithdrawAuthority: account.withdrawAuthority,
strict: true,
});- Broadcast the transaction to the Solana network with
sendTransaction().
await client.solana.sendTransaction({
signedTransaction: transaction,
network: 'mainnet-beta',
});What's next?
- StakingApiClient
- getStakingAccounts()
- Staking API reference
Updated about 19 hours ago