ExpressJS middleware to add functionality for proxying requests to Electrum servers
Web applications can't communicate with electrum servers. This package provide ability to make requests to them.
Node >= 7.x
npm install @agilie/electrum-proxy-middleware
const electrum = require('@agilie/electrum-proxy-middleware');
app.use(electrum.router);
app.listen(3000)
curl -X GET http://localhost:3000/server/version?coinType=btc
> {"status":"success","result":["ElectrumX 1.13.0","1.4"]}
or
curl -X GET 'http://localhost:3000/server/version?port=55002&host=tn.not.fyi&connectionType=ssl&version=1.4'
> {"status":"success","result":["ElectrumX 1.13.0","1.4"]}
npm test
All calls are required to have a coinType param or at least host, port, connectionType and version params.
Param | Value |
---|---|
coinType (required) | supported coin types |
netMode | mainnet(by default) or testnet |
or
Param | Value |
---|---|
host (required) | e.g. tn.not.fyi |
port (required) | e.g. 55002 |
connectionType (required) | ssl or tcp |
version (required) | e.g 1.4 |
netMode | mainnet (by default) or testnet |
Example: /server/version?coinType=btc
Additional params:
Param | Type | Description |
---|---|---|
version | Float | server version |
height | non-negative integer | the height of the block |
Example: /block/header?coinType=btc&height=5
Additional params: start_height - the height of the first header requested, count - the number of headers requested.
Example: /block/headers?&coinType=btc&start_height=5&count=1
Additional params:
Param | Description |
---|---|
blocks | the number of blocks to target for confirmation |
Example: /blockchain/estimatefee?coinType=btc&blocks=1
Example: /blockchain/relayfee?coinType=btc
Example: /mempool/get_fee_histogram?coinType=btc
Param | Type | Description |
---|---|---|
scripthash | hexadecimal string | script hash |
Example: /scripthash/balance?scripthash=20b360e68b4fe6d1eb460e45434f756fa1582ed687167898f9a716435ecd737f&coinType=btc
Additional params:
Param | Type | Description |
---|---|---|
raw_tx | hexadecimal string | raw transaction |
Additional params:
Param | Type | Description |
---|---|---|
tx_hash | hexadecimal string | transaction hash |
verbose | boolean | whether a verbose coin-specific response is required |
Example: /transaction/get?tx_hash=871af2528c83ba90bd7b3fbfeac703cbd20f204f1b800ba4ec748842fcac0c9b&coinType=btc
Additional params:
Param | Type | Description |
---|---|---|
tx_hash | hexadecimal string | raw transaction |
height | integer | the height at which it was confirmed |
Additional params:
Param | Type | Description |
---|---|---|
height | non-negative integer | the main chain block height |
tx_pos | integer | a zero-based index of the transaction in the given block |
merkle | boolean | whether a merkle proof should also be returned |
Getting history docs.
For more details, refer to the ElectrumX Protocol Methods docs.
Here are some basic examples.
-
URL
</server/version?coinType=btc>
-
Method:
GET
-
URL Params
Required:
coinType=[CoinType]
Optional:
netMode=[Netmode]
-
Success Response:
- Code: 200
- Content:
{ "status":"success","result":["ElectrumX 1.13.0","1.4"] }
- Code: 200
-
Error Response:
- Code: 409
- Content:
{ "error": [{ "target": { "netMode": "mainnet", "coinType": "etc" }, "value": "etc", "property": "coinType", "children": [], "constraints": { "isEnum": "coinType must be a valid enum value" } }] }
- Code: 409
Or you can specify electrum server:
-
URL
</server/version?port=55002&host=tn.not.fyi&connectionType=ssl&version=1.4>
-
Method:
GET
-
URL Params
Required:
port=[integer]
host=[string]
connectionType=[ssl | tcp]
version=[server version]
Optional:
netMode=[testnet | mainnet]
-
URL
</history/get_history?address=1BWwXJH3q6PRsizBkSGm2Uw4Sz1urZ5sCj&coinType=btc&page=1&pageSize=2>
-
Method:
GET
-
URL Params
Required:
coinType=[CoinType]
address=[string]
Optional:
netMode=[Netmode]
page=[number]
pageSize=[number]
-
Success Response:
- Code: 200
- Content:
{ "status": "success", "result": [{ "value": "0.0002", "timestamp": 1399325126000, "fee": "0.0001", "status": "completed" }, { "value": "0.00011", "timestamp": 1399325126000, "fee": "0.0001", "status": "completed" }], "time": 336.57917699999996 }
- Code: 200
-
Error Response:
- Code: 409
- Content:
{ "error": [{ "target": { "netMode": "test", "address": "8b01df4e368ea28f8dc0423bcf77a4923e3a12d307c875e47a0cfbf90b5c39161", "coinType": "btc", "page": "1", "pageSize": "2" }, "value": "test", "property": "netMode", "children": [], "constraints": { "isEnum": "netMode must be a valid enum value" } }] }
- Code: 409
The MIT License (MIT). Full license text is available in LICENSE.