0.1.7 • Published 10 months ago

hello-tokens v0.1.7

Weekly downloads
-
License
Open BSV License
Repository
-
Last release
10 months ago

hello-tokens

A simple utility for creating Bitcoin locking scripts that embed a "Hello World" message in the token.

Installation

To install the package, run:

npm i hello-tokens

Example Usage

import { HelloTokens } from 'hello-tokens'

// Create an output script
const script = await HelloTokens.createOutputScript('Hello Blockchain!')
const overlayURL = 'https://staging-overlay.babbage.systems'

// Create the action
const newToken = await createAction({
  outputs: [{
    satoshis: 1,
    script,
    description: 'New HelloWorld token'
  }],
  description: 'Create a HelloWorld token'
})

const beef = toBEEFfromEnvelope({
  rawTx: newToken.rawTx,
  inputs: newToken.inputs,
  txid: newToken.txid
}).beef

// Submit the new HelloWorld token to an Overlay Service
const submitResults = await fetch(`${overlayURL}/submit`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/octet-stream',
    'X-Topics': JSON.stringify(['tm_helloworld'])
  },
  body: new Uint8Array(beef)
})

// Find HelloWorld token by message
const lookupResults = await fetch(`${overlayURL}/lookup`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    service: 'ls_helloworld',
    query: 'Hello Blockchain!'
  })
})

// Parse the lookup answer
const lookupAnswer = await lookupResults.json()
const message = await HelloTokens.parseLookupAnswer(lookupAnswer)

Note: You must have the MetaNet Client or other compatible wallet available.

0.1.7

10 months ago

0.1.6

10 months ago

0.1.5

10 months ago

0.1.4

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago