1.1.11 • Published 3 years ago

jsstc v1.1.11

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

jsstc

Install

Require style

Install with npm install --save jsstc inside your project. Then just

const jsstc = require('jsstc')

CDN style

If you are working in the browser and want to load jsstc from a CDN:

<script src="https://unpkg.com/jsstc/bin/jsstc.min.js"></script>

By default, jsstc hits on the main stc testnet (https://api.staketoclaim.com). You can eventually make jsstc hit on your local node or any stc node like so:

jsstc.init({api: 'http://localhost:3001'})

GET API

GET single account

jsstc.getAccount('alice', (err, account) => {
    console.log(err, account)
})

GET many accounts

Just pass an array of usernames instead

jsstc.getAccounts(['alice', 'bob'], (err, accounts) => {
    console.log(err, accounts)
})

GET list of filtered accounts

Return an array of accounts strictly matching the value of a json object key.

jsstc.getFilterAccounts ('type', 'shop', 0, 100,  (err, accounts) => {
    console.log(err, accounts)
})

GET list of searched accounts

Return an array of accounts by searching the value in a matching json key.

jsstc.getSearchAccounts('city', 'flo', 0, 100,  (err, accounts) => {
    //list of accounts with the city key value containing 'flo' (like florida, florence, florianopolis)
    console.log(err, accounts)
})

GET account transaction history

For the history, you also need to specify a block number. The api will return all blocks lower than the specified block where the user was involved in a transaction

jsstc.getAccountHistory('alice', 0, (err, blocks) => {
    console.log(err, blocks)
})

GET single content

jsstc.getContent('alice', 'pocNl2YhZdM', (err, content) => {
    console.log(err, content)
})

GET followers

jsstc.getFollowers('alice', (err, followers) => {
    console.log(err, followers)
})

GET following

jsstc.getFollowers('alice', (err, followers) => {
    console.log(err, followers)
})

GET contents by author

You can pass a username and permlink (identifying a content) in the 2nd and 3rd argument to 'get more'.

jsstc.getDiscussionsByAuthor('alice', null, null, (err, contents) => {
    console.log(err, contents)
})

GET contents by creation time

You can pass a username and a permlink to 'get more'.

jsstc.getNewDiscussions('alice', null, null, (err, contents) => {
    console.log(err, contents)
})

GET contents by popularity (hot)

You can pass a username and a permlink to 'get more'.

jsstc.getHotDiscussions(null, null, (err, contents) => {
    console.log(err, contents)
})

GET contents by feed

This lists the contents posted by the following of the passed username.

You can pass a username and a permlink in the 2nd and 3rd argument to 'get more'.

jsstc.getFeedDiscussions('alice', null, null, (err, contents) => {
    console.log(err, contents)
})

GET notifications

jsstc.getNotifications('alice', (err, contents) => {
    console.log(err, contents)
})

POST API

To send a transaction to the network, you will need multiple steps. First you need to define your transaction and sign it.

var newTx = {
    type: jsstc.TransactionType.FOLLOW,
    data: {
        target: 'bob'
    }
}

newTx = jsstc.sign(alice_key, 'alice', newTx)

After this step, the transaction is forged with a timestamp, hash, and signature. This transaction needs to be sent in the next 60 secs or will be forever invalid.

You can send it like so

jsstc.sendTransaction(newTx, function(err, res) {
    cb(err, res)
})

The callback will return once your transaction has been included in a new block.

Alternatively, you can just want the callback as soon as the receiving node has it, you can do:

jsstc.sendRawTransaction(newTx, function(err, res) {
    cb(err, res)
})

Convenience

Generate a keypair

console.log(jsstc.keypair())

Growing variables

Voting Power and Bandwidth are growing in time but the API will only return the latest update in the vt and bw fields of the accounts. To get the actual value, use votingPower() and bandwidth()

jsstc.getAccount('alice', (err, account) => {
    console.log(jsstc.votingPower(account))
    console.log(jsstc.bandwidth(account)) 
})
1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.99

4 years ago

1.0.98

4 years ago

1.0.96

4 years ago

1.0.95

4 years ago

1.0.94

4 years ago

1.0.93

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.91

4 years ago

1.0.92

4 years ago

1.0.6

4 years ago

1.0.2

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago