Skip to content

Commit b34040c

Browse files
committed
feat(getPsffppPrice): New endpoint to get PSFFPP pin price
1 parent 01a4d0f commit b34040c

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/price.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,42 @@ class Price {
230230
else throw err
231231
}
232232
}
233+
234+
/**
235+
* @api price.getPsffppPrice() getPsffppPrice()
236+
* @apiName Price getPsffppPrice()
237+
* @apiGroup Price
238+
* @apiDescription Return the cost in PSF tokens to write 1MB of data to the PSFFPP
239+
* Find out more at PSFFPP.com. This is a IPFS pinning service that can pin
240+
* up to 100MB per transaction into its network. The cost is denominated in
241+
* PSF SLP tokens. The endpoint returns the cost to pin 1MB of data to the
242+
* PSFFPP network.
243+
*
244+
* @apiExample Example usage:
245+
*(async () => {
246+
* try {
247+
* let current = await bchjs.Price.getPsffppPrice();
248+
* console.log(current);
249+
* } catch(err) {
250+
* console.error(err)
251+
* }
252+
*})()
253+
*
254+
* // 0.08335233
255+
*/
256+
async getPsffppPrice () {
257+
try {
258+
const response = await this.axios.get(
259+
`${this.restURL}price/psffpp`,
260+
this.axiosOptions
261+
)
262+
263+
return response.data.writePrice
264+
} catch (err) {
265+
if (err.response && err.response.data) throw err.response.data
266+
else throw err
267+
}
268+
}
233269
}
234270

235271
module.exports = Price

test/integration/price.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ describe('#price', () => {
5252
assert.property(result, 'CAD')
5353
})
5454
})
55+
56+
describe('#getPsffppPrice', () => {
57+
it('should get the price of BCH in several currencies', async () => {
58+
const result = await bchjs.Price.getPsffppPrice()
59+
// console.log(result)
60+
61+
assert.isNumber(result)
62+
})
63+
})
5564
})
5665

5766
function sleep (ms) {

0 commit comments

Comments
 (0)