Use in a Browser

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 BCH
network: 'testnet', // testnet or livenet
path: "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 -y
npm i -s bitcoin-computer
npm i -g parcel-bundler
npm i -s @babel/runtime
npm i -d @babel/plugin-transform-runtime
parcel 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.

Video

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.