Skip to content

Commit

Permalink
Add difficulty adjustment examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelMedeiros committed Jul 23, 2021
1 parent caf8d95 commit aed4bc5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README-bitcoin.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Interface to access the Bitcoin `mainet`, `testnet`, `signet` APIs.
- [Get Blocks](#get-blocks)
- [Get Blocks Tip Height](#get-blocks-tip-height)
- [Get Blocks Tip Hash](#get-blocks-tip-hash)
- Difficulty
- [Get Difficulty Adjustment](#get-difficulty-adjustment)
- Fees
- [Get Fees Recommended](#get-fees-recommended)
- [Get Fees Mempool Blocks](#get-fees-mempool-blocks)
Expand Down Expand Up @@ -376,6 +378,21 @@ const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHash);
```

### **Get Difficulty Adjustment**

Returns the hash of the last block.

[ [NodeJS Example](examples/nodejs/bitcoin/difficulty.ts) ] [ [HTML Example](examples/html/bitcoin/difficulty.html) ] [ [Top](#features) ]

```js
const {
bitcoin: { difficulty },
} = mempoolJS();

const difficultyAdjustment = await difficulty.getDifficultyAdjustment();
console.log(difficultyAdjustment);
```

### **Get Fees Recommended**

Returns our currently suggested fees for new transactions.
Expand Down
20 changes: 20 additions & 0 deletions examples/html/bitcoin/difficulty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bitcoin: { difficulty },
} = mempoolJS();

const difficultyAdjustment = await difficulty.getDifficultyAdjustment();
console.log(difficultyAdjustment);

};
init();
</script>
</head>
<body></body>
</html>
11 changes: 11 additions & 0 deletions examples/nodejs/bitcoin/difficulty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import mempoolJS from "@mempool/mempool.js";

const init = async () => {
const {
bitcoin: { difficulty },
} = mempoolJS();

const difficultyAdjustment = await difficulty.getDifficultyAdjustment();
console.log(difficultyAdjustment);
};
init();

0 comments on commit aed4bc5

Please sign in to comment.