Polygon Staking API
Before staking MATIC with InfStones Safe Stake SDK, users must initially complete the Increase Allowance
step. This is a one-time requirement, ensuring seamless future transactions within the staking process.
1 Increase Allowance
Users can authorize the MATIC token smart contract to access the maximum permissible amount of their tokens.
import Web3 from "web3"
const web3 = new Web3("<ethereum_endpoint>") // Replace this with your Ethereum Fast API endpoint
const wallet = {
privateKey:
"<your_ethereum_wallet_private_key>",
address: "<your_ethereum_wallet_address>",
}
try {
console.log(`Attempting to send transaction from ${wallet.address} to ${addressTo}`)
//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();
let rawTx = {
nonce: nonce,
to: "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0", //Matic Token Smart Contract Address
value: "0x0",
data: "0x095ea7b30000000000000000000000005e3ef299fddf15eaa0432e6e66473ace8c13d908ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // Increase to the maximum allowance
}
rawTx = { ...rawTx, gas: "300000", gasPrice: gasPrice.toString()}
const createTransaction = await web3.eth.accounts.signTransaction(
rawTx,
wallet.privateKey
)
//Send tx and wait for receipt
const createReceipt = await web3.eth.sendSignedTransaction(
createTransaction.rawTransaction
)
console.log(
`Transaction successful with hash: ${createReceipt.transactionHash}`
)
} catch (error) {
console.log(error)
}
2 Stake
Staking MATIC through the InfStones Safe Stake SDK involves a straightforward process: Giving permission to the highest possible level for the MATIC token smart contract to use a specified amount of your tokens, users stake MATIC 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.
2.1 Stake
Through stake
API, users can stake a specified amount of MATIC and get the activity ID.
Request
curl -X 'POST'
'<https://stakingapi.infstones.com/polygon/stake>'
-H 'x-api-key: \<access_token>'
-H 'Content-Type: application/json'
-d '{
"wallet": "<your_ethereum_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": "5f6ae9a7-0c28-49d2-81e0-64d6a1a384d0"
}
2.2 Get Raw Transaction
Open GraphQL Playground, users can retrieve the raw transaction associated with the activity ID from 2.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:"5f6ae9a7-0c28-49d2-81e0-64d6a1a384d0") {
activity {
wallet
amount
raw_tx
activity_status
}
}
}
Response
{
"data": {
"get_activity": {
"activity": [
{
"wallet": "0xb31ef182b807e5276b91250208422f8d75316e70",
"amount": "42342342",
"raw_tx": "{\"from_address\":\"0xb31ef182b807e5276b91250208422f8d75316e70\",\"to_address\":\"0x35B1CA0F398905Cf752e6FE122b51c88022FCa32\",\"value\":\"0x0\",\"data\":\"0x6ab15071000000000000000000000000000000000000000000230656f58fd955734000000000000000000000000000000000000000000000000000000000000000000977\",\"gas_limit\":\"\"}",
"activity_status": "completed"
}
]
}
}
}
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 stake process.
import Web3 from "web3"
const web3 = new Web3("<ethereum_endpoint>") // Replace this with your Ethereum Fast API endpoint
const wallet = {
privateKey: "<your_ethereum_wallet_private_key>",
address: "<your_ethereum_wallet_address>",
}
try {
//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()
let rawTx = {
nonce: nonce,
to: "0x35B1CA0F398905Cf752e6FE122b51c88022FCa32", // This is InfStones Polygon Staking Smart Contract Address
value: "<value>", // Retrieved from activity
data: "<data>", // Retrieved from activity
}
//Increase gas accordingly
rawTx = {
...rawTx,
gas: "300000",
gasPrice: gasPrice.toString(),
}
const createTransaction = await web3.eth.accounts.signTransaction(
rawTx,
wallet.privateKey
)
//Send tx and wait for receipt
const createReceipt = await web3.eth.sendSignedTransaction(
createTransaction.rawTransaction
)
console.log(
`Transaction successful with hash: ${createReceipt.transactionHash}`
)
} catch (error) {
console.log(error)
}
3 Unstake
Unstaking MATIC through the InfStones Safe Stake SDK involves a straightforward process: users unstake MATIC 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.
3.1 Unstake
Through unstake
API, users can unstake a specified amount of MATIC and get the activity ID.
Request
curl -X 'POST'
'<https://stakingapi.infstones.com/polygon/unstake>'
-H 'x-api-key: \<access_token>'
-H 'Content-Type: application/json'
-d '{
"wallet": "<your_ethereum_wallet_address>",
"amount": "<unstake_amount>"
}'
Response
{
"data": "53961ecf-9e65-4d9a-bfd5-12143ea645e6"
}
3.2 Get Raw Transaction
Open GraphQL Playground, users can retrieve the raw transaction associated with the activity ID from 3.1 Unstake
.
Request
{
get_activity(id:"53961ecf-9e65-4d9a-bfd5-12143ea645e6") {
activity {
wallet
amount
raw_tx
activity_status
}
}
}
Response
{
"data": {
"get_activity": {
"activity": [
{
"wallet": "0xb31ef182b807e5276b91250208422f8d75316e70",
"amount": "0.5",
"raw_tx": "{\"from_address\":\"0xb31ef182b807e5276b91250208422f8d75316e70\",\"to_address\":\"0x35B1CA0F398905Cf752e6FE122b51c88022FCa32\",\"value\":\"0x0\",\"data\":\"0xc83ec04d00000000000000000000000000000000000000000000000006f05b59d3b2000000000000000000000000000000000000000000000000000006f05b59d3b20000\",\"gas_limit\":\"\"}",
"activity_status": "completed"
}
]
}
}
}
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.
import Web3 from "web3"
const web3 = new Web3("<ethereum_endpoint>") // Replace this with your Ethereum Fast API endpoint
const wallet = {
privateKey: "<your_ethereum_wallet_private_key>",
address: "<your_ethereum_wallet_address>",
}
try {
//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()
let rawTx = {
nonce: nonce,
to: "0x35B1CA0F398905Cf752e6FE122b51c88022FCa32", // This is InfStones Polygon Staking Smart Contract Address
value: "<value>", // Retrieved from activity
data: "<data>", // Retrieved from activity
}
//Increase gas accordingly
rawTx = {
...rawTx,
gas: "300000",
gasPrice: gasPrice.toString(),
}
const createTransaction = await web3.eth.accounts.signTransaction(
rawTx,
wallet.privateKey
)
//Send tx and wait for receipt
const createReceipt = await web3.eth.sendSignedTransaction(
createTransaction.rawTransaction
)
console.log(
`Transaction successful with hash: ${createReceipt.transactionHash}`
)
} catch (error) {
console.log(error)
}
Once unstaking is complete, you need to wait for 80 checkpoints and then manually withdraw to your wallet. Every checkpoint takes approximately 30 minutes.
4 Withdrawal
Withdrawing MATIC through the InfStones Safe Stake SDK involves a straightforward process: users withdraw MATIC 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 withdrawal process seamlessly.
4.1 Withdrawal
Through withdrawal
API, users can withdraw a specified amount of MATIC and get the activity ID.
Request
curl -X 'POST'
'<https://stakingapi.infstones.com/polygon/withdrawal>'
-H 'x-api-key: \<access_token>'
-H 'Content-Type: application/json'
-d '{
"wallet": "<your_ethereum_wallet_address>",
"amount": "<withdrawal_amount>",
"data": {
"tx_hash": "<unstake_tx_hash>"
}
}'
{
"data": "d7ab1a5c-9b84-4fa2-9a5c-0102d3f04842"
}
4.2 Get Raw Transaction
Open GraphQL Playground, users can retrieve the raw transaction associated with the activity ID from 4.1 Withdrawal
.
Request
{
get_activity(id:"d7ab1a5c-9b84-4fa2-9a5c-0102d3f04842") {
activity {
wallet
amount
raw_tx
activity_status
}
}
}
Response
{
"data": {
"get_activity": {
"activity": [
{
"wallet": "0xb31ef182b807e5276b91250208422f8d75316e70",
"amount": "0.5",
"raw_tx": "{\"from_address\":\"0xb31ef182b807e5276b91250208422f8d75316e70\",\"to_address\":\"0x35B1CA0F398905Cf752e6FE122b51c88022FCa32\",\"value\":\"0x0\",\"data\":\"0xe97fddc20000000000000000000000000000000000000000000000000000000000000005\",\"gas_limit\":\"\"}",
"activity_status": "completed"
}
]
}
}
}
The activity status
completed
means the transaction details are fully prepared and ready for the next stepSign Transaction and Broadcast
.
4.3 Sign Transaction and Broadcast
Users can sign the raw transaction using their own wallet's private key and broadcast it to complete the withdrawal process.
import Web3 from "web3"
const web3 = new Web3("<ethereum_endpoint>") // Replace this with your Ethereum Fast API endpoint
const wallet = {
privateKey: "<your_ethereum_wallet_private_key>",
address: "<your_ethereum_wallet_address>",
}
try {
//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()
let rawTx = {
nonce: nonce,
to: "0x35B1CA0F398905Cf752e6FE122b51c88022FCa32", // This is InfStones Polygon Staking Smart Contract Address
value: "<value>", // Retrieved from activity
data: "<data>", // Retrieved from activity
}
//Increase gas accordingly
rawTx = {
...rawTx,
gas: "300000",
gasPrice: gasPrice.toString(),
}
const createTransaction = await web3.eth.accounts.signTransaction(
rawTx,
wallet.privateKey
)
//Send tx and wait for receipt
const createReceipt = await web3.eth.sendSignedTransaction(
createTransaction.rawTransaction
)
console.log(
`Transaction successful with hash: ${createReceipt.transactionHash}`
)
} catch (error) {
console.log(error)
}
5 Claim Reward
Claiming reward through the InfStones Safe Stake SDK involves a straightforward process: users claim reward 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 reward process seamlessly.
5.1 Claim Reward
Through claim
API, users can claim reward using their <access_token>
and get the activity ID.
Request
curl -X 'POST'
'<https://stakingapi.infstones.com/polygon/claim>'
-H 'x-api-key: \<access_token>'
-H 'Content-Type: application/json'
-d '{
"wallet": "your_ethereum_wallet_address"
}'
Response
{
"data": "65ae91a7-b559-43bc-b6b1-891e57d39dcc"
}
5.2 Get Raw Transaction
Open GraphQL Playground, users can retrieve the raw transaction associated with the activity ID from 5.1 Unstake
.
Request
{
get_activity(id:"65ae91a7-b559-43bc-b6b1-891e57d39dcc") {
activity {
wallet
amount
raw_tx
activity_status
}
}
}
Response
{
"data": {
"get_activity": {
"activity": [
{
"wallet": "0xb31ef182b807e5276b91250208422f8d75316e70",
"amount": "0",
"raw_tx": "{\"from_address\":\"0xb31ef182b807e5276b91250208422f8d75316e70\",\"to_address\":\"0x35B1CA0F398905Cf752e6FE122b51c88022FCa32\",\"value\":\"0x0\",\"data\":\"0xc7b8981c\",\"gas_limit\":\"\"}",
"activity_status": "completed"
}
]
}
}
}
The activity status
completed
means the transaction details are fully prepared and ready for the next stepSign Transaction and Broadcast
.
5.3 Sign Transaction and Broadcast
Users can sign the raw transaction using their own wallet's private key and broadcast it to complete the claim reward process.
import Web3 from "web3"
const web3 = new Web3("<ethereum_endpoint>") // Replace this with your Ethereum Fast API endpoint
const wallet = {
privateKey: "<your_ethereum_wallet_private_key>",
address: "<your_ethereum_wallet_address>",
}
try {
//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()
let rawTx = {
nonce: nonce,
to: "0x35B1CA0F398905Cf752e6FE122b51c88022FCa32", // This is InfStones Polygon Staking Smart Contract Address
value: "<value>", // Retrieved from activity
data: "<data>", // Retrieved from activity
}
//Increase gas accordingly
rawTx = {
...rawTx,
gas: "300000",
gasPrice: gasPrice.toString(),
}
const createTransaction = await web3.eth.accounts.signTransaction(
rawTx,
wallet.privateKey
)
//Send tx and wait for receipt
const createReceipt = await web3.eth.sendSignedTransaction(
createTransaction.rawTransaction
)
console.log(
`Transaction successful with hash: ${createReceipt.transactionHash}`
)
} catch (error) {
console.log(error)
}
Updated 9 months ago