npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bitcoin-computer/lib

v0.18.0-beta.0

Published

Smart Contracts for Bitcoin

Downloads

153

Readme

Prerequisites

You need to have node.js installed.

Use on a Server

Install

Run the commands below in an empty folder.

# Create packages.json file
npm init

# Install library
npm install @bitcoin-computer/lib

Write a Smart Contract

Create a file index.mjs.

import { Computer, Contract } from '@bitcoin-computer/lib'

// A smart contract
class Counter extends Contract {
  constructor() {
    super({ n: 0 })
  }

  inc() {
    this.n += 1
  }
}

// Create a Bitcoin Computer wallet
const computer = new Computer({ mnemonic: 'drip audit speed belt gallery tribe bus poet used scrub view spike' })

// Fund the computer wallet
await computer.faucet(1e7)

// Deploy a smart contract and create a smart object
const counter = await computer.new(Counter)

// Update the smart object
await counter.inc()

// Log the smart object
console.log(counter)

Run the Smart Contract

node index.mjs

The expected output is:

Counter {
  n: 1,
  _id: '656...024:0',
  _rev: '90f...73f:0',
  _root: '656...024:0',
  _amount: 7860,
  _owners: ['037...954']
}

Use in a Browser

Write a Smart contract

Create a file index.mjs.

import { Computer, Contract } from "https://unpkg.com/@bitcoin-computer/lib/dist/bc-lib.browser.min.mjs";

class Counter extends Contract {
  constructor() {
    super({ n: 0 })
  }

  inc() {
    this.n += 1
  }
}

const computer = new Computer({ mnemonic: 'drip audit speed belt gallery tribe bus poet used scrub view spike' })

await computer.faucet(1e7)

const counter = await computer.new(Counter)
document.getElementById("count").innerHTML = counter.n

await counter.inc()
document.getElementById("count").innerHTML = counter.n

Make a Website

Create a file index.html

<html>
  <body>
    <script type="module" src="./index.mjs"></script>
    Counter value: <span id='count'></span>
  </body>
</html>

Start a Web Server

Run the following code in an empty directory and open http://localhost:8080.

# Create a packages.json file
npm init -y

# Install web server
npm i http-server

# Start web server
http-server

Use locally on regtest or connect to a mainnet node

Install a Bitcoin Computer Node and run it with the command below:

# Start a node
npm run up -- -litecoin -regtest

When you call the Computer constructor on the client, pass the url of your node to the url parameter. Make sure that chain and network match your node's configuration.

// Connect computer object to node url
const computer = new Computer({
  url: 'http://localhost:1031', // Bitcoin Computer Node node url
  chain: 'LTC', // LTC or BTC
  network: 'regtest', // regtest, testnet, or mainnet
  mnemonic: 'drip audit speed belt gallery tribe bus poet used scrub view spike', // BIP 39 mnemonic sentence
})

Documentation

Have a look at the docs.

Getting Help

If you have any questions, please let us know on Telegram, Twitter, or by email [email protected].

Price

It is free to develop and test on testnet and regtest. On mainnet we charge a small fee to support the development:

  • The fee for a constructor or function call is satoshis-per-byte * 475. This is about as much as the average transaction fee for a payment.
  • The fee for deploying a module makes use of the segwit discount. It is satoshis-per-byte * data size * 1/4.

You can configure satoshis per byte. This fee is in addition to the mining fee.

Development Status

There are no known security vulnerabilities. However we do not yet recommend to use the Bitcoin Computer in production yet.

License

This software is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported license.

You are free to: share, copy, and redistribute the material in any medium or format for any purpose, even commercially under the following terms:

  • Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material.

This is a human-readable summary of (and not a substitute for) the license.