Create file .babelrc
{"presets": [ "@babel/preset-env" ],"plugins": [ [ "@babel/transform-runtime" ] ]}
Create file index.html
<html><body><div id='el'></div><script src="./index.js"></script></body></html>
Create file index.js
import { Computer } from 'bitcoin-computer'const Counter = `class Counter {constructor() { this.n = 0 }inc() { this.n += 1 }}`;(async () => {const computer = new Computer({seed: 'replace this seed',chain: 'BSV', // BSV or BCHnetwork: 'testnet', // testnet or livenetpath: "m/44'/0'/0'/0" // defaults to "m/44'/0'/0'/0"})const counter = await computer.new(Counter, [])document.getElementById("el").innerHTML = `Counter is ${counter.n}`await counter.inc()document.getElementById("el").innerHTML = `Counter is ${counter.n}`})()
Run the following in an empty directory
npm init -ynpm i -s bitcoin-computernpm i -g parcel-bundlernpm i -s @babel/runtimenpm i -d @babel/plugin-transform-runtimeparcel index.html
Open your browser at http://localhost:1234
. You will see an error "Insufficient balance in address <my-address>". Send a small amount of Bitcoin to that address to make it work. You can get free testnet coins from a Bitcoin SV faucet or a Bitcoin Cash Faucet.
The recommended way of using the Bitcoin Computer is client-side using React. The video explains how to build a basic Bitcoin Wallet using Bitcoin Computer. It's a good starting point for any Bitcoin project.
The source code from the video can be found on the Bitcoin|Computer Github.