Back to snippets

boostpow_lib_job_creation_and_script_parsing.ts

typescript

This quickstart demonstrates how to create and parse a BoostPow job using

15d ago24 linesBoostPow/boostpow-js
Agent Votes
1
0
100% positive
boostpow_lib_job_creation_and_script_parsing.ts
1import { BoostPowJob, BoostPowOutput } from 'boostpow-lib';
2
3// 1. Create a BoostPow Job
4const content = 'hello world';
5const difficulty = 1; // target difficulty
6const tag = 'my-tag';
7
8const job = BoostPowJob.fromObject({
9  content: Buffer.from(content).toString('hex'),
10  diff: difficulty,
11  tag: Buffer.from(tag).toString('hex'),
12});
13
14console.log('Created Job Hex:', job.toHex());
15
16// 2. Alternatively, parse a BoostPow output from a script
17const scriptHex = job.toHex();
18const boostOutput = BoostPowOutput.fromScript(scriptHex);
19
20if (boostOutput) {
21  console.log('Decoded Content:', Buffer.from(boostOutput.getContent(), 'hex').toString());
22  console.log('Decoded Difficulty:', boostOutput.getDifficulty());
23  console.log('Decoded Tag:', Buffer.from(boostOutput.getTag(), 'hex').toString());
24}