Money Button Documentation

Money Button Documentation

  • Money Button
  • API
  • Examples
  • Paymail
  • bsv

›Examples

Money Button

  • Money Button Overview
  • HTML
  • Javascript
  • React
  • Crypto Operations
  • Invisible Money Button
  • Paymail Signatures
  • Paymail Encryption

API

  • API Overview
  • Apps
  • Webhooks
  • Tokens
  • Currencies
  • Javascript Client
  • Authentication

    • Authentication Overview
    • OAuth
    • OAuth With JS Client

    API v1

    • Get User Identity
    • Get User Profile
    • Get User Balance
    • Get Payments
    • Get Payment By ID

    API v2

    • Get User Balances
    • Get Payments
    • Get Payment By ID
    • Get Assets
    • Create Asset
    • Modify Asset

Simple Fabriik Protocol for Tokens

  • Protocol Overview
  • Wallets Integration Guide
  • SFP Paymail Extension Build Action
  • SFP Paymail Extension Authorise Action

Examples

  • Examples Overview
  • OP_RETURN Scripts
  • Assets

Paymail

  • Paymail Overview
  • Paymail Video Series
  • Paymail Introduction
  • BRFC Specifications
  • Specification Documents
  • BRFC ID Assignment
  • Service Discovery
  • Host Discovery
  • Capability Discovery
  • Public Key Infrastructure
  • Payment Addressing
  • Payment Addressing (Basic Address Resolution)
  • Payment Addressing (Payer Validation)
  • Payment Addressing (Payee Approvals)
  • Payment Addressing (PayTo Protocol Prefix)
  • Verify Public Key Owner
  • P2P Transactions
  • P2P Payment Destination
  • P2P Payment Destination with Tokens Support
  • Asset Information
  • Recommendations

Bitcoin SV Library (bsv)

  • Bitcoin SV Library (bsv)
  • Big Numbers
  • Points (Elliptic Curves)
  • Hash Functions
  • Base 58
  • Private Keys
  • Public Keys
  • Addresses
  • ECDSA
  • Bitcoin Signed Messages
  • Signatures
  • HD Private Keys (BIP32)
  • HD Public Keys (BIP32)
  • Mnemonics (BIP39)
  • Script

OP_RETURN Scripts

The most common way to use bsv with a Money Button app is to write sophisticated scripts, particularly OP_RETURN scripts.

First, a bit of background. Transactions in Bitcoin SV have inputs and outputs. Each input comes from an earlier output. Each input and output has a script inside. For a transaction to be valid, each input must be valid. For an input to be valid, the script of the input must evaluate true, and then, keeping the stack the same, the script from the previous output must also evaluate true.

Scripts are written in binary inside a Bitcoin transaction using a custom format. There is a standard way to write scripts in string format called "ASM". The ASM format is supported by bsv.

An example of an OP_RETURN script written in ASM format is this:

OP_FALSE OP_RETURN 6d6f6e6579627574746f6e2e636f6d

You can see it starts with the OP_FALSE and OP_RETURN opcodes.

The value "6d6f6e6579627574746f6e2e636f6d" is actually the string "moneybutton.com" encoded in hex format.

To convert a string to a utf8-encoded hex string in node.js, use this:

Buffer.from('moneybutton.com').toString('hex')

A more sophisticiated OP_RETURN script looks like this:

OP_FALSE OP_RETURN 6d6f6e6579627574746f6e2e636f6d 75746638 68656c6c6f2e20686f772061726520796f753f

This script pushes three different values. The values are as follows:

hexstring
6d6f6e6579627574746f6e2e636f6dmoneybutton.com
75746638utf8
68656c6c6f2e20686f772061726520796f753fhello. how are you?

bsv has a convenience method for writing scripts like this. use the bsv.Script.buildSafeDataOut. It works like this:

bsv.Script.buildSafeDataOut(['moneybutton.com', 'utf8', 'hello. how are you?']).toAsmString()

That code will return this string value:

'OP_FALSE OP_RETURN 6d6f6e6579627574746f6e2e636f6d 75746638 68656c6c6f2e20686f772061726520796f753f'

You can insert this value into a Money Button output as follows. If you are using the HTML Money Button, it looks like this:

<div class='money-button'
  data-outputs='[{
    "script": "OP_FALSE OP_RETURN 6d6f6e6579627574746f6e2e636f6d 75746638 68656c6c6f2e20686f772061726520796f753f",
    "amount": "0",
    "currency": "BSV"
  }]'
></div>

If you are using the Javascript Money Button, it looks like this:

<div id='my-money-button'></div>
<script language='javascript'>
  const div = document.getElementById('my-money-button')
  moneyButton.render(div, {
    outputs: [{
      script: 'OP_FALSE OP_RETURN 6d6f6e6579627574746f6e2e636f6d 75746638 68656c6c6f2e20686f772061726520796f753f',
      amount: '0',
      currency: 'BSV'
    }]
  })
</script>

The most popular way to insert file data into the blockchain is to use B. However, data can be structure in any way and it is up to writers (wallets) and readers (block explorers or browsers) to decide what works best for their application.

← Examples OverviewAssets →
Money Button Documentation
Docs
Money ButtonAPIDesignbsv
Community
redditYoutubeTelegramTwitter
More
BlogInstagramGitHubStar
See an error in our documentation? Issue a pull request to fix it.
Copyright © 2022 Fermatted Drives Limited