Use in Node

In an empty directory run npm init -y and install Bitcoin Computer

npm i -s bitcoin-computer

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
import { Computer } from 'bitcoin-computer'
// the smart contract
class Counter {
constructor() { this.n = 0 }
inc() { this.n += 1 }
}
// run the smart contract
;(async () => {
const computer = new Computer({
seed: 'replace this seed',
chain: 'BSV', // BSV or BCH
network: 'testnet' // testnet or livenet
})
const counter = await computer.new(Counter, [])
await counter.inc()
console.log(counter)
})()

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. Run the contract again and if it worked you will see:

Counter {
n: 1,
_id: '83553f27c9e4651323f1ebb...',
_rev: '290923708ca56ea448dd67...'
}

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.