JSPM

  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q68689F
  • License MIT

BIP44 Javascript Wallet

Package Exports

  • oip-hdmw

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (oip-hdmw) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Coverage Status

OIP HD-MultiWallet

oip-hdmw is a BIP44 Javascript Lite Wallet. You can spawn and recover the entire wallet for each coin using just a single BIP-39 Mnemonic. We use an insight-api server as the source of truth for Wallet balances and unspent outputs instead of syncing Block Headers like most SPV wallets do.

Table of Contents

Installation Instructions

You can install the latest version by running the following npm install command.

$ npm install --save oip-hdmw

Getting Started

Creating your first Wallet

Creating a wallet is extremely simple! To create a new wallet with a random new Mnemonic, all we need to do is create a Wallet with no paramaters. After the wallet is created, we log the Mnemonic so that we can use it in our other examples

const HDMW = require('oip-hdmw')
const Wallet = HDMW.Wallet;

var myWallet = new Wallet();

console.log("My Mnemonic: '" + myWallet.getMnemonic() + "'")
// My Mnemonic: 'carbon panda replace drum guess heart inside useless random bulb hint industry'

Getting the Coins from your Wallet

Now that you have a Mnemonic for your wallet, lets go ahead and create the Wallet again, but this time, we will give it the Mnemonic to start from.

const HDMW = require('oip-hdmw')
const Wallet = HDMW.Wallet;

var myWallet = new Wallet('carbon panda replace drum guess heart inside useless random bulb hint industry');

console.log("My Wallets Coins: ", myWallet.getCoins())
// My Wallets Coins: {
//	bitcoin: Coin,
//	litecoin: Coin,
//	flo: Coin
//}

As you can see, we get back a JSON object containing each Coin along with an identifier that is the Coin name.

Getting your first Address

Now that we have created a new Wallet and accessed the Coins on the wallet, lets go ahead and get the Main Address for one of the coins. To do this, we will first need to get a Coin from the Wallet. To do this, we use the getCoin function and pass it the Coin name that we wish to get the Coin for. After we have grabbed the Coin, we run the getMainAddress function in order to get the main address for the Coin. After we have stored the Address returned to us by the Coin, we need to get the human readable Public key of the Address.

const HDMW = require('oip-hdmw')
const Wallet = HDMW.Wallet;

var myWallet = new Wallet('carbon panda replace drum guess heart inside useless random bulb hint industry');

var bitcoin = myWallet.getCoin('bitcoin');

var myMainAddress = bitcoin.getMainAddress();

console.log("My Wallets Bitcoin Main Address: ", myMainAddress.getPublicAddress());
// My Wallets Bitcoin Main Address: 13BW4eTvNFXBLeTjJQRgVxuiuStAFp1HfL

Sending your first Transaction

In order to send a transaction, we will need to have a balance on our Wallet first. Send some funds to the Address that you got in the last step. After you have sent some money to the Wallet, we can send our first transaction. To send the Transaction, use the sendPayment method.

const HDMW = require('oip-hdmw')
const Wallet = HDMW.Wallet;

var myWallet = new Wallet('carbon panda replace drum guess heart inside useless random bulb hint industry');

myWallet.sendPayment({
    to: { "12nP3k9tFKgQPJNkDDyNWqgjtm2bt3qq1b": 0.001 }
}).then(function(txid){
    console.log("Successfully sent Transaction! " + txid);
}).catch(function(error){
    console.error("Unable to send Transaction!", error)
})

Understanding the Wallet Topology

API Documentation

Learn more about how each Class works, or take a look at all functions available to you.

License

MIT License

Copyright (c) 2018 Open Index Protocol Working Group

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.