Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

steem

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

steem - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

post.js

115

lib/steem.js

@@ -1,3 +0,116 @@

var Steem = 'test';
var ws = require('ws');
var Steem = function(url){
this.url = url || 'wss://this.piston.rocks';
};
Steem.prototype.send = function(data, callback) {
var w = new ws(this.url);
w.onmessage = function(msg) {
var data = JSON.parse(msg.data);
var err = data.error || '';
callback(data.result, err);
};
w.onopen = function() {
w.send(JSON.stringify(data));
}
};
Steem.prototype.getAccounts = function(usernames, callback) {
this.send({
'id': 1,
'method': 'get_accounts',
'params': [usernames]
}, function(result, err) {
callback(result, err);
});
};
Steem.prototype.getAccount = function(username, callback) {
this.send({
'id': 1,
'method': 'get_accounts',
'params': [[username]]
}, function(result, err) {
callback(result[0], err);
});
};
Steem.prototype.getBlock = function(id, callback) {
this.send({
'id': 1,
'method': 'get_block',
'params': [id]
}, function(result, err) {
callback(result, err);
});
};
Steem.prototype.streamBlockNumber = function(callback) {
var current = '';
var w = new ws(this.url);
w.onmessage = function(msg) {
var data = JSON.parse(msg.data);
var blockId = data.result.head_block_number;
if (blockId != current) {
current = blockId;
callback(current);
}
};
w.onopen = function() {
setInterval(function () {
w.send(JSON.stringify({
'id': 1,
'method': 'get_dynamic_global_properties',
'params': []
}));
}, 100);
}
};
Steem.prototype.streamBlock = function(callback) {
var w = new ws(this.url);
var current = '';
var last = '';
this.streamBlockNumber(function(id) {
current = id;
});
var self = this;
w.onopen = function() {
setInterval(function () {
if (current != last) {
last = current;
self.getBlock(current, function(result) {
callback(result);
});
}
}, 100);
}
};
Steem.prototype.streamTransactions = function(callback) {
this.streamBlock(function(result) {
result.transactions.forEach(function (transaction) {
callback(transaction);
});
})
};
Steem.prototype.streamOperations = function(callback) {
this.streamBlock(function(result) {
result.transactions.forEach(function (transaction) {
transaction.operations.forEach(function (operation) {
callback(operation);
});
});
})
};
module.exports = Steem;

6

package.json
{
"name": "steem",
"version": "0.0.2",
"description": "Steem Blockchain API",
"version": "0.1.0",
"description": "SteemJS the JavaScript API for Steem blockchain",
"main": "index.js",

@@ -26,4 +26,4 @@ "scripts": {

"dependencies": {
"steem-rpc": "^0.5.2"
"ws": "^1.1.1"
}
}

@@ -1,2 +0,88 @@

# Steem
/!\ This package is under development and not working yet.
# SteemJS
## Install
```
$ npm install steem --save
```
## Usage
```js
var steem = require('./lib/steem');
var Steem = new steem();
Steem.getAccount('steemit', function(result, err) {
console.log(result, err);
});
```
## Send
```js
var data = {
'id': 1,
'method': 'get_accounts',
'params': [['steemit']]
};
Steem.send(data, function(result, err) {
console.log(result, err);
});
```
## Get Accounts
```js
Steem.getAccounts(['ned', 'dan'], function(result, err) {
console.log(result, err);
});
```
## Get Account
```js
Steem.getAccount('steemit', function(result, err) {
console.log(result, err);
});
```
## Get Block
```js
Steem.getBlock(3000000, function(result, err) {
console.log(result, err);
});
```
## Streaming Block Number
```js
Steem.streamBlockNumber(function(result) {
console.log(result);
});
```
## Streaming Block
```js
Steem.streamBlock(function(result) {
console.log(result);
});
```
## Streaming Transactions
```js
Steem.streamTransactions(function(result) {
console.log(result);
});
```
## Streaming Operations
```js
Steem.streamOperations(function(result) {
console.log(result);
});
```
## License
MIT

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc