初探bigchaindb
設定bigchaindb本地節點
使用docker
- pull image:
docker pull bigchaindb/bigchaindb:all-in-one
- run image:
docker run \
--detach \
--name bigchaindb \
--publish 9984:9984 \
--publish 9985:9985 \
--publish 27017:27017 \
--publish 26657:26657 \
--volume $HOME/bigchaindb_docker/mongodb/data/db:/data/db \
--volume $HOME/bigchaindb_docker/mongodb/data/configdb:/data/configdb \
--volume $HOME/bigchaindb_docker/tendermint:/tendermint \
bigchaindb/bigchaindb:all-in-one`
python 程式
- 設定節點
from bigchaindb_driver import BigchainDB
bdb_root_url = 'http://localhost:9984'
bdb = BigchainDB(bdb_root_url)
- 定義asset(資產)
game_boy_token = {
'data': {
'token_for': {
'game_boy': {
'serial_number': 'LR1235'
}
},
'description': 'Time share token. Each token equals one hour of usage.',
},
}
- 建立交易
prepared_token_tx = bdb.transactions.prepare(
operation='CREATE',
signers=alice.public_key,
recipients=[([bob.public_key], 10)],
asset=game_boy_token)
- 簽署交易
fulfilled_token_tx = bdb.transactions.fulfill(
prepared_token_tx,
private_keys=alice.private_key)
- 送出交易
txn_id = bdb.transactions.send_commit(fulfilled_token_tx)
txn_id
應該會看到以下