MultiWallet
NodeJS multiple crypto-currencies wallet bindings that exposes the same API for every currency.
Not intented for browsers.
It uses external lightweight clients.
Supported currencies are:
- Bitcoin (Electrum)
- Litecoin (Electrum-LTC)
- Dash (Electrum-Dash)
- Ethereum (ethereum-cli)
To-do:
- Monero
- Decred
- Ripple
Install
Make sure your server has Electrum, Electrum-LTC, Electrum-Dash and ethereum-cli installed. Run each one of them after installing in order to create your wallet/seed. Then install the lib.
npm i multicryptowallet
Usage
Start by requiring the lib.
const MultiWallet =
Now you have to instantiate it. You can have multiple instances. Use "btc", "ltc", "dash" or "eth".
let btcWallet = 'btc'let dashWallet = 'dash'
As second argument, you can set a few optional settings:
let btcWallet = 'btc' bin: '/path/to/electrum' // if not on PATH environment variable args: '' // additional electrum arguments (appended) rpchost: '127.0.0.1' rpcport: 7777 rpcuser: 'admin' rpcpassword: 'strong-password-here' walletpassword: 'stronger-password' testnet: false web3: 'https://mainnet.infura.io' // for Ethereum only
It's recommended to run the three Electrum versions outside your NodeJS application. You do not need to run ethereum-cli outside, as it is used as a library, and not as a command.
If you prefer so, the library can also try to load Electrum versions for you. However we highly advise not to do so, as it may not work in some environments or may not be safe at all.
await btcWallet.init()
It will initialize Electrum, although it is not recommended. To stop Electrum process:
await btcWallet.shutdown()
Note: when using Ethereum, you MUST call init()
. But shutdown is not required.
await ethWallet
Generating address
let walletAddr = await Walletconsole
Getting wallet balance
let confirmedBalance = await Walletlet unconfirmedBalance = await Walletconsoleconsole
Getting another address balance
let walletConfBalance = await Walletlet walletUnconfBalance = await Walletconsoleconsole
Sending coins
let txId = await Wallet
Raw Transactions
Creating ("from_wallet" is required if using Ethereum):
let rawTx = await Wallet
Signing ("from" is required if using Ethereum):
let signedRawTx = await Wallet
Pushing:
let txId = await Wallet
Developing new bindings
In order to add support for new coins, copy the source code at docs/currency-bootstrap.js and implement the functions listed. Copy your file to "lib/currencies", renaming it to your currency's code.
A testing script is available through npm test
. Edit it on the "test" folder.