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
// module import; // nodejs modulesconst SimpleWallet = ;
Create new wallets
const simpleWallet = ; // 12 words seed phrase for the walletconsole; // cash address derived from the seed (derivation path: m/44'/0'/0'/0/0)console; // legacy address derived from the seed (derivation path: m/44'/0'/0'/0/0)console; // private key for the BCH address derived from the seed (derivation path: m/44'/0'/0'/0/0)console;
Mnemonic encryption
const simpleWallet = null password: "myStrongPassword"; // 12 words seed phrase for the walletconsole; // encrypted mnemonicconsole; const simpleWallet2 = simpleWalletmnemonicEncrypted password: "myStrongPassword"; // decrypted mnemonicconsole;
Initialize wallet with mnemonic
// initialize with 12 words seed phrase for the walletconst simpleWallet = "minor bench until split suffer shine series bag avoid cruel orient aunt"; // initialize for specific HD derivation pathconst simpleWallet2 = "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 = "minor bench until split suffer shine series bag avoid cruel orient aunt"; const receivers = address: "bitcoincash:qp2rmj8heytjrksxm2xrjs0hncnvl08xwgkweawu9h" // amount in satoshis, 1 satoshi = 0.00000001 Bitcoin amountSat: 100000 ; const tx = await simpleWallet; // Transaction ID// you can then see the transaction in one of the explorers// example: `https://explorer.bitcoin.com/bch/tx/${tx.txid}`;console;
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 = "minor bench until split suffer shine series bag avoid cruel orient aunt"; const receivers = address: "bitcoincash:qp2rmj8heytjrksxm2xrjs0hncnvl08xwgkweawu9h" // amount in satoshis, 1 satoshi = 0.00000001 Bitcoin amountSat: 100000 // Post memo containing the text "Hello world!" opReturn: "0x6d02" "Hello world!" ; const tx = await simpleWallet; // Transaction ID// you can then see the transaction in one of the explorers// example: `https://explorer.bitcoin.com/bch/tx/${tx.txid}`;console;
getBalance(bchAddress?: string): Promise
Gets balance (confirmed + unconfirmed) for an BCH address
// will get a balance for simpleWallet.cashAddressconst myBalance = await simpleWallet; // will get a balance for any addressconst balanceOfOtherAddress = await simpleWallet;
Get full address info
// will get a balance for simpleWallet.cashAddressconst myWalletInfo = await simpleWallet; // will get a balance for any addressconst walletInfoOfOtherAddress = await simpleWallet;/**{ balance: 0.00373518 balanceSat: 373518 cashAddress: "bitcoincash:qrlhkg4d9z3y88j246a6482xzregxaxnfsagmd2kh3" legacyAddress: "1QHrpX426kFvoxRNPZh9aW5Qve5emndARr" totalReceived: 0.15087197 totalReceivedSat: 15087197 totalSent: 0.14713679 totalSentSat: 14713679 transactions: [ "txId1", "txId2" ] txApperances: 2 unconfirmedBalance: 0 unconfirmedBalanceSat: 0 unconfirmedTxApperances: 0}*/
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 = "minor bench until split suffer shine series bag avoid cruel orient aunt"; // any data is allowedconst data = title: "Hello wordl" body: "Hello world" author: "honest_cash"; // meta is optionalconst meta = title: "hello wordl" extUri: "https://honest.cash"; const fileId = await simpleWallet; // 3 sec later request the file.;
Error Handling
try tx = await simpleWallet; catch err console; if errmessage && errmessage > -1 return ; return ;
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 = ; // save the mnemonic for laterlocalStorage; // retrieve mnemonic to initialize the walletconst simpleWallet2 = localStorage;
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.