https://github.com/arjun-r34/btc_utils
This is an SDK to generate a BECH32 BTC wallet (mainnet and testnet) and also perform transactions.
https://github.com/arjun-r34/btc_utils
Last synced: about 1 year ago
JSON representation
This is an SDK to generate a BECH32 BTC wallet (mainnet and testnet) and also perform transactions.
- Host: GitHub
- URL: https://github.com/arjun-r34/btc_utils
- Owner: ARJUN-R34
- Created: 2020-07-10T07:45:45.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T19:57:59.000Z (over 3 years ago)
- Last Synced: 2025-01-30T19:48:12.357Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 938 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bitcoin Transaction
This package can be used to generate Bech32 Bitcoin wallets and also transact on the Bitcoin testnet.
### Methods
1. generateP2PKH()
2. generateBECH32()
3. signAndSendTransaction()
4. generateTestAccounts()
### Installation
Install this package using,
```npm install --save btc-utils```
Import this package using,
```const bitcoin = require('btc-utils');```
### Usage
#### Generate P2PKH Wallet
```const p2pkhWallet = bitcoin.generateP2PKH();```
##### Response
- ```privateKey``` - Private Key of the wallet.
- ```publicKey``` - Public Key of the wallet.
- ```address``` - Address of the wallet.
#### Generate BECH32 Wallet
```const bech32Wallet = bitcoin.generateBECH32();```
##### Response
- ```privateKey``` - Private Key of the wallet.
- ```publicKey``` - Public Key of the wallet.
- ```privateKeyWIF``` - Private key in WIF (Wallet Import Format).
- ```address``` - Address of the wallet.
#### Generate Bitcoin Test Wallet
```const testWallet = bitcoin.generateTestAccounts();```
##### Response
- ```private``` - Private Key of the wallet.
- ```public``` - Public Key of the wallet.
- ```address``` - Address of the wallet.
- ```wif``` - Private key in WIF (Wallet Import Format).
#### Bitcoin Transaction (Testnet)
```const btcTx = bitcoin.signAndSendTransaction({ fromAddress, toAddress, value, privateKeyWIF });```
##### Parameters
- ```fromAddress``` - Address of the wallet to send the transaction from (sender).
- ```toAddress``` - Address of the wallet to send the transaction to (recepient).
- ```value``` - Amount of Bitcoins (in satoshis).
- ```privateKeyWIF``` - Private key of the sender in WIF (Wallet Import Format).
#### Success Response
```response: {transactionHash} - Transaction Hash of that particular transaction.```
#### Error Response
##### Insufficient balance
```error: 'Insufficient funds.'```
##### Incorrect private key
```error: 'Incorrect private Key.'```