--- layout: simple --- ## A toy chain ### The chain should have these properties: - Running on at least 2 pre-defined [nodes][7] (IP addresses given in a [config file][8] / no additional discovery necessary)- - [PoW][9], with every node a miner- - The [difficulty][10] is fixed (i.e., block time is not), each [block rewards][12] 100 coins- - [ECDSA][13] cryptography; addresses may be pure public keys- - Protect against [double][14] spending - [Transactions][11] can have additional data payload, signed by the sender (and there needs to be a way to [set it][5]) - Blocks can have additional data payload (and there needs to be a way to set it) - Implement a simple REST-like [web service][1] [API](/api/) which implements the following services and returns JSON data: * Query the [block count][2]. * Query a [single block][3] and return all its transaction data. * Query a [single transaction][4] and return all its data. * Create a [transaction][5] from JSON [data][11] and accept it for [mining][6]. ### Example of curl commands ```sh # getting block count curl http://127.0.0.1:8089/api/0.0/getheight # getting 4th block curl http://127.0.0.1:8089/api/0.0/getblock?n=4 # getting transaction Ztxrms5c5oKqb9Zof3xeC5Q2ZQjSaWv7FU4rAxe2s3sP curl http://127.0.0.1:8089/api/0.0/gettx?txaddr=Ztxrms5c5oKqb9Zof3xeC5Q2ZQjSaWv7FU4rAxe2s3sP # posting a transaction cat txpool/tx.yml | sed -e "s/$/%0a/g" | curl -s -X POST http://127.0.0.1:8089/api/0.0/settx -d @- # processing the txpool (mining) curl http://127.0.0.1:8089/api/0.0/minepool ``` ### Security Warning Blockchains are transparent and public so we encrypt private keys and other sensitive data, however as it is just a toy, we expose **all the files** for educational purpose. >> ** PLEASE DO NOT USE IN A PRODUCTION ENVIRONMENT ** note: sensitive data are encrypted w/ git-crypt; please send us your public key if you need access or ask for a shared DH secret decrypt can be done with the command : ```sh export GPG_ASKPASS=ssh-askpass git-crypt unlock #gpg --decrypt local.key.asc | git-crypt unlock - ``` [1]: webservice.html [2]: http://127.0.0.1:8089/api/0.0/getheight [3]: http://127.0.0.1:8089/api/0.0/getblock [4]: http://127.0.0.1:8089/api/0.0/gettx?encode=json&addr=txcoin [5]: http://127.0.0.1:8089/api/settx.html [6]: http://127.0.0.1:8089/api/0.0/minepool [7]: http://127.0.0.1:8089/docs/nodes.html [7a]: http://127.0.0.1:8089/api/0.0/getnodes [8]: http://127.0.0.1:8089/api/0.0/config [9]: http://127.0.0.1:8089/docs/pow.html [10]: http://127.0.0.1:8089/docs/difficulties.html [11]: http://127.0.0.1:8089/api/transaction.html [12]: http://127.0.0.1:8089/docs/bkreward.html [13]: http://127.0.0.1:8089/admin/keygen.html [14]: http://127.0.0.1:8089/docs/UTXO.html