Skip to content

Commit 8560dd3

Browse files
authored
Merge pull request #44 from davay42/patch-1
Bech32 examples in the docs
2 parents 61f5fa5 + eb6bc16 commit 8560dd3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,22 @@ import { createBase58check } from '@scure/base';
7373
createBase58check(sha256).encode(data);
7474
```
7575

76+
7677
## Bech32, Bech32m and Bitcoin
7778

79+
```js
80+
const words = bech32.toWords(Buffer.from('hello', 'utf8'));
81+
const addr = bech32.encode('test', words);
82+
console.log(addr); // "test1w508d6qejxtdg4"
83+
84+
const { prefix, words: decoded } = bech32.decode(addr);
85+
console.log(prefix); // "test"
86+
console.log(Buffer.from(bech32.fromWords(decoded)).toString()); // "hello"
87+
88+
console.log(bech32.decodeUnsafe('invalid')); // undefined
89+
90+
```
91+
7892
We provide low-level bech32 operations.
7993
If you need high-level methods for BTC (addresses, and others), use
8094
[scure-btc-signer](https://github.com/paulmillr/scure-btc-signer) instead.

0 commit comments

Comments
 (0)