This application is a simple blockchain implementation. There is functionality for creating transactions, putting them in the transactions pool, verifying, mining the new block and adding to the blockchain.
You need to have Elixir 1.6 and Erlang/OTP 20. Detailed installation instructions can be found at: http://elixir-lang.org/install.html.
mix deps.get
Start the application in interactive Elixir mode:
iex -S mix
iex> Blockchain.Miner.Worker.start()
This will continuously mine new blocks until you stop the miner.
iex> Blockchain.Miner.Worker.mine_one_block()
This will mine only one block.
iex> Blockchain.Miner.Worker.stop()
iex> Blockchain.Chain.Worker.get_state()
There is information about last block in the chain and accounts with their tokens
iex> Blockchain.Pool.Worker.check_pool()
To interact with blockchain first of all you should have some tokens. To generate them you have to start miner for at least 10 seconds.
iex> Blockchain.Miner.Worker.start()
Stop the miner:
iex> Blockchain.Miner.Worker.stop()
You can check your balance in the chanstate:
iex> Blockchain.Chain.Worker.get_state()
To create a transaction you should have private and public key.
- Create private and public key:
iex> private_key_miner = Blockchain.Keys.Mock.private_key_miner()
iex> pub_key_miner = Blockchain.Keys.Mock.pub_key_miner()
iex> private_key_1 = Blockchain.Keys.Mock.private_key_1()
iex> pub_key_1 = Blockchain.Keys.Mock.pub_key_1()
- Then, build the transaction:
iex> alias Blockchain.Structures.Transaction
iex> alias Blockchain.Structures.SignedTx
iex> alias Blockchain.Pool.Worker, as: Pool
iex> data = Transaction.create(pub_key_miner, pub_key_1, 100)
iex> tx = SignedTx.sign_tx(data, private_key_miner)
- Next, add the transaction to the pool:
iex> Blockchain.Pool.Worker.add_tx(tx)
- To check what is in the pool:
iex> Blockchain.Pool.Worker.check_pool()
- To mine one block
iex> Blockchain.Miner.Worker.mine_one_block()
If you have enough money the transaction will appear in the new block. Otherwise the transaction will stay in the pool.
- Check the state to see if yout transaction is in the new block.
iex> Blockchain.Chain.Worker.get_state()