Add difficulty adjustment examples.

This commit is contained in:
Miguel Medeiros 2021-07-23 17:58:54 -03:00
parent caf8d956b5
commit aed4bc5fc9
3 changed files with 48 additions and 0 deletions

View File

@ -31,6 +31,8 @@ Interface to access the Bitcoin `mainet`, `testnet`, `signet` APIs.
- [Get Blocks](#get-blocks) - [Get Blocks](#get-blocks)
- [Get Blocks Tip Height](#get-blocks-tip-height) - [Get Blocks Tip Height](#get-blocks-tip-height)
- [Get Blocks Tip Hash](#get-blocks-tip-hash) - [Get Blocks Tip Hash](#get-blocks-tip-hash)
- Difficulty
- [Get Difficulty Adjustment](#get-difficulty-adjustment)
- Fees - Fees
- [Get Fees Recommended](#get-fees-recommended) - [Get Fees Recommended](#get-fees-recommended)
- [Get Fees Mempool Blocks](#get-fees-mempool-blocks) - [Get Fees Mempool Blocks](#get-fees-mempool-blocks)
@ -376,6 +378,21 @@ const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHash); 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** ### **Get Fees Recommended**
Returns our currently suggested fees for new transactions. Returns our currently suggested fees for new transactions.

View File

@ -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>

View File

@ -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();