New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bitcoin-computer

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcoin-computer

Smart Contracts on Bitcoin

  • 0.3.0-alpha.18
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source
logo

Bitcoin Computer

BitcoinComputer is a Javascript library for running smart contracts on Bitcoin. See bitcoincomputer.io for more documentation.

Run the Tests

The easiest way to get started is to run the tests. In an empty directory run

git clone git@github.com:bitcoin-computer/computer.git
cd computer
npm install
npm test

If you get an error "Insuffienct balance in <your address>" send free testnet coins to <your address> as explained in Fund Your Computer below.

Run in Node

In an empty directory run

npm init -y && npm i -s bitcoin-computer

Create file index.mjs as shown below.

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 code using

node --experimental-modules index.mjs

If you get an error "Insuffienct funds in <your address>" have a look at the secion Fund Your Computer below. Run the code again after funding the wallet and you will see:

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

Run in the 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'

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. See the instructions for how to configure your own seed phrase and how to fund the computer in the sections below.

Configure Your Seed Phrase

By default the bitcoin computer object uses the pass phrase "replace this seed" to initialize the wallet. If you want to use your own seed phrase, replace the string "replace this seed" with any bip39 compatible seed phrase or generate a new one here.

Fund Your Computer

If you get an error message "Insufficient balance in address <your_address>" you need to fund the wallet inside the computer object. You can get free testnet coins from a Bitcoin SV faucet or a Bitcoin Cash Faucet and send them to <your_address>.

Documentation

You can find more information in the Bitcoin Computer Docs

Getting Help

If you have any issues ask a question in the Telegram Group or create an issue on Github.

Breaking Changes

  • 0.3.0-alpha.10 -> 0.3.0-alpha.11: We changed the default wallet derivation path from the empty string to "m/44'/0'/0'/0". To use funds from a wallet created in version 0.3.0-alpha.10 or before, set the path option to the empty string when creating a computer object.

Keywords

FAQs

Package last updated on 23 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc