BSC Staking API
1 Stake
Staking BNB through the InfStones Safe Stake SDK involves a straightforward process: users stake BNB and are provided with an activity ID. This activity ID can be utilized to access the raw transaction which users can then sign and broadcast to complete the stake process seamlessly.
1.1 Stake
Through stake
API, users can stake a specified amount of BNB and get the activity ID.
Request
curl -X 'POST' \
'https://stakingapi.infstones.com/bsc/stake' \
-H 'x-api-key: <access_token>' \
-H 'Content-Type: application/json' \
-d '{
"wallet": "<your_bnb_wallet_address>",
"amount": "<stake_amount>",
"delegateVotePower": false
}'
<access_token>
should be asked from InfStones. For more details, please check https://docs.infstones.com/docs/get-started#1-create-access-token.
Response
{
"data": "d21e659b-0a1f-4fe0-bf18-91f45349d3bc"
}
1.2 Get Raw Transaction
Open GraphQL Playground, users can retrieve the raw transaction associated with the activity ID from 1.1 Stake.
Step 1: Input your access token in the Headers
section.
Step 2: Input the activity ID and run the command, you will get the response with raw_tx
.
Request
{
get_activity(
id:"d21e659b-0a1f-4fe0-bf18-91f45349d3bc"
) {
activity {
id
protocol
wallet
raw_tx
amount
activity_status
action
timestamp
},
count
}
}
Response
{
"data": {
"get_activity": {
"activity": [
{
"id": "d21e659b-0a1f-4fe0-bf18-91f45349d3bc",
"protocol": "bsc",
"wallet": "0x5a1f4d3975749719ef98716e0afb26fbc2216cb4",
"raw_tx": "{\"from_address\":\"0x5a1f4d3975749719ef98716e0afb26fbc2216cb4\",\"to_address\":\"0x0000000000000000000000000000000000002002\",\"value\":\"0xde0b6b3a7640000\",\"data\":\"0x982ef0a7000000000000000000000000d34403249B2d82AAdDB14e778422c966265e5Fb50000000000000000000000000000000000000000000000000000000000000000\"}",
"amount": "1",
"activity_status": "completed",
"action": "stake",
"timestamp": "1724700096"
}
],
"count": 1
}
}
}
The activity status
completed
means the transaction details are fully prepared and ready for the next stepSign Transaction and Broadcast
.
1.3 Sign Transaction and Broadcast
Users can sign the raw transaction using their own wallet's private key and broadcast it to complete the staking process.
import Web3 from "web3"
import { Common } from "@ethereumjs/common"
import { LegacyTransaction } from "@ethereumjs/tx"
import { bytesToHex } from "@ethereumjs/util"
// Step 1. Replace this with your BSC Fast API endpoint
const web3 = new Web3("<your_fast_API_endpoint>")
// Step 2. Replace this with your BSC wallet address and private key
const wallet = {
privateKey: "<your_private_key>",
address: "<your_wallet_address>",
}
// Step 3. Replace this with your raw tx from activity
const rawTxFromInfstones = '{\"from_address\":\"0x5a1f4d3975749719ef98716e0afb26fbc2216cb4\",\"to_address\":\"0x0000000000000000000000000000000000002002\",\"value\":\"0xde0b6b3a7640000\",\"data\":\"0x982ef0a7000000000000000000000000d34403249B2d82AAdDB14e778422c966265e5Fb50000000000000000000000000000000000000000000000000000000000000000\"}'
try {
const rawTxParsed = JSON.parse(rawTxFromInfstones)
// Check if from address is the same as wallet address, cases insensitive
if (rawTxParsed.from_address.toLowerCase() !== wallet.address.toLowerCase()) {
throw new Error(`Caution: "from_address" of InfStones activity ${rawTxParsed.from_address} is not the same as wallet address ${wallet.address}`)
}
console.log(`Attempting to send transaction from ${wallet.address} to ${rawTxParsed.to_address}`)
//Sign tx with Private Key
const txCount = await web3.eth.getTransactionCount(wallet.address)
const nonce = await web3.utils.toHex(txCount)
const gasPrice = await web3.eth.getGasPrice('NUMBER_HEX');
var rawTx = {
nonce: nonce,
from: wallet.address,
gasPrice: gasPrice,
to: rawTxParsed.to_address,
value: rawTxParsed.value,
data: rawTxParsed.data,
}
const gas = await web3.eth.estimateGas(rawTx, 'latest', 'NUMBER_HEX')
rawTx = { ...rawTx, gasLimit: gas}
var common = Common.custom(
{
name: 'bsc',
chainId: 56, // mainnet: 56, testnet: 97
networkId: 56, // mainnet: 56, testnet: 97
},
)
var tx = LegacyTransaction.fromTxData(rawTx, { common });
var signedTx = tx.sign(Buffer.from(wallet.privateKey, 'hex'));
var createReceipt = await web3.eth.sendSignedTransaction(bytesToHex(signedTx.serialize() ))
console.log(`Transaction successful with hash: ${createReceipt.transactionHash}`)
} catch (error) {
console.log(error)
}
2 Unstake
Unstaking BNB through the InfStones Safe Stake SDK involves a straightforward process: users unstake BNB and are provided with an activity ID. This activity ID can be utilized to access the raw transaction which users can then sign and broadcast to complete the unstaking process seamlessly.
2.1 Unstake
Through unstake
API, users can unstake a specified amount of BNB and get the activity ID.
Request
curl -X 'POST' \
'https://stakingapi.infstones.com/bsc/unstake' \
-H 'x-api-key: <access_token>' \
-H 'Content-Type: application/json' \
-d '{
"wallet": "<your_bnb_wallet_address>",
"amount": "<unstake_amount>"
}'
Response
{
"data": "95f60301-0b6a-41a5-9b70-1c64db9f9c00"
}
2.2 Get Raw Transaction
Open GraphQL Playground, users can retrieve the raw transaction associated with the activity ID from 2.1 Unstake.
Request
{
get_activity(
id:"95f60301-0b6a-41a5-9b70-1c64db9f9c00"
) {
activity {
id
protocol
wallet
raw_tx
amount
activity_status
action
timestamp
},
count
}
}
Response
{
"data": {
"get_activity": {
"activity": [
{
"id": "95f60301-0b6a-41a5-9b70-1c64db9f9c00",
"protocol": "bsc",
"wallet": "0x44527b0b64f863dc70b05e1c14990671d3ae8535",
"raw_tx": "{\"from_address\":\"0x5a1f4d3975749719ef98716e0afb26fbc2216cb4\",\"to_address\":\"0x0000000000000000000000000000000000002002\",\"value\":\"0x0\",\"data\":\"0x4d99dd16000000000000000000000000d34403249b2d82aaddb14e778422c966265e5fb5000000000000000000000000000000000000000000000000069503eebc25b485\"}",
"amount": "0.475649723963867657",
"activity_status": "completed",
"action": "unstake",
"timestamp": "1724700761"
}
],
"count": 1
}
}
}
The activity status
completed
means the transaction details are fully prepared and ready for the next stepSign Transaction and Broadcast
.
2.3 Sign Transaction and Broadcast
Users can sign the raw transaction using their own wallet's private key and broadcast it to complete the unstaking process.
Refer to 1.3 Sign Transaction and Broadcast
3 Withdrawal
Withdrawing BNB through the InfStones Safe Stake SDK involves a straightforward process: users withdraw BNB and are provided with an activity ID. This activity ID can be utilized to access the raw transaction which users can then sign and broadcast to complete the claim process seamlessly.
3.1 Withdrawal
Through withdrawal
API, users can withdraw a specified amount of BNB and get the activity ID.
Request
curl -X 'POST'
'<https://stakingapi.infstones.com/bsc/withdrawal'>
-H 'x-api-key: <access_token>'
-H 'Content-Type: application/json'
-d '{
"wallet": "<your_bnb_wallet_address>",
"requestNumber": "<claim_request_number>"
}'
Response
{
"data": "8bfe6c60-47c8-479c-b89a-bb6e3a27efdb"
}
3.2 Get Raw Transaction
Open GraphQL Playground, users can retrieve the raw transaction associated with the activity ID from 3.1 Withdrawal.
Request
{
get_activity(
id:"8bfe6c60-47c8-479c-b89a-bb6e3a27efdb"
) {
activity {
id
protocol
wallet
raw_tx
activity_status
action
timestamp
},
count
}
}
Response
{
"data": {
"get_activity": {
"activity": [
{
"id": "8bfe6c60-47c8-479c-b89a-bb6e3a27efdb",
"protocol": "bsc",
"wallet": "0x5a1f4d3975749719ef98716e0afb26fbc2216cb4",
"raw_tx": "{\"from_address\":\"0x5a1f4d3975749719ef98716e0afb26fbc2216cb4\",\"to_address\":\"0x0000000000000000000000000000000000002002\",\"value\":\"0x0\",\"data\":\"0xaad3ec96000000000000000000000000341e228f22d4ec16297dd05a9d6347c74c125f660000000000000000000000000000000000000000000000000000000000000001\"}",
"activity_status": "completed",
"action": "withdrawal",
"timestamp": "1724701293"
}
],
"count": 1
}
}
}
The activity status
completed
means the transaction details are fully prepared and ready for the next stepSign Transaction and Broadcast
.
3.3 Sign Transaction and Broadcast
Users can sign the raw transaction using their own wallet's private key and broadcast it to complete the unstaking process.
Refer to 1.3 Sign Transaction and Broadcast
Updated about 1 month ago