The Voting Power API from SDS
Previously, I have been using the SDS API to get the voting power:
However I found out that within 6 minutes, the voting power difference is 2% which doesn't seem correct. As far as I understand, in 24 hours, the VP is restored 20% so, 6 minutes is 0.08%
And steemchiller told me I should use the following instead - which returns a real time voting power. The one above doesn't get update until a vote is made.
https://sds0.steemworld.org/accounts_api/getAccountExt/justyy/null/upvote_mana_percent
https://sds0.steemworld.org/accounts_api/getAccountExt/justyy
Therefore, I have updated my functions (with simple retry logics).
PHP
function getVP($id, $retries = 3, $delaySeconds = 1) {
$url = "https://sds0.steemworld.org/accounts_api/getAccountExt/$id/null/upvote_mana_percent";
for ($i = 0; $i < $retries; $i++) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlError = curl_error($ch);
curl_close($ch);
if ($response === false || $httpCode !== 200) {
error_log("Attempt " . ($i + 1) . ": HTTP Error $httpCode - $curlError");
sleep($delaySeconds);
continue;
}
$data = json_decode($response, true);
if (isset($data['result']['upvote_mana_percent'])) {
return floatval($data['result']['upvote_mana_percent']);
} else {
error_log("Attempt " . ($i + 1) . ": Malformed JSON or missing field");
sleep($delaySeconds);
}
}
return -1; // All retries failed
}
NodeJs
async function getVP(id, retries = 3, delayMs = 1000) {
const url = `https://sds0.steemworld.org/accounts_api/getAccountExt/${id}/null/upvote_mana_percent`;
for (let i = 0; i < retries; i++) {
try {
const response = await fetch(url);
if (!response.ok) {
console.error(`Attempt ${i + 1}: Response status was ${response.status}`);
await new Promise(resolve => setTimeout(resolve, delayMs));
continue;
}
const data = await response.json();
const current = parseFloat(data.result.upvote_mana_percent);
return current;
} catch (error) {
console.error(`Attempt ${i + 1}: Fetch error`, error);
await new Promise(resolve => setTimeout(resolve, delayMs));
}
}
return -1;
}
Steem to the Moon🚀!
- You can rent Steem Power via rentsp!
- You can swap the TRON:TRX/USDT/USDD to STEEM via tron2steem!
- You can swap the STEEM/SBD to SOL Solana via steem2sol!
- You can swap the STEEM/SBD to ETH Ethereum via steem2eth!
- You can swap the STEEM/SBD to Tether USDT (TRC-20) via steem2usdt!
- You can swap the STEEM/SBD to TRX (TRON) via steem2trx!
- You can swap the STEEM/SBD to BTS (BitShares) via steem2bts!
- Register a free STEEM account at SteemYY!
- Steem Block Explorer
- ChatGPT/Steem Integration: You can type !ask command to invoke ChatGPT
- Steem Witness Table and API
- Other Steem Tools