@bitcoin-computer/lib v0.19.0-beta.0
Use in a Browser
Create a file index.html
and open it in your browser.
<html>
<head>
<script type="module">
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()
await computer.faucet(0.0001e8)
const counter = await computer.new(Counter)
document.getElementById("count").innerHTML = counter.n
await counter.inc()
document.getElementById("count").innerHTML = counter.n
</script>
</head>
<body>
Counter value: <span id='count'>*</span>
</body>
</html>
You should see "Counter value: x" where x is '*' at first, then '0' and then '1'. Have a look here for a full example using React.
Use on a Server
You need to have node.js installed. First install the Bitcoin Computer library.
# Create packages.json file
npm init
# Install library
npm install @bitcoin-computer/lib
Then 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()
// 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)
Execute 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']
}
You can find a full example here.
Connect to a Bitcoin Computer Node
By default, a computer
object will connect to a Bitcoin Computer Node in regtest mode that we provide. You can connect to your own node by installing the Bitcoin Computer Node and starting it with the command below:
# Start a node
npm run up -- -litecoin -regtest
You can use the url
parameter for the Computer
constructor call to specify which node to connect to. Make sure that chain
and network
match your node's configuration.
// connect to a specific node url
const computer = new Computer({ url: 'http://localhost:1031' })
Documentation
Have a look at the docs.
Getting Help
If you have any questions, please let us know on Telegram, Twitter, or by email clemens@bitcoincomputer.io.
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.
This fee is in addition to the mining fee. You can configure satoshis per byte.
Development Status
We are in beta, so there is a possibility of unknown bugs. Currently, mainnet is disabled in all jurisdictions.
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.
8 days ago
27 days ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
8 months ago
8 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago