0.1.7 • Published 1 year ago

hello-tokens v0.1.7

Weekly downloads
-
License
Open BSV License
Repository
-
Last release
1 year 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

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago