Skip to content

Commit

Permalink
add riaa client sample
Browse files Browse the repository at this point in the history
  • Loading branch information
you21979 committed Oct 30, 2017
1 parent d697c70 commit 71e7dc3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Electrum Protocol Client for Node.js

## what is this

https://electrum.org/

electrum is bitcoin wallet service.
This is a library of Node.js that can communicate with the electrum(x) server.

## install

```
Expand All @@ -14,6 +21,8 @@ npm i electrum-client
* TCP / TLS
* JSON-RPC
* Subscribe Message
* High Performance Message
* no dependency for other library

## usage

Expand All @@ -34,3 +43,4 @@ const main = async () => {
main()
```


38 changes: 38 additions & 0 deletions example/riaa_client_transaction_send.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
const ElectrumClient = require('electrum-client');

const createRiaaClient = (port, host, protocol, options) => {
return (params, promise) => {
const name = params.join(':')
const client = new ElectrumClient(port, host, protocol, options)
console.time(name)
return client.connect().then( () => {
return promise(client)
}).catch( e => {
client.close()
console.timeEnd(name)
throw e
}).then( res => {
client.close()
console.timeEnd(name)
return res
})
}

}

const main = async(hex) => {
const connect = createRiaaClient(50001, 'electrumx.tamami-foundation.org', 'tcp')
await connect(['blockchainTransaction_broadcast', hex], async(client) => {
const ver = await client.server_version('2.7.11', '1.0')
console.log(ver)
const result = await client.blockchainTransaction_broadcast(hex)
console.log(result)
})
}

const getopt = () => {
return process.argv.slice(2)[0]
}

main(getopt())
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "electrum-client",
"version": "0.0.4",
"version": "0.0.5",
"description": "Electrum protocol client for node.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
},
"dependencies": {},
"repository": {
"type": "git",
"url": "git://github.com/you21979/node-electrum-client.git"
Expand All @@ -20,6 +19,9 @@
"electrum",
"bitcoin"
],
"engines": {
"node": ">=6"
},
"author": "Yuki Akiyama",
"license": "MIT"
}

0 comments on commit 71e7dc3

Please sign in to comment.