0.0.1-alpha.6 • Published 5 years ago

simple-wallet v0.0.1-alpha.6

Weekly downloads
1
License
UNLICENSED
Repository
-
Last release
5 years ago

Simple Wallet for Bitcoin Cash

For a web developers building applications for Bitcoin Cash, Simple Wallet provides an easy and quick way to create BCH wallets and sen bitcoin around. Simple wallets gives developers high-level interfaces that hides most of the complexity required for such functionality. The mission is to make the interaction with Bitcoin Cash Blockchain it as simple as possible.

How to use it?

Import

Add to your HTML scripts

<script src="https://honest.cash/js/simplewallet.min.js" />

Node module

npm install simple-wallet --save
// module import
import SimpleWallet from "simple-wallet";

// nodejs modules
const SimpleWallet = require("simple-wallet");

Create new wallets

const simpleWallet = new SimpleWallet();

// 12 words seed phrase for the wallet
console.log(simpleWallet.mnemonic);

// cash address derived from the seed (derivation path: m/44'/145'/0/0/1')
console.log(simpleWallet.cashAddress);

// legacy address derived from the seed (derivation path: m/44'/145'/0/0/1')
console.log(simpleWallet.legacyAddress);

// private key for the BCH address derived from the seed (derivation path: m/44'/145'/0/0/1')
console.log(simpleWallet.privateKey);

Initialize wallet with mnemonic

// initialize with 12 words seed phrase for the wallet
const simpleWallet = new SimpleWallet("<mnemonic>");

Send transactions

You can send funds to other BCH wallets. You are able distribute funds to N users.

const simpleWallet = new SimpleWallet("<mnemonic>");

const tx = await simpleWallet.send([
    {
        address: "bitcoincash:qp2rmj8heytjrksxm2xrjs0hncnvl08xwgkweawu9h",
        // amount in satoshis, 1 satoshi = 0.00000001 Bitcoin
        amountSat: 1000
    }
]);

// Transaction ID
// you can then see the transaction in one of the explorers
// example: `https://explorer.bitcoin.com/bch/tx/${tx.txid}`;
console.log(tx.txid);

Error Handling

try {
    tx = await simpleWallet.send([
        { address: address, amountSat: 10 }
    ]);
} catch (err) {
    console.error(err);

    if (err.message && err.message.indexOf("Insufficient") > -1) {
        return alert("Insufficient balance on your BCH account.");
    }

    alert("Error. Try again later.");
}

Save keys in the browser

const simpleWallet1 = new SimpleWallet();

localStorage.setItem("BCH_MNEMONIC", simpleWallet.mnemonic);

const simpleWallet2 = new SimpleWallet(localStorage.getItem("BCH_MNEMONIC"));

Under the hood

  • Simple wallet is a wallet programmed for honest.cash. It combines functionality of multiple libraries and recombines them in a way that it is simple for developers to begin working with Bitcoin Cash blockchain.

  • Simple wallet is powered by Bitbox SDK and communicates with rest.bitcoin.com Cloud API.

Author

Adrian Barwicki

Licence

Unlicenced.

Copyright 2018 Adrian Barwicki (adrianbarwicki@gmail.com)

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.

PS. This library is still in alpha. We will open-source it once it becomes mature.