The BitcoinToken library is a collection of tools that make it easy to integrate Bitcoin into web applications.
- BitcoinSource a readable JS implementation of Bitcoin
- BitcoinWallet send, store, and receive Bitcoin
- BitcoinDb store data on the blockchain
- BitcoinToken issue tokens
The docs are at www.bitcointoken.com/docs
You need node.js and npm installed. Then install BitcoinToken using
npm i bitcointoken
If you only want to use BitcoinWallet you are done. If you want to use BitcoinDb or BitcoinToken you need to install and run a non-standard server in a separate terminal window.
We recommend to use Docker and Docker Compose to build and run the server using the commands below. If you do not use docker you can find instructions in the Github repo.
git clone https://github.com/BitcoinDB/bitcoin-non-standard-server.git
cd bitcoin-non-standard-server
docker-compose up
After installing BitcoinToken, create a file index.js
// index.js
const { Wallet } = require('bitcointoken')
const wallet = new Wallet()
console.log(`address: ${wallet.getAddress()}`)
Run the code
node index.js
The output should be similar to address: mwZd1bgRYhxY4JLyx1sdEGBYFZnXVDvgmp
After installing BitcoinToken, create files index.js
and index.html
.
// index.js
const Bitcoin = require('bitcointoken')
const wallet = new Bitcoin.Wallet()
document.body.innerHTML = `address: ${wallet.getAddress()}`
<!-- index.html -->
<html>
<body>
<script src="./bundle.js"></script>
</body>
</html>
Install and run browserify
npm install -g browserify
browserify index.js > bundle.js
Open index.html
in a web browser
If you have a problem that is not discussed here, please let us know in the Telegram group.
The problem is most likely that you are not running the non-standard server.
You have to fund your wallet. First check that the same wallet is generated every time you run your code: Run it multiple times and check if the same address is logged every time.
If so you can fund that address using a testnet faucet.
Otherwise you need to initialize your object from a mnemonic. To generate a mnemonic, create the file generate-mnemonic.js
and run it using node --experimental-repl-await generate-mnemonic.js
. Now you can generate your object using the logged mnemonic using Wallet.fromMnemonic()
and fund it using the testnet faucet
const { Wallet } = require('bitcointoken')
console.log(Wallet.getRandomMnemonic())