Steemit API Question

in steemdev •  6 years ago 

question.png

I'm trying to import blocks from the chain immediately as they are posted. I'm tired of waiting a full minute before I can see what's being posted to the platform.

One tutorial said this:

const stream = client.blockchain.getOperationsStream({ mode: BlockchainMode.Latest })

This threw an error for me using javascript.

Another tutorial says this:

const stream = client.blockchain.getOperationsStream({mode: dsteem.BlockchainMode.Latest})

This doesn't throw an error in JavaScript, but it also doesn't work.

Does anyone know?

You'd think the most basic things you could do would be documented.
Guess not.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  ·  6 years ago (edited)

I can get the latest block in python like this:
from steem import Steem
import pprint

stm = Steem()
num = stm.head_block_number
newest_block = stm.get_block(num)

pprint.pprint(newest_block)

Have you tried asking in SteemDev discord? You may be able to get a better answer there.

Gah I'm actually trying this and have the same damn problem.

client.blockchain.getCurrentBlockHeader()

Gives me a block that is a minute old.
Are you sure Python is giving brand new blocks?

Yes, just tested with this while loop and compared with head block numbers on steemd.com.
Seems to be returning the correct block numbers.

lb.png

I miss Python... it's been so long.

So apparently getOperationsStream() is just broken.
getBlockStream() is working for getting the new blocks.

Thanks for your time though and reminding me how awesome Python is.

I was thinking about "cheating" like this.

Best suggestion so far though so... 100% upvote and all that.

The tutorial on Steem Dev portal works https://developers.steem.io/tutorials-javascript/stream_blockchain_transactions ... Well the tutorial sucks but you can look at the repo the code runs as is from codepen. One thin I do however since a while ago is only use dsteem 0.10 and not higher since higher just does weird things not sure if it just me, don't care. There is always steemjs I can use also. Codepen

im using version 10 as well... was thinking about changing it up to see if i get different results.

unfortunately the linked tutorial you gave me doesn't have the word "Latest" in it.

Did you check to make sure you are on same UTC time synced with steemit since your JavaScript browser time is different?
B27E7CE0-3A20-4231-8516-73927AD93AD2.jpeg

https://mktcode.github.io/steemit-widgets/

I'm pretty sure my time isn't synced. Not sure if/why that matters.
The blocks I'm receiving are immutable. I want blocks that are fresh off the line.

Yeah u want them fresh off the line steemit time! What does the error code say?

I created a repo for u to test this out https://github.com/superoo7/steem-stream-example

import { Client } from "dsteem";
const client = new Client("https://api.steemit.com");

const stream = client.blockchain.getBlockStream();

stream.on("data", operation => {
  console.log(operation);
});

It's streaming straight from the blockchain

source: https://developers.steem.io/tutorials-javascript/stream_blockchain_transactions

Nice, but I'm trying to do it in javascript. And I don't want Immutable blocks. I want Latest blocks.

<script src="https://unpkg.com/dsteem@^0.10.0/dist/dsteem.js"></script>

let client = new dsteem.Client('https://api.steemit.com')

var stream = client.blockchain.getOperationsStream()

stream.on('data', (operation) => filter(operation))

The blocks that this script retrieves are 20 blocks late. (immutable)

Actually could you tell me how to run this?
I'm a super noob when it comes to GitHub.

I've only got experience with the python library.

Maybe look at the post promoter code and see how they did it?

Posted using Partiko Android

It's concerning, because this is the most basic thing someone can try to do.

Oh, your blockchain has information on it? How do I access it?

And yet, when you look at the official API documentation and search for the word "stream" there are zero matches... so... bad...

Have you declared what nodes you're connecting to?

Posted using Partiko Android

Only connected to Steemit I think...

  let client = new dsteem.Client('https://api.steemit.com')

I just realised you referenced the condenser api, you might wanna take a look at steem-js instead. I'm 80% sure they're different things.

This is old but may still be relevant

Magic Dice has rewarded your post with a 38% upvote. Thanks for playing Magic Dice.

Classic.
All hail, stinc!

Using steemjs:

steem.api.streamOperations()