0.9.89 • Published 6 years ago

wenodejs v0.9.89

Weekly downloads
5
License
BSD-3-Clause
Repository
github
Last release
6 years ago

wenodejs Build Status Coverage Status Package Version

Robust WeYouMe blockchain client library that runs in both node.js and the browser.


note As of version 0.7.0 WebSocket support has been removed. The only transport provided now is HTTP(2). For most users the only change required is to swap wss:// to https:// in the address. If you run your own full node make sure to set the proper CORS headers if you plan to access it from a browser.


Browser compatibility

Build Status

Installation

Via npm

For node.js or the browser with browserify or webpack.

npm install wenodejs

From cdn or self-hosted script

Grab dist/wenodejs from a release and include in your html:

<script src="wenodejs"></script>

Or from the unpkg cdn:

<script src="https://unpkg.com/wenodejs@^0.8.0/dist/wenodejs"></script>

Make sure to set the version you want when including from the cdn, you can also use wenodejs@latest but that is not always desirable. See unpkg.com for more information.

Usage

In the browser

<script src="https://unpkg.com/wenodejs@latest/dist/wenodejs"></script>
<script>
    var client = new wenodejs.Client('https://api.WeYouMe.io')
    client.database.getDiscussions('trending', {tag: 'writing', limit: 1}).then(function(discussions){
        document.body.innerHTML += '<h1>' + discussions[0].title + '</h1>'
        document.body.innerHTML += '<h2>by ' + discussions[0].author + '</h2>'
        document.body.innerHTML += '<pre style="white-space: pre-wrap">' + discussions[0].body + '</pre>'
    })
</script>

See the demo source for an example on how to setup a livereloading TypeScript pipeline with wintersmith and browserify.

In node.js

With TypeScript:

import {Client} from 'wenodejs'

const client = new Client('https://api.WeYouMe.io')

for await (const block of client.blockchain.getBlocks()) {
    console.log(`New block, id: ${ block.block_id }`)
}

With JavaScript:

var wenodejs = require('wenodejs')

var client = new wenodejs.Client('https://api.WeYouMe.io')
var key = wenodejs.PrivateKey.fromLogin('username', 'password', 'posting')

client.broadcast.vote({
    voter: 'username',
    author: 'almost-digital',
    permlink: 'wenodejs-is-the-best',
    weight: 10000
}, key).then(function(result){
   console.log('Included in block: ' + result.block_num)
}, function(error) {
   console.error(error)
})

With ES2016 (node.js 7+):

const {Client} = require('wenodejs')

const client = new Client('https://api.WeYouMe.io')

async function main() {
    const props = await client.database.getChainProperties()
    console.log(`Maximum blocksize consensus: ${ props.maximum_block_size } bytes`)
    client.disconnect()
}

main().catch(console.error)

With node.js streams:

var wenodejs = require('wenodejs')
var es = require('event-stream') // npm install event-stream
var util = require('util')

var client = new wenodejs.Client('https://api.WeYouMe.io')

var stream = client.blockchain.getBlockStream()

stream.pipe(es.map(function(block, callback) {
    callback(null, util.inspect(block, {colors: true, depth: null}) + '\n')
})).pipe(process.stdout)

Bundling

The easiest way to bundle wenodejs (with browserify, webpack etc.) is to just npm install wenodejs and require('wenodejs') which will give you well-tested (see browser compatibility matrix above) pre-bundled code guaranteed to JustWork™. However, that is not always desirable since it will not allow your bundler to de-duplicate any shared dependencies wenodejs and your app might have.

To allow for deduplication you can require('wenodejs/lib/index-browser'), or if you plan to provide your own polyfills: require('wenodejs/lib/index'). See src/index-browser.ts for a list of polyfills expected.


Share and Enjoy!

0.9.89

6 years ago

0.9.87

6 years ago

0.9.86

6 years ago

0.9.85

6 years ago

0.9.84

6 years ago

0.9.83

6 years ago

0.9.82

6 years ago

0.9.81

6 years ago

0.9.80

6 years ago

0.9.79

6 years ago

0.9.78

6 years ago

0.9.77

6 years ago

0.9.76

6 years ago

0.9.73

6 years ago

0.9.72

6 years ago

0.9.71

6 years ago

0.9.69

6 years ago

0.9.68

6 years ago

0.9.66

6 years ago

0.9.75

6 years ago

0.9.74

6 years ago

0.9.70

6 years ago

0.9.67

6 years ago

0.9.63

6 years ago

0.9.62

6 years ago

0.9.60

6 years ago

0.9.59

6 years ago

0.9.58

6 years ago

0.9.57

6 years ago

0.9.56

6 years ago

0.9.55

6 years ago

0.9.53

6 years ago

0.9.52

6 years ago

0.9.51

6 years ago

0.9.50

6 years ago

0.9.49

6 years ago

0.9.48

6 years ago

0.9.47

6 years ago

0.9.46

6 years ago

0.9.45

6 years ago

0.9.44

6 years ago

0.9.42

6 years ago

0.9.41

6 years ago

0.9.40

6 years ago

0.9.39

6 years ago

0.9.38

6 years ago

0.9.37

6 years ago

0.9.36

6 years ago

0.9.33

6 years ago

0.9.32

6 years ago

0.9.31

6 years ago

0.9.30

6 years ago

0.9.29

6 years ago

0.9.28

6 years ago

0.9.27

6 years ago

0.9.26

6 years ago

0.9.25

6 years ago

0.9.24

6 years ago

0.9.23

6 years ago

0.9.21

6 years ago

0.9.20

6 years ago

0.9.19

6 years ago

0.9.18

6 years ago

0.9.17

6 years ago

0.9.14

6 years ago

0.9.13

6 years ago

0.9.12

6 years ago

0.9.11

6 years ago

0.9.10

6 years ago

0.9.9

6 years ago

0.9.7

6 years ago

0.9.6

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

1.0.11

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.9.111

6 years ago