SharpChain is a simple blockchain implementation for educational purposes, written in C#. It is a simpler, smaller model of the Bitcoin blockchain. I believe it makes it easier to see how the blockchain actually works nicely.
.NET Core 2.0 SDK
If you have Visual Studio, just open the .sln file and build as usual. Alternatively, you can do:
dotnet build
in the folder where the .sln file is.
Query | Description |
---|---|
SharpChain/Register | Gets the user an ID to use with their requests. |
SharpChain/Mine/{ID} | Mines a block using the Hashcash algorithm. The default difficuly is 4, and the reward is 1 SharpCoin. |
SharpChain/GetBalance/{ID} | Gets the balance of {ID}. |
SharpChain/SendCoin/{senderID}/{recipientID}/{amount} | Send {amount} of SharpCoins to {recipientID}. The {senderID} should be your ID. |
SharpChain/GetChain | Gets the whole blockchain as JSON. |
First you need to get and ID, like so:
localhost:9532/SharpChain/Register
This will return an ID, like 723e83c4-8f43-4e96-a1e2-af895d041a46. After that, SharpChain works exactly like the Bitcoin blockchain. You need to mine blocks with:
localhost:9532/SharpChain/Mine/723e83c4-8f43-4e96-a1e2-af895d041a46
Blocks are needed to store transactions & send coins to someone. You can send coins with:
localhost:9532/SharpChain/SendCoin/723e83c4-8f43-4e96-a1e2-af895d041a46/f6b88148-b0e9-439c-b246-21e7a55e0c11/5
This will send 5 SharpCoins to f6b88148-b0e9-439c-b246-21e7a55e0c11, from 723e83c4-8f43-4e96-a1e2-af895d041a46. The transaction will be added to the next mined block.
You can see your balance anytime with:
localhost:9532/SharpChain/GetBalance/723e83c4-8f43-4e96-a1e2-af895d041a46
If anytime, you want to see the whole chain, you can do:
localhost:9532/SharpChain/GetChain
- Consensus
- Persistance
- UI