bitsim
bitcoin simulator
about
bitsim is the controller for the your bitcoin simulation environment. it works with the bitsim docker image.
prerequisites
- docker
- nodejs
manual
installation
npm i --save bitsim
start the console
single-player mode
docker run --name bitsim -d -p 18332-18333:18332-18333 -p 18444:18444 planaria/bitsim:0.0.1
multi-player mode ( COMING SOON )
curl https://raw.githubusercontent.com/interplanaria/bitsim/master/docker-compose.yml > docker-compose.yml && docker-compose up -d
play the demo
1) enter NodeJS REPL
node
for more information on how to use NodeJS REPL, see the docs
we will be using
.then
syntax to read the callbacks in realtime without async scope. it's worht noting that ordinarily, you'd probably want to use async/await.
2) initialize new Bitsim controller
const Bitsim = const bitsim =
3) mine some blocks
// mine a single blockbitsim // mine 5 blocksbitsim // check status (most recent block header)bitsim
4) submit transactions
// initial fund step (more details below)bitsim // add 10 "default" data transactions (more details below)bitsim // add 1000 data transactionsbitsim // add 100 custom data transactionlet dataOut = "o0": "OP_0" "o1": "OP_RETURN" "s2": "Hello My Custom Transaction" bitsim // check the mempoolbitsim
NOTE: initial funding requires mining 100 blocks to make the coinbase bitcoin eligible for spending. this coinbase transaction is used to fund a local toychain which builds and submits to the Bitsim peer.
NOTE: the term "default transaction" refers to the default prototype data out transaction provided by the Bitsim library.
5) create a fork
// get the last block headerlet lastHeight; bitsim // create a fork 3 blocks backbitsim // get the new last block headerlet newHeightbitsim
learn the controls
initialize
const Bitsim = const bitsim =
core methods
;async await bitsim // initializes and bootstraps toychain // 1. funds toychain with coinbase tx // 2. mines 100 blocks so those coin are spendable // 3. bootstraps tx tree to avoid mempool limit await bitsim // returns last block header from node await bitsim // mines `n` number of blocks to `address` // parameters are optional. will use default if blank await bitsim // adds `n` data-only transactions to mempool with prototype (output array) await bitsim // creates fork at given block `height` by invalidating `height + 1` await bitsim // return arbitrary rpc method response. accepts array of params or no params
convenience methods
;async await bitsim // provides random block height and hash from chain within limit // useful for creating tests await bitsim // wrapper for `getbestblockhash` rpc call await bitsim // wrapper for `getblockheader` rpc call await bitsim // wrapper for `getmempoolinfo` rpc call await bitsim // wrapper for `getrawmempool` rpc call await bitsim // wrapper for `getblockhash` rpc call await bitsim // wrapper for `invalidateBlock` rpc call
settings
pass configuration options to bitsim as an object on initialization:
const bitsim = mine: 1 delay: 1000 rpc: 'http://root:bitcoin@127.0.0.1:18332' xpriv: 'xprv9s21ZrQH143K2AUh9yj3SmnzFVpHFgfGh23tz9iQb6p86yee29B1CcUenjSvWUFtNQ6oBho8PwPZNPi758kTFvJnxs1SoYbtUbyZeTK9zBC'
the above represent the default configuration, and need not be specified for most use cases.