npm.io
0.1.4 • Published 4 years ago

public-square-api

Licence
MIT
Version
0.1.4
Deps
4
Size
40 kB
Vulns
23
Weekly
0

@decentdotland/public-square-api

See it on NPM! License

public-square-api

an api for the public-square Protocol

Install

npm install public-square-api

Examples

I) get public-square's feed
method 1: data decoded from the TX's data property
import { getFeed } from "public-square-api"

async function loadTribusFeed() {
    const feed = await getFeed();

    return feed;
}
method 2 (LazyAccess): data decoded from the TX's lazyAcess tag
import { getLazyFeed } from "public-square-api"

async function loadTribusFeed() {
    const feed = await getLazyFeed();

    return feed;
}

returns an array of posts metadata objects:

[
  {
    pid: 'JzK-8crzmr76Uj7SkiP_XhD6Ig-B8N6OsSSSmOIL3g8',
    poster: 'vZY2XY1RD9HIfWi8ift-1_DnHLDadZMWrufSh-_rKF0',
    timestamp: 1637349516,
    data: { text: 'stonks 📈📈', media: [] }
  },
  {
    pid: 'RfE5vkrluExB7Q-JgPFEr6PbbcWcmtq5emF64QkxN5w',
    poster: 'vZY2XY1RD9HIfWi8ift-1_DnHLDadZMWrufSh-_rKF0',
    timestamp: 1637349516,
    data: { text: 'welcome to the PublicSquare! 👋', media: [] }
  },
  ...
]

II) get posts TXIDs per address

code:

// assuming the code is async-await
const address = "...";
const postsTxs = await getPostsOf(address);

output:

The same output of getFeed() but filtered for a single address.

License

This project is licensed under the MIT license

Keywords