Megacoin-Node-Api is an Express middleware plugin that easily exposes a URL structure for interfacing with a megacoind Megacoin wallet.
NB: The middleware is experimental at present. Certain JSON-RPC methods are not supported yet and/or experimental. These are methods with more complex parameters that do not fit easily into a query string:
These methods will be added in the future. If there any other problems with the other methods, please report the bugs.
npm install megacoin-node-api
How to use
var megacoinapi = ;var express = ;var app = ;//Username and password relate to those set in the megacoin.conf filevar wallet =host: 'localhost'port: 7950user: 'username'pass: 'password';megacoinapi;megacoinapi; //Access controlapp; //Bind the middleware to any chosen urlapp;
Just add the method name after the binded url.
This returns data exactly as would be expected from the JSON-RPC api.
"version": 80300"protocolversion": 70001"walletversion": 60000"balance": 43222"blocks": 245645"timeoffset": -2"connections": 8"proxy": """difficulty": 21335329113983"testnet": false"keypoololdest": 1368414896"keypoolsize": 101"paytxfee": 00001"unlocked_until": 0"errors": ""
Parameters are sent via a query string:
"amount": 0002"confirmations": 1321"blockhash": "000000000000009d0a2bb76c81dd185d1f6c28256037baef7b3345b7a7e958c7""blockindex": 150"blocktime": 1372728756"txid": "d6c7e35ff9c9623208c22ee37a118ad523ae6c2d137d10053739cb03dbac62e0""time": 1372728436"timereceived": 1372728436"details":"account": "localtest""address": "1Htev475XRVYfenku7ZWXGPSun15ESynCq""category": "receive""amount": 0002
Consult the API call list for parameter information.
If you have encrypted your wallet.dat you need to set the passphrase before attaching the middleware.
The .setAccess method controls the access to the urls. By default all commands are accessible. The method takes two parameters: type (string) and accesslist (array). To restrict access there are two ways to do this:
The 'only' type only exposes the methods given by an array of methods as the accesslist parameter.
//Only allow the getinfo methodmegacoinapi;
The 'restrict' type prevents methods from being accessed.
Megacoin-Node-Api has predefined access profiles to make it easy to set up.
It prevents 'dumpprivkey' and 'walletpassphrasechange' being accessed. This prevents potential theft. Also removes the 'stop' command to prevent someone from stopping the server.
This profile only exposes methods that show information. No methods that can send/alter the wallet are exposed.
Megacoin-Node-Api is used in the following projects:
If you use Megacoin-Node-Api in your projects submit a pull request to the readme with a link.
Copyright (C) 2013 Niel de la Rouviere
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.