Use in Node
In an empty directory run npm init -y and install Bitcoin Computer
1
npm i -s bitcoin-computer
Copied!
Create index.mjs as shown below (make sure to use the mjs file extension). Replace the string "replace this seed" with your own seed phrase, eg from your wallet or from here.
index.mjs
1
import { Computer } from 'bitcoin-computer'
2
3
// the smart contract
4
class Counter {
5
constructor() { this.n = 0 }
6
inc() { this.n += 1 }
7
}
8
9
10
// run the smart contract
11
;(async () => {
12
const computer = new Computer({
13
seed: 'replace this seed',
14
chain: 'BSV', // BSV or BCH
15
network: 'testnet' // testnet or livenet
16
})
17
const counter = await computer.new(Counter, [])
18
await counter.inc()
19
console.log(counter)
20
})()
Copied!
Run the contract using node --experimental-modules index.mjs. You will get an error message "Insufficient balance in address <my_address>"
Send a small amount of Bitcoin Cash to <my_address>, eg from a Bitcoin SV faucet or a Bitcoin Cash Faucet (or this Bitcoin Cash Faucet). Run the contract again and if it worked you will see:
1
Counter {
2
n: 1,
3
_id: '83553f27c9e4651323f1ebb...',
4
_rev: '290923708ca56ea448dd67...'
5
}
Copied!
If you get an error, make sure you are setting the chain parameter when creating the computer object.

Video

The source code from the video can be found on the Bitcoin Computer Github repository.
Last modified 1mo ago
Copy link
Contents
Video