You need to have node.js installed.
Run the commands below in an empty folder.
# Create packages.json file
npm init
# Install library
npm install @bitcoin-computer/lib
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)
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']
}
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
Create a file index.html
<html>
<body>
<script type="module" src="./index.mjs"></script>
Counter value: <span id='count'></span>
</body>
</html>
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
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
})
Have a look at the docs.
If you have any questions, please let us know on Telegram, Twitter, or by email clemens@bitcoincomputer.io.
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.
There are no known security vulnerabilities. However we do not yet recommend to use the Bitcoin Computer in production yet.
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.