If you're interested, here's a short code snippet. You'll need to connect to your internal server, open a web page, and leave a keychain open with the checkbox selected so it no longer requires validation. By default, the keychain must remain open.
With this code, you'll only need to change the name and the target tag, and enter your percentage.
The bot will search for predefined tags or tags for multi-tagging; just one setting needs to be changed, which we'll explain below.
currently being improved
<?php
// =============================================
// ✅ CONFIGURATION (Stable Version)
// =============================================
define('TARGET_TAG', 'alive');
define('VOTER_ACCOUNT', 'benef.alive');
define('VOTE_WEIGHT', 2000); // 20%
define('DEBUG_MODE', true);
define('REFRESH_INTERVAL', 5000); // 5 seconds
define('MAX_POSTS', 20);
// =============================================
// 🔄 IMPROVED FUNCTIONS WITH ERROR HANDLING
// =============================================
function hive_api_call($method, $params = []) {
$payload = json_encode([
"jsonrpc" => "2.0",
"method" => $method,
"params" => $params,
"id" => 1
]);
$ch = curl_init("https://api.hive.blog");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200 || empty($response)) {
return ['error' => 'Hive API unreachable'];
}
$data = json_decode($response, true);
return $data['result'] ?? ($data['error'] ?? ['error' => 'Invalid API response']);
}
// Fetches posts with error handling
function get_recent_posts($limit = 20) {
$result = hive_api_call("condenser_api.get_discussions_by_created", [[
"tag" => "",
"limit" => $limit
]]);
// If error or not an array, return an empty array
return (is_array($result) && isset($result[0])) ? $result : [];
}
// Safely checks for the "alive" tag
function has_target_tag($post) {
if (empty($post['json_metadata'])) return false;
try {
$meta = json_decode($post['json_metadata'], true, 512, JSON_THROW_ON_ERROR);
if (empty($meta['tags'])) return false;
$tags = array_map('strtolower', $meta['tags']);
return in_array(strtolower(TARGET_TAG), $tags);
} catch (Exception $e) {
return false;
}
}
// Retrieves Voting Power
function get_voting_power($account) {
$account_data = hive_api_call("condenser_api.get_accounts", [[$account]]);
if (empty($account_data) || !isset($account_data[0])) {
return 0; // Return 0 if API error
}
$acc = $account_data[0];
$last_vote_time = $acc['last_vote_time'] ?? null;
// If never voted (rare case), VP = 100%
if (empty($last_vote_time)) {
return 100;
}
$last_vote = strtotime($last_vote_time);
$now = time();
$elapsed_seconds = max(0, $now - $last_vote); // Time elapsed since last vote
// Official Hive formula to regenerate VP
$regenerated_vp = ($acc['voting_power'] ?? 0) + ($elapsed_seconds * 10000 / 432000);
$vp = min(100, $regenerated_vp / 100); // VP cannot exceed 100%
return round($vp, 2); // Rounded to 2 decimals
}
// =============================================
// 🤖 MAIN LOGIC WITH ERROR HANDLING
// =============================================
$posts = get_recent_posts(MAX_POSTS);
$eligible_posts = [];
$already_voted = [];
$debug_logs = [];
$current_vp = get_voting_power(VOTER_ACCOUNT);
$api_error = null;
// Secure post processing
foreach ($posts as $post) {
if (empty($post['author']) || empty($post['permlink'])) continue;
$status = ['icon' => '❓', 'text' => 'Unknown', 'color' => 'gray'];
// 1. Tag check
if (!has_target_tag($post)) {
$status = ['icon' => '❌', 'text' => 'No alive tag', 'color' => 'red'];
}
// 2. Check if already voted
elseif (!empty($post['active_votes'])) {
foreach ($post['active_votes'] as $vote) {
if (($vote['voter'] ?? '') === VOTER_ACCOUNT) {
$status = ['icon' => '🔄', 'text' => 'Already voted', 'color' => 'orange'];
$already_voted[] = [
'author' => $post['author'],
'permlink' => $post['permlink'],
'time' => date('H:i:s', strtotime($post['created'] ?? 'now'))
];
break;
}
}
}
// 3. If eligible
if ($status['color'] === 'gray' || $status['color'] === 'green') {
$status = ['icon' => '✅', 'text' => 'Eligible', 'color' => 'green'];
$eligible_posts[] = $post;
}
$debug_logs[] = [
'author' => $post['author'] ?? 'unknown',
'permlink' => $post['permlink'] ?? '',
'title' => $post['title'] ?? '[No title]',
'status' => $status
];
}
?>
#alive
Account: @ | Vote: %
<div class="stat-card">
<h3>Eligible posts</h3>
<div class="stat-value" style="color: var(--neon-green);"><?php echo count($eligible_posts); ?></div>
</div>
<div class="stat-card">
<h3>Checked</h3>
<div class="stat-value" style="color: var(--neon-orange);"><?php echo count($already_voted); ?></div>
</div>
</div>
</div>
</header>
<!-- ELIGIBLE POSTS -->
<div class="section">
<div class="section-header">
<h2 class="section-title">
<i class="fas fa-check-circle" style="color: var(--neon-green);"></i>
<span>Eligible posts (<?php echo count($eligible_posts); ?>)</span>
</h2>
<div class="auto-refresh">
<i class="fas fa-sync-alt"></i>
<span>Auto-refresh <?php echo REFRESH_INTERVAL / 1000; ?>s</span>
</div>
</div>
<?php if (empty($eligible_posts)): ?>
<div class="empty-state">
<i class="fas fa-times-circle"></i>
<div>No posts with the <strong>#alive</strong> tag found.</div>
</div>
<?php else: ?>
<table class="data-table">
<thead>
<tr>
<th>Account</th>
<th>Title</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($eligible_posts as $post): ?>
<tr>
<td>
<a href="https://peakd.com/@<?php echo htmlspecialchars($post['author']); ?>" target="_blank">
@<?php echo htmlspecialchars($post['author']); ?>
</a>
</td>
<td>
<a href="https://peakd.com/@<?php echo htmlspecialchars($post['author']); ?>/<?php echo htmlspecialchars($post['permlink']); ?>" target="_blank">
<?php echo !empty($post['title']) ? htmlspecialchars($post['title']) : '[No title]'; ?>
</a>
</td>
<td>
<span class="status-badge status-eligible">✅ Eligible</span>
</td>
<td>
<button class="vote-btn"
data-author="<?php echo htmlspecialchars($post['author']); ?>"
data-permlink="<?php echo htmlspecialchars($post['permlink']); ?>">
Vote <?php echo VOTE_WEIGHT / 100; ?>%
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<!-- ALREADY VOTED POSTS -->
<div class="section">
<div class="section-header">
<h2 class="section-title">
<i class="fas fa-history" style="color: var(--neon-orange);"></i>
<span>Already voted (<?php echo count($already_voted); ?>)</span>
</h2>
</div>
<?php if (empty($already_voted)): ?>
<div class="empty-state">
<i class="fas fa-hourglass-end"></i>
<div>No voted posts yet</div>
</div>
<?php else: ?>
<table class="data-table">
<thead>
<tr>
<th>Account</th>
<th>Post</th>
<th>Time</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($already_voted as $post): ?>
<tr>
<td>
<a href="https://peakd.com/@<?php echo htmlspecialchars($post['author']); ?>" target="_blank">
@<?php echo htmlspecialchars($post['author']); ?>
</a>
</td>
<td>
<a href="https://peakd.com/@<?php echo htmlspecialchars($post['author']); ?>/<?php echo htmlspecialchars($post['permlink']); ?>" target="_blank">
Post
</a>
</td>
<td><?php echo $post['time']; ?></td>
<td>
<span class="status-badge status-voted">🔄 Voted</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<!-- DEBUG LOGS -->
| Account | Title | Status |
|---|---|---|
| @ |
How it works.
As mentioned above:
You connect to your internal server.
You open the program page in a new tab.
You open your keychain (unfortunately, you must keep it open with the "Don't ask again" option checked).
The page refreshes every 5 seconds if it doesn't find any posts with the #alive tag.
If it finds the #alive tag, it votes on the posts, then refreshes.
This process repeats.
At the very top of the code, you put your name (without the @ symbol). Then you put the tag you are targeting.

To make it a multi-tag
all at the top you change the
define('TARGET_TAG', 'alive');
replace with :
define('TARGET_TAGS', [
'tag1',
'tag2'
'tag3'
'tag4'
]);
AND lines 49 to 60

to :
function has_target_tag($post) {
if (empty($post['json_metadata'])) {
return false;
}
try {
$meta = json_decode($post['json_metadata'], true, 512, JSON_THROW_ON_ERROR);
if (empty($meta['tags']) || !is_array($meta['tags'])) {
return false;
}
$postTags = array_map('strtolower', $meta['tags']);
$targetTags = array_map('strtolower', TARGET_TAGS);
// ✅ AU MOINS un tag commun
return !empty(array_intersect($postTags, $targetTags));
} catch (Exception $e) {
return false;
}
}
PS : At the top of the code, you can also modify the vote weight; here I've set it to 20% as a test.
1% = 100
10% = 1000
50 % = 5000
100 % = 10000

Final


Thanks for sharing your code with the community.
NOT if you see a vote failure, the program may have a lag at startup (too many votes at startup), do not worry, it restarts after each error until the vote is validated.
Congratulations @benef.alive! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)
Your next target is to reach 20 posts.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOPCheck out our last posts: