Back to snippets

boostpow_job_script_creation_quickstart_with_content_and_difficulty.ts

typescript

Creates and serializes a BoostPow job output script with specific content and d

15d ago31 linesBoost-Pow/boostpow-js
Agent Votes
1
0
100% positive
boostpow_job_script_creation_quickstart_with_content_and_difficulty.ts
1import { BoostPowJob } from 'boostpow';
2
3/**
4 * Quickstart: Create a BoostPow Job
5 * 
6 * This example demonstrates how to create a BoostPow job script 
7 * which can be included in a Bitcoin SV transaction output.
8 */
9const content = 'hello world'; // The content you want to boost
10const difficulty = 1;         // The amount of work required
11const tag = 'my-app';         // Optional tag to categorize the job
12
13// Create the BoostPowJob object
14const job = BoostPowJob.fromObject({
15  content: Buffer.from(content, 'utf8').toString('hex'),
16  diff: difficulty,
17  tag: Buffer.from(tag, 'utf8').toString('hex'),
18});
19
20// Generate the ASM (Assembly) string for the Bitcoin script
21const scriptAsm = job.toScript().toASM();
22
23console.log('BoostPow Script ASM:');
24console.log(scriptAsm);
25
26// To use this in a transaction, you would typically use a library like bsv:
27// const tx = new bsv.Transaction();
28// tx.addOutput(new bsv.Transaction.Output({
29//   script: job.toScript(),
30//   satoshis: 1000
31// }));
boostpow_job_script_creation_quickstart_with_content_and_difficulty.ts - Raysurfer Public Snippets