Sui Staking API
1 Stake
Staking SUI through the InfStones Safe Stake SDK involves a straightforward process: users stake SUI 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 staking process seamlessly.
1.1 Stake
Through stake
API, users can stake a specified amount of SUI and get the activity ID.
Request
curl -X 'POST' \
'https://stakingapi.infstones.com/sui/stake' \
-H 'x-api-key: <access_token>' \
-H 'Content-Type: application/json' \
-d '{
"wallet": "<your_sui_wallet_address>",
"amount": "<stake_amount>"
}'
<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": "221654a6-87c2-48f8-a68f-da4a2359e416"
}
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:"221654a6-87c2-48f8-a68f-da4a2359e416") {
activity {
wallet
amount
raw_tx
activity_status
}
}
}
Response
{
"data": {
"get_activity": {
"activity": [
{
"wallet": "0x6001b02f1f613f42cc815f9b1dc9f9ef65575c13bcc5d38ba4c63c6308ed7a40",
"amount": "1.001",
"raw_tx": "AAADAAhADKo7AAAAAAEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUBAAAAAAAAAAEAIMpYBL+34EKCEi2rw6IBV+IALlOdurmoymyxsPIqUlSiAgIAAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwpzdWlfc3lzdGVtEXJlcXVlc3RfYWRkX3N0YWtlAAMBAQACAAABAgBgAbAvH2E/QsyBX5sdyfnvZVdcE7zF04ukxjxjCO16QAE2SSeRLANCGXGINf9vOP+UKOq2c1s6V6WWyGE7KwRfsaNGogAAAAAAIN71LxVwurQ/2As5h2nzxxeKfFk8Xo5OYuwbfVoiZSZsYAGwLx9hP0LMgV+bHcn572VXXBO8xdOLpMY8YwjtekDoAwAAAAAAAOOajCoBAAAAAA==",
"activity_status": "completed"
}
]
}
}
}
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 { SuiClient, getFullnodeUrl } from "@mysten/sui.js/client";
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
import { TransactionBlock } from "@mysten/sui.js/transactions";
// Generate a new Ed25519 Keypair
const keypair = Ed25519Keypair.deriveKeypair("<your_sui_wallet_private_key>"); // Replace this with your Sui wallet mnemonic
const client = new SuiClient({
url: getFullnodeUrl("mainnet"),
});
console.log(keypair.getPublicKey().toSuiAddress());
const rawTx = '<raw_tx>';
const tx = TransactionBlock.from(rawTx);
const result = await client.signAndExecuteTransactionBlock({
signer: keypair,
transactionBlock: tx,
});
console.log(result);
2 Unstake
2.1 Get Object ID of Staked SUI
Due to the mechanism of Sui, you need to first obtain the object ID of your staked SUI.
Follow the instructions to get your Sui Fast API endpoint.
Request
curl --location '<sui_mainnet_endpoint>' \ Replace this with your Sui Fast API endpoint
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "suix_getStakes",
"params": [
"<your_sui_wallet_address>"
]
}'
Response
{
"jsonrpc": "2.0",
"result": [
{
"validatorAddress": "0xca5804bfb7e04282122dabc3a20157e2002e539dbab9a8ca6cb1b0f22a5254a2",
"stakingPool": "0x81c306f645a17bd60bc618e213aa1630f3943ebec52cd90d56cd50374cf34f9f",
"stakes": [
{
"stakedSuiId": "0x2751e17d631f349f96e2a150906857f7c3116766fdcbdc0a3966faed237fe150",
"stakeRequestEpoch": "128",
"stakeActiveEpoch": "129",
"principal": "1000000000",
"status": "Active",
"estimatedReward": "6356807"
},
{
"stakedSuiId": "0x47bc13daa53a5e0a948fb143c0886445a6617d530130642c1bb6b77663320b89",
"stakeRequestEpoch": "167",
"stakeActiveEpoch": "168",
"principal": "3200000000",
"status": "Active",
"estimatedReward": "7898846"
}
]
}
],
"id": 1
}
2.2 Unstake
Unstaking SUI through the InfStones Safe Stake SDK involves a straightforward process: users unstake SUI 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.
Request
curl -X 'POST' \
'https://stakingapi.infstones.com/sui/unstake' \
-H 'x-api-key: <access_token>' \
-H 'Content-Type: application/json' \
-d '{
"wallet": "<your_sui_wallet_address>",
"amount": "<unstake_amount>",
"data": {
"staked_sui_id": "<your_staked_object_id>"
}
}'
<unstake_amount>
should be total amount in<your_staked_object_id>
.
<your_staked_object_id>
is thestakedSuiId
you obtained in 2.1.
Response
{
"data": "eadaeb2c-3e0b-4446-8f66-bee0601dd27d"
}
2.3 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:"eadaeb2c-3e0b-4446-8f66-bee0601dd27d") {
activity {
wallet
amount
raw_tx
activity_status
}
}
}
Response
{
"data": {
"get_activity": {
"activity": [
{
"wallet": "0x6001b02f1f613f42cc815f9b1dc9f9ef65575c13bcc5d38ba4c63c6308ed7a40",
"amount": "5",
"raw_tx": "AAACAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQEAAAAAAAAAAQEAGGQ19RnuRsMfo6Ew6IdyEkI6dTOuSFc2yot/TT6WIRVp9qEAAAAAACBRXmCyyUdQCFy/2OpMhL3rtU4GEXGdpXmP7W6zw/airQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMKc3VpX3N5c3RlbRZyZXF1ZXN0X3dpdGhkcmF3X3N0YWtlAAIBAAABAQBgAbAvH2E/QsyBX5sdyfnvZVdcE7zF04ukxjxjCO16QAE2SSeRLANCGXGINf9vOP+UKOq2c1s6V6WWyGE7KwRfsaNGogAAAAAAIN71LxVwurQ/2As5h2nzxxeKfFk8Xo5OYuwbfVoiZSZsYAGwLx9hP0LMgV+bHcn572VXXBO8xdOLpMY8YwjtekDoAwAAAAAAAADKmjsAAAAAAA==",
"activity_status": "completed"
}
]
}
}
}
The activity status
completed
means the transaction details are fully prepared and ready for the next stepSign Transaction and Broadcast
.
2.4 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.
import { SuiClient, getFullnodeUrl } from "@mysten/sui.js/client";
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
import { TransactionBlock } from "@mysten/sui.js/transactions";
// Generate a new Ed25519 Keypair
const keypair = Ed25519Keypair.deriveKeypair("<your_sui_wallet_private_key>"); // Replace this with your Sui wallet mnemonic
const client = new SuiClient({
url: getFullnodeUrl("mainnet"),
});
console.log(keypair.getPublicKey().toSuiAddress());
const rawTx = '<raw_tx>';
const tx = TransactionBlock.from(rawTx);
const result = await client.signAndExecuteTransactionBlock({
signer: keypair,
transactionBlock: tx,
});
console.log(result);
Updated 11 months ago