Use in a Browser
Create file .babelrc
1
{
2
"presets": [ "@babel/preset-env" ],
3
"plugins": [ [ "@babel/transform-runtime" ] ]
4
}
Copied!
Create file index.html
1
<html>
2
<body>
3
<div id='el'></div>
4
<script src="./index.js"></script>
5
</body>
6
</html>
Copied!
Create file index.js
1
import { Computer } from 'bitcoin-computer'
2
3
const Counter = `class Counter {
4
constructor() { this.n = 0 }
5
inc() { this.n += 1 }
6
}`
7
8
9
;(async () => {
10
const computer = new Computer({
11
seed: 'replace this seed',
12
chain: 'BSV', // BSV or BCH
13
network: 'testnet', // testnet or livenet
14
path: "m/44'/0'/0'/0" // defaults to "m/44'/0'/0'/0"
15
})
16
const counter = await computer.new(Counter, [])
17
document.getElementById("el").innerHTML = `Counter is ${counter.n}`
18
19
await counter.inc()
20
document.getElementById("el").innerHTML = `Counter is ${counter.n}`
21
})()
Copied!
Run the following in an empty directory
1
npm init -y
2
npm i -s bitcoin-computer
3
npm i -g parcel-bundler
4
npm i -s @babel/runtime
5
npm i -d @babel/plugin-transform-runtime
6
parcel index.html
Copied!
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.
Last modified 9mo ago
Copy link
Contents
Video