🚀 PeakeCoin Tipping Bot: Building Without Smart Contracts

PEK Tips

When I first started building out PeakeCoin, I ran into a wall a lot of us in the Hive/Engine ecosystem face: I don’t have the liquid assets to buy more BEE and spin up “smart” contracts.

Instead of giving up, I worked this out for tipping. If people can’t swap on-chain yet, at least we can reward each other directly with PeakeCoin (PEK) through comments. This post explains how the tipping bot works, why I designed it the way I did, and what each part of the code is actually doing.


💡 The Concept

The tipping bot listens to the Hive blockchain for a special hashtag — #peaketip.
Whenever a whitelisted user leaves a comment like:

  thanks for your post!

…the bot springs into action:

  1. Checks if the tipper owns at least a minimum balance of PEK (so they have skin in the game).

  2. Makes sure the bot account has enough Resource Credits (RC) to reply and confirm.

  3. Sends a fixed amount of PEK to the mentioned user.

  4. Replies under the comment confirming the tip.

No smart contracts. No need to pre-buy more BEE. Just simple Python logic layered over the Hive + Hive Engine APIs.


🐍 The Code (Annotated)

Here’s the full script, with keys redacted and every section explained:

from nectar import Hive, Comment, Blockchain, Account
from nectarengine.wallet import Wallet
import time, re

ACCOUNT = "peakecoin"
ACTIVE_KEY  = "ACTIVE_PRIVATE_KEY_REDACTED"
POSTING_KEY = "POSTING_PRIVATE_KEY_REDACTED"
TOKEN = "PEK"
TIP_AMOUNT = 0.00000001
MIN_BALANCE_REQUIRED = 5.0
WHITELIST_USERS = ["paulmoon410", "peakecoin", "strangedad"]

# Regex to find " "
TIP_PATTERN = re.compile(r"\s+@(\w+)", re.IGNORECASE)

# Initialize Hive + Engine connections
hive = Hive(keys=[ACTIVE_KEY, POSTING_KEY])
account = Account(ACCOUNT, blockchain_instance=hive)
blockchain = Blockchain(mode="head")
wallet = Wallet(ACCOUNT, blockchain_instance=hive)

def has_enough_rc():
    rc = account.get_rc()
    percent = rc["rc_manabar"]["current_mana"] / rc["max_rc"] * 100
    return percent > 10

def check_user_balance(username):
    user_wallet = Wallet(username, blockchain_instance=hive)
    balances = user_wallet.get_balances()
    for item in balances:
        if item.get("symbol") == TOKEN:
            return float(item["balance"]) >= MIN_BALANCE_REQUIRED
    return False

def send_tip(from_user, to_user, memo):
    return wallet.transfer(to_user, TIP_AMOUNT, TOKEN, memo)

def process_comment(op):
    if op["author"] in WHITELIST_USERS:
        match = TIP_PATTERN.search(op.get("body",""))
        if match and check_user_balance(op["author"]) and has_enough_rc():
            to_user = match.group(1)
            send_tip(op["author"], to_user, "You've been tipped with PeakeCoin!")
            Comment(f"@{op['author']}/{op['permlink']}").reply(
                f"✅ @{op['author']} tipped {TIP_AMOUNT} PEK to @{to_user}!", author=ACCOUNT
            )

for op in blockchain.stream(["comment"]):
    process_comment(op)

🔍 What Each Part Does

  • Regex Parsing → Finds #peaketip @username inside a comment.

  • Whitelist Users → Keeps spam down and focuses tipping to trusted users.

  • Balance Check → Only allows tipping if the user owns PEK already.

  • RC Check → Prevents the bot from running dry on Hive resources.

  • Transfer → Actually moves PEK using Hive Engine wallet functions.

  • Reply → Posts a confirmation message under the original comment.


⚙️ Why This Matters

This isn’t a polished “smart contract” on BEE. It’s a grassroots workaround.
It proves you don’t need massive liquid assets or complex contracts to build useful tools. With some Python, patience, and persistence, you can still create real functionality on Hive and Hive Engine.


📌 Next Steps

  1. Persistence — Right now, tip history resets if the bot restarts. Adding a small DB would fix that.

  2. Custom Amounts — The parser already recognizes amounts, I just hardcoded it for safety.

  3. Open Whitelist — Could expand beyond hardcoded accounts with a file or on-chain registry.

  4. Retries & Logging — Improve robustness by retrying failed transfers and logging all actions.


👷 It may not be the fanciest setup, but it works. This is the kind of Maryland grit that keeps PeakeCoin moving forward. One step at a time, without waiting on expensive contracts, just building what we need.



0
0
0.000
3 comments