# ddpayv1

> dPay blockchain v1 RPC client library

Latest version **1.1.0** (published 2018-09-10) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install ddpayv1
pnpm add ddpayv1
yarn add ddpayv1
bun add ddpayv1
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-09-10 |
| First published | 2018-09-10 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 1.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Johan Nordberg |
| Maintainers | dpay |
| Keywords | blockchain, client, rpc, dpay, dsite |

## Links

- npm: https://www.npmjs.com/package/ddpayv1
- Repository: https://github.com/dpays/ddpay
- Homepage: https://github.com/dpays/ddpay#readme
- Issues: https://github.com/dpays/ddpay/issues
- npm.io page: https://npm.io/package/ddpayv1

## Dependencies (7)

- [bs58](https://npm.io/package/bs58.md) ^4.0.1
- [verror](https://npm.io/package/verror.md) ^1.10.0
- [core-js](https://npm.io/package/core-js.md) ^2.5.0
- [secp256k1](https://npm.io/package/secp256k1.md) ^3.3.1
- [bytebuffer](https://npm.io/package/bytebuffer.md) ^5.0.1
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.0.0-alpha.9
- [whatwg-fetch](https://npm.io/package/whatwg-fetch.md) ^2.0.3

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2018-09-10
- 1.0.0 — 2018-09-10

## README

# [ddpayv1](https://github.com/dpays/ddpayv1)

Robust [dPay blockchain](https://dpays.io) 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](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) if you plan to access it from a browser.

---

Installation
------------

### Via npm

For node.js or the browser with [browserify](https://github.com/substack/node-browserify) or [webpack](https://github.com/webpack/webpack).

```
npm install ddpayv1
```

### From cdn or self-hosted script

Grab `dist/ddpay.js` from a [release](https://github.com/jnordberg/ddpay/releases) and include in your html:

```html
<script src="ddpay.js"></script>
```

Or from the [unpkg](https://unpkg.com) cdn:

```html
<script src="https://unpkg.com/ddpayv1@^1.0.0/dist/ddpay.js"></script>
```

Make sure to set the version you want when including from the cdn, you can also use `ddpayv1@latest` but that is not always desirable. See [unpkg.com](https://unpkg.com) for more information.


Usage
-----

### In the browser

```html
<script src="https://unpkg.com/ddpayv1@latest/dist/ddpay.js"></script>
<script>
    var client = new ddpay.Client('https://api.dpays.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](https://github.com/dpays/ddpayv1/tree/master/examples/comment-feed) for an example on how to setup a livereloading TypeScript pipeline with [wintersmith](https://github.com/jnordberg/wintersmith) and [browserify](https://github.com/substack/node-browserify).

### In node.js

With TypeScript:

```typescript
import {Client} from 'ddpayv1'

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

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

With JavaScript:

```javascript
var ddpay = require('ddpayv1')

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

client.broadcast.comment({
    voter: 'username',
    author: 'almost-digital',
    permlink: 'ddpay-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+):

```javascript
const {Client} = require('ddpayv1')

const client = new Client('https://api.dpays.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:

```javascript
var ddpay = require('ddpayv1')
var es = require('event-stream') // npm install event-stream
var util = require('util')

var client = new ddpay.Client('https://api.dpays.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 ddpayv1 (with browserify, webpack etc.) is to just `npm install ddpayv1` and `require('ddpayv1')` 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 ddpayv1 and your app might have.

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

---

*Share and Enjoy!*

---
_Source: https://npm.io/package/ddpayv1 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
