Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LtbLightning/bdk-rn
Bitcoin Development Kit - React Native Module
https://github.com/LtbLightning/bdk-rn
Last synced: 4 days ago
JSON representation
Bitcoin Development Kit - React Native Module
- Host: GitHub
- URL: https://github.com/LtbLightning/bdk-rn
- Owner: LtbLightning
- License: mit
- Created: 2022-03-26T14:46:55.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-27T04:23:25.000Z (8 months ago)
- Last Synced: 2024-11-02T04:52:36.626Z (8 days ago)
- Language: Swift
- Size: 1.33 MB
- Stars: 50
- Watchers: 5
- Forks: 15
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-bdk - bdk-rn on GitHub
README
## bdk-rn
A React Native version of the Bitcoin Development Kit (https://bitcoindevkit.org/)
`bdk` aims to be the core building block for Bitcoin Applications of any kind.## Installation
Using npm:
```bash
npm i --save bdk-rn
```Using yarn:
```bash
yarn add bdk-rn
```[IOS Only] Install pods:
```bash
npx pod-install
or
cd ios && pod install
```### Examples
### Create a Wallet & sync the balance of a descriptor
```ts
import { DescriptorSecretKey, Mnemonic, Blockchain, Wallet, DatabaseConfig, Descriptor } from 'bdk-rn';
import { WordCount, Network } from 'bdk-rn/lib/lib/enums';// ....
const mnemonic = await new Mnemonic().create(WordCount.WORDS12);
const descriptorSecretKey = await new DescriptorSecretKey().create(Network.Testnet, mnemonic);
const externalDescriptor = await new Descriptor().newBip84(descriptorSecretKey, KeychainKind.External, Network.Testnet);
const internalDescriptor = await new Descriptor().newBip84(descriptorSecretKey, KeychainKind.Internal, Network.Testnet);const config: BlockchainElectrumConfig = {
url: 'ssl://electrum.blockstream.info:60002',
sock5: null,
retry: 5,
timeout: 5,
stopGap: 100,
validateDomain: false,
};const blockchain = await new Blockchain().create(config);
const dbConfig = await new DatabaseConfig().memory();const wallet = await new Wallet().create(externalDescriptor, internalDescriptor, Network.Testnet, dbConfig);
await wallet.sync(blockchain);
```### Create a `public` wallet descriptor
```ts
import { DescriptorSecretKey, Mnemonic, Descriptor } from 'bdk-rn';
import { WordCount, Network, KeychainKind } from 'bdk-rn/lib/lib/enums';// ....
const mnemonic = await new Mnemonic().create(WordCount.WORDS12);
const descriptorSecretKey = await new DescriptorSecretKey().create(Network.Testnet, mnemonic);
const descriptorPublicKey = await descriptorSecretKey.asPublic();
const fingerprint = 'd1d04177';
const externalPublicDescriptor = await new Descriptor().newBip84Public(
descriptorPublicKey,
fingerprint,
KeychainKind.External,
Network.Testnet
);
```### Store wallet data persistently
```ts
import RNFS from 'react-native-fs'
import { DatabaseConfig, ... } from 'bdk-rn';// create sqlite database config with rn document directory path
const dbConfig = await new DatabaseConfig().sqlite(`${RNFS.DocumentDirectoryPath}/bdk-wallet`)```
### References:
- Setting up a local Esplora instance for testing:
https://bitcoin.stackexchange.com/questions/116937/how-do-i-setup-an-esplora-instance-for-local-testing/116938#116938
---_Note: Caution this is an Alpha at this stage
Please consider reviewing, experimenting and contributing ⚡️_Thanks for taking a look!