Why Your Steem Bots Keep Crashing (And How We Patched It in @substeem/steem-sdk v1.3.0)

in Steem Dev • 4 days ago

image

Anyone who has ever run a bot, a curation trail, or a contest tracker on Steem knows the 3 AM headache.

You write a script to watch incoming transfers. It runs fine for three hours. Then a public RPC node hiccups, your script throws an unhandled promise rejection, and the entire process dies silently. By the time you wake up, thirty transfers arrived, your database is out of sync, and people are asking why their entries didn't register.

When we shipped v1.2.1 of @substeem/steem-sdk two days ago, people tested simple transfers and votes. That stuff is easy.

The trouble started when we threw live, heavy indexers at it.

Within 48 hours of stress-testing, we ran into two nasty bugs that have plagued Steem developers for years. So we cut v1.3.0 today to kill them permanently.

Here's what went wrong and how we fixed it.


The Blind While-Loop Problem

For nearly eight years, the standard way to stream blocks on Steem was embarrassingly crude.

Almost every script ran an infinite while-loop:

  1. Ask the node for the latest block number.
  2. Fetch that block.
  3. Sleep for three seconds.
  4. Repeat forever.

It works until network traffic spikes. The second a node drops one request, the loop breaks. Worse, if a node lags behind consensus during a witness handover, your script fetches duplicate blocks or misses transactions completely.

Over on Hive, MahdiYari fixed this years ago inside hive-tx by building clean, memory-efficient streams. Hive developers took it for granted. Steem developers were still writing homemade retry wrappers with duct tape.

In v1.3.0, we introduced streamBlocks and streamOperations.

Instead of guessing where the chain is, the SDK tracks the Last Irreversible Block (LIB). It batches block requests in chunks, guarantees you never process a micro-fork that gets rolled back, and auto-resumes if your connection drops. If your home wifi cuts out for thirty seconds, the stream doesn't crash. It simply waits, catches up to the current block, and keeps moving without missing a single byte.


The Global State Trap

Here is an annoying bug that caught us during testing:

If you initialized two separate clients in the same Node process, say one client to query your local witness node and another client with a 15-second timeout for public broadcasting, they silently fought each other. Why? Because the old config object was stored at the module level. Configuring client B secretly changed the settings for client A.

That's fine for throwaway scripts. It's a disaster for real applications.

In v1.3.0, every single Client and Transaction instance is completely isolated. You can spin up ten different clients pointing to ten different nodes with different timeouts, and none of them will bleed state into the others.


Type-Safe Filtering for Lazy Developers

Most people tracking the chain don't want every vote, comment, and reblog. A contest runner or an exchange only cares about transfers.

Previously, you had to fetch every operation, write an ugly switch statement, check if op[0] === 'transfer', and manually cast the payload.

In v1.3.0, you just pass the operation name directly into the stream:

import { streamOperations, type TransferOperation } from '@substeem/steem-sdk'

// Stream only transfers with full TypeScript autocomplete
for await (const { block, op } of streamOperations<['transfer', TransferOperation]>('transfer')) {
  console.log(`Block ${block}: @${op.from} sent ${op.amount} to @${op.to}`)
}

TypeScript automatically types op as a TransferOperation. No runtime checks. No boilerplate.


Why Non-Developers Should Care

If you don't write code, this still matters for your daily wallet experience.

When developers have to build on fragile 2016 libraries, they spend all their time fixing broken node connections instead of building good apps.

Batching block requests cuts node bandwidth by more than 60%. That means running Steem infrastructure gets cheaper, contest bots stop missing your transfers, and curation trails don't double-vote your posts by mistake.

To update:

npm install @substeem/steem-sdk@latest

The package is live on NPM and the repo is open on GitHub:

If you're building a bot, a trail, or a tool on Steem, grab the update. If you break it, drop a comment below and tell us what failed.

Sort:  

Thank you for sharing on steem! I'm witness fuli, and I've given you a free upvote. If you'd like to support me, please consider voting at https://steemitwallet.com/~witnesses 🌟