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.10
  • 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. bitcoincomputer.io

Run in Node

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

Create file index.mjs as shown below. Replace the string "replace this seed" with your own seed phrase (eg from your wallet or from here).

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)
  computer.shutdown()
})()

Send testnet coins to the computer

To run the code you need to fund the Bitcoin wallet inside the computer object. Run the code using node --experimental-modules index.mjs. You will get an error message "Insufficient balance in address <your_address>".

Send free testnet coins from a Bitcoin SV faucet or a Bitcoin Cash Faucet to <your_address>. Run the contract again and you will see:

Counter {
  n: 1,
  _owners: [ '028b43c3e12159179c...' ],
  _amount: 2000
}

Run in the Browser

Create file .babelrc

{
  "presets": [ "@babel/preset-env" ],
  "plugins": [ [ "@babel/transform-runtime" ] ]
}

Create file index.html

<html>
  <body>
    <script src="./index.js"></script>
    <div id='el'></div>
  </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: 'BCH', // BSV or BCH
    network: 'testnet' // testnet or livenet
  })
  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}`;

  computer.shutdown()
})()

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 pick your own seed phrase and how to fund the computer in the section above

Documentation

You can find more information in the Bitcoin|Computer Docs

Getting Help

Bitcoin|Computer is in alpha stage, so there will be bugs. If you have any issues, please

Keywords

FAQs

Package last updated on 01 Jun 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