Polygon Staking API
1 Increase Allowance
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
Request
curl -X 'POST'
'<https://stakingapi.infstones.com/polygon/stake>'
-H 'x-api-key: \<api_token>'
-H 'Content-Type: application/json'
-d '{
"wallet": "0xca5804bfb7e04282122dabc3a20157e2002e539dbab9a8ca6cb1b0f22a5254a2",
"amount": "10"
}'
Response
{
"data": "0168fc5a-8dc3-48b3-b879-304a6368058c"
}
3 Unstake
Request
curl -X 'POST'
'<https://stakingapi.infstones.com/polygon/unstake>'
-H 'x-api-key: \<api_token>'
-H 'Content-Type: application/json'
-d '{
"wallet": "0xca5804bfb7e04282122dabc3a20157e2002e539dbab9a8ca6cb1b0f22a5254a2",
"amount": "10"
}'
Response
{
"data": "0168fc5a-8dc3-48b3-b879-304a6368058c"
}
4 Withdrawal
Request
curl -X 'POST'
'<https://stakingapi.infstones.com/polygon/withdrawal>'
-H 'x-api-key: \<api_token>'
-H 'Content-Type: application/json'
-d '{
"wallet": "0xca5804bfb7e04282122dabc3a20157e2002e539dbab9a8ca6cb1b0f22a5254a2",
"amount": "10",
"data": {
"nonce": "1"
}
}'
Response
{
"data": "0168fc5a-8dc3-48b3-b879-304a6368058c"
}
5 Claim
Request
curl -X 'POST'
'<https://stakingapi.infstones.com/polygon/claim>'
-H 'x-api-key: \<api_token>'
-H 'Content-Type: application/json'
-d '{
"wallet": "0xca5804bfb7e04282122dabc3a20157e2002e539dbab9a8ca6cb1b0f22a5254a2"
}'
Response
{
"data": "0168fc5a-8dc3-48b3-b879-304a6368058c"
}
5 Sign Polygon Transaction
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: "0x35B1CA0F398905Cf752e6FE122b51c88022FCa32", // This is InfStones Polygon Staking Smart Contract Address
value: "<value>", // Retrieved from activity
data: "<data>", // Retrieved from activity
}
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 about 17 hours ago