Simple Bitcoin Wallet

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

Simple Wallet is used for Honest.Cash. It uses Bitbox and rest.bitcoin.com.

The default derivation path for the wallet keypair is m/44'/0'/0'/0/0.

Functionality

Create wallets

Send Transactions (1:n fund distribution possible!)

Upload and Download data from the blockchain (deprecated)

Support for encryption of recovery phrases

How to use it?

Import

Add to your HTML scripts

< script src = " https://honest.cash/js/simple-bitcoin-wallet.min.js " > < / script >

Node module

npm install simple-bitcoin-wallet --save

import SimpleWallet from " simple-bitcoin-wallet " ; const SimpleWallet = require ( " simple-bitcoin-wallet " ) ;

Create new wallets

const simpleWallet = new SimpleWallet ( ) ; console . log ( simpleWallet . mnemonic ) ; console . log ( simpleWallet . cashAddress ) ; console . log ( simpleWallet . legacyAddress ) ; console . log ( simpleWallet . privateKey ) ;

Mnemonic encryption

const simpleWallet = new SimpleWallet ( null , { password : " myStrongPassword " } ) ; console . log ( simpleWallet . mnemonic ) ; console . log ( simpleWallet . mnemonicEncrypted ) ; const simpleWallet2 = new SimpleWallet ( simpleWallet . mnemonicEncrypted , { password : " myStrongPassword " } ) ; console . log ( simpleWallet . mnemonic ) ;

Initialize wallet with mnemonic

const simpleWallet = new SimpleWallet ( " minor bench until split suffer shine series bag avoid cruel orient aunt " ) ; const simpleWallet2 = new SimpleWallet ( " minor bench until split suffer shine series bag avoid cruel orient aunt " , { HdPath : " m/44'/0'/0'/1' " } ) ;

Send transactions

You can send funds to other BCH wallets. You can distribute funds to N users by simply extending the receiver array.

const simpleWallet = new SimpleWallet ( " minor bench until split suffer shine series bag avoid cruel orient aunt " ) ; const receivers = [ { address : " bitcoincash:qp2rmj8heytjrksxm2xrjs0hncnvl08xwgkweawu9h " , amountSat : 100000 } ] ; const tx = await simpleWallet . send ( receivers ) ; console . log ( tx . txid ) ;

Send OP_RETURN transaction

You can include any OP_RETURN data outputs to your receivers array when sending a transaction. The OP_RETURN data is included using an array of strings. The strings are utf8 by default, but can be interpreted as hex by prepending the string with '0x'. This allows you to use applications with an OP_RETURN protocol, such as memo.cash.

const simpleWallet = new SimpleWallet ( " minor bench until split suffer shine series bag avoid cruel orient aunt " ) ; const receivers = [ { address : " bitcoincash:qp2rmj8heytjrksxm2xrjs0hncnvl08xwgkweawu9h " , amountSat : 100000 } , { opReturn : [ " 0x6d02 " , " Hello world! " ] } ] ; const tx = await simpleWallet . send ( receivers ) ; console . log ( tx . txid ) ;

getBalance(bchAddress?: string): Promise

Gets balance (confirmed + unconfirmed) for an BCH address

const myBalance = await simpleWallet . getBalance ( ) ; const balanceOfOtherAddress = await simpleWallet . getBalance ( " bitcoincash:qp2rmj8heytjrksxm2xrjs0hncnvl08xwgkweawu9h " ) ;

Get full address info

const myWalletInfo = await simpleWallet . getWalletInfo ( ) ; const walletInfoOfOtherAddress = await simpleWallet . getWalletInfo ( " bitcoincash:qp2rmj8heytjrksxm2xrjs0hncnvl08xwgkweawu9h " ) ;

Upload and download stuff on Bitcoin Cash

You can save and retrieve data on the Bitcoin Cash blockchain using the BitcoinFiles protocol. This is fullt integrated into simple-bitcoin-wallet.

const simpleWallet = new SimpleWallet ( " minor bench until split suffer shine series bag avoid cruel orient aunt " ) ; const data = { title : " Hello wordl " , body : " Hello world " , author : " honest_cash " } ; const meta = { title : " hello wordl " , extUri : " https://honest.cash " } ; const { fileId } = await simpleWallet . upload ( data , meta ) ; setTimeout ( async ( ) => { const result = await simpleWallet . download ( fileId ) ; console . log ( result ) ; } , 3000 ) ;

Error Handling

try { tx = await simpleWallet . send ( [ { address : " bitcoincash:qrlhkg4d9z3y88j246a6482xzregxaxnfsagmd2kh3 " , amountSat : 1000 } ] ) ; } catch ( err ) { console . error ( err ) ; if ( err . message && err . message . indexOf ( " Insufficient " ) > - 1 ) { return alert ( " Insufficient balance on your BCH account. " ) ; } return alert ( " Error. Try again later. " ) ; }

Save keys in the browser

While developing BCH apps, remember to never send the private keys / mnemonic / seed phrase to your servers.

Your servers can be hacked Depending on your jurisdiction you may not have the allowance to manage the funds of your users

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 implemented for honest.cash. It combines functionality of multiple libraries and recombines them in a way that makes it simple for developers to begin working with Bitcoin Cash blockchain.

Simple Bitcoin Wallet is powered by Bitbox Light (a fork of Bitbox SDK) and communicates with the Cloud API rest.bitcoin.com.

Licence

Copyright 2018-2019

Honest Cash (honest.cash)

Alphateam Hackers GmbH (https://alphateamhackers.com)

Adrian Barwicki (adrian@adrianbarwicki.com)

Rosco Kalis (rosco.kalis@gmail.com)

Josh Ellithorpe (quest@mac.com)

MIT

Disclaimer

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.