BsvWallet ⚡🔑
A simple Bitcoin SV wallet library
- can work offline ✅
- enable peer to peer transactions ✅
- follow the whitepaper ✅
- browser friendly ✅
- autocomplete in js and ts files ✅
- HD Private Keys at 0 technical cost ✅
- ❤️ easy to use ❤️
How to install
npm i bsv-wallet
How to import
Typescript
const { Wallet } from "bsv-wallet"
Javascript
const { Wallet } = require("bsv-wallet");
How to use
Create or Import a wallet
Import with a mnemonic
const myMnemonic = "awkward will execute giant ...";
const wallet = new Wallet({ key: myMnemonic });
Import with a seed string
const seed = "Kwn6yDoKobVjH2dqa9UZ4c5yXfUQQo6PxdQ...";
const walet = new Wallet({ key: seed, keyFormat: "string" });
Create a new Wallet and get the mnemonic
const wallet = new Wallet();
const myNewWalletMnemonic = wallet.getMnemonic();
require("fs").writeFileSync("private.key", myNewWalletMnemonic);
localStorage.setItem("key", myNewWalletMnemonic);
Get your balance
const balanceInSatoshis = wallet.getBalance();
console.log({ balanceInSatoshis });
Sign a tx for your friend
const friendAdr = "";
const txHex = await wallet.signTx({
to: friendAdr,
amount: 5000,
});
Broadcast it to the blockchain
const txHex = "...";
wallet.broadcast(txHex);
Exemple: Bob sending money to Alice
const walletBob = new Wallet(key: "bob private key");
const walletAlice = new Wallet(key: "alice private key");
const adrAlice = await walletAlice.getAddress();
const txForAlice = await walletBob.signTx({
to: adrAlice,
amount: 1234
});
walletBob.broadcast(txForAlice)
walletAlice.broadcast(txForAlice)
Dev note
There i no other documentation at this time but the autocomplete will mostly tell you how to use it
If you wish to contribute or encounter any issue
You can contact me on my discord @Kysan#8315