{"id":16930204,"url":"https://github.com/digorithm/blockchain-rs","last_synced_at":"2025-06-11T04:10:27.022Z","repository":{"id":82926157,"uuid":"372027331","full_name":"digorithm/blockchain-rs","owner":"digorithm","description":"Simple multi-node Proof-of-Work blockchain written in rust. Not trying to be the next Dogecoin. ","archived":false,"fork":false,"pushed_at":"2021-06-04T00:21:49.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T00:11:20.896Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digorithm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-29T17:01:45.000Z","updated_at":"2024-04-07T07:15:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"a0902f9f-e626-4370-bc7a-673cbf3f37ac","html_url":"https://github.com/digorithm/blockchain-rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digorithm%2Fblockchain-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digorithm%2Fblockchain-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digorithm%2Fblockchain-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digorithm%2Fblockchain-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digorithm","download_url":"https://codeload.github.com/digorithm/blockchain-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244729241,"owners_count":20500214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T20:41:08.445Z","updated_at":"2025-03-21T03:23:48.496Z","avatar_url":"https://github.com/digorithm.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blockchain-rs\n\nSimple proof of concept blockchain written in Rust. _Do not build the next Dogecoin on top of this, I won't be held responsible!_\n\n**Jokes aside, this was built for learning purposes, meaning it's not production-quality at all.**\n\nIt support basic blockchain capabilities such as multi-node Proof-of-Work consensus. It exposes a HTTP API with the following endpoints:\n\n```rust\n.service(web::resource(\"/nodes/register\").route(web::post().to(register)))\n.service(web::resource(\"/nodes/resolve\").route(web::get().to(resolve)))\n.service(web::resource(\"/mine\").route(web::get().to(mine)))\n.service(web::resource(\"/chain\").route(web::get().to(chain)))\n.service(web::resource(\"/transactions/new\").route(web::post().to(transaction)))\n```\n\nThere a lot of missing features I would like to add someday for fun:\n1. Bootstrap node and node registration broadcasting (currently you have to manually register every node);\n2. RPC-based communication;\n3. Persistence to disk (currently everything is in-memory);\n4. Public-key encryption (right now it's all UUID + sha hashing);\n5. Different consensus algorithms such as Proof-of-Stake;\n6. Much more validations and assertions;\n7. For PoW: configurable and dynamic mining difficulty (right now it's hardcoded);\n8. Remove most of the `.clone()` parts in the codebase that I inserted for speed-of-development reasons (I ain't got no time to fight you, borrow checker!). Removing should improve memory efficiency considerably;\n9. And much more.\n\n## Running nodes and interacting with them\n\nTo run a node you can use: `cargo run -- 8080` where the only argument is the port exposed by that single node.\n\nWhen running multiple nodes, you must register each one of them manually. For instance, to register `8080` to the `8081` node:\n```\n curl -X POST -d '{\"addresses\": [\"http://localhost:8080\"]}' -H \"Content-type: application/json\" http://localhost:8081/nodes/register\n```\n\nNote that you also have to register `8081` to `8080`. This is necessary for the consensus algorithm to work properly; Once their chain differ, they will query each other's chain and pick the longest one.\n\nTo query the current chain in a node you can: \n\n```\ncurl http://localhost:8080/chain | json_pp\n[\n   {\n      \"index\" : 1,\n      \"previous_hash\" : \"1\",\n      \"proof\" : 100,\n      \"timestamp\" : {\n         \"nanos_since_epoch\" : 658139000,\n         \"secs_since_epoch\" : 1622306099\n      },\n      \"transactions\" : []\n   },\n   {\n      \"index\" : 2,\n      \"previous_hash\" : \"ECADC938053B0063C9C5ADCA6EBF64B7E8004FD1FB5B196DD782C59D3470213B\",\n      \"proof\" : 248000,\n      \"timestamp\" : {\n         \"nanos_since_epoch\" : 191055800,\n         \"secs_since_epoch\" : 1622306146\n      },\n      \"transactions\" : [\n         {\n            \"amount\" : 1,\n            \"recipient\" : \"9509df17-9979-4b36-9942-e8c4cbf09830\",\n            \"sender\" : \"0\"\n         }\n      ]\n   },\n   {\n      \"index\" : 3,\n      \"previous_hash\" : \"4F80AFD7194667E0AA77FD8FC745CE36BBC19F7C9CCC930D50CC826C4BD39FEF\",\n      \"proof\" : 101720,\n      \"timestamp\" : {\n         \"nanos_since_epoch\" : 304410600,\n         \"secs_since_epoch\" : 1622306169\n      },\n      \"transactions\" : [\n         {\n            \"amount\" : 1,\n            \"recipient\" : \"55098877-a3a4-40ee-b68a-1f7e459aa20d\",\n            \"sender\" : \"0\"\n         }\n      ]\n   },\n   {\n      \"index\" : 4,\n      \"previous_hash\" : \"ACB813083B3026D5A75E1E0FE53A30FEBC3BCC8BAA41FFDFB2938845F9462763\",\n      \"proof\" : 1282,\n      \"timestamp\" : {\n         \"nanos_since_epoch\" : 988313400,\n         \"secs_since_epoch\" : 1622306230\n      },\n      \"transactions\" : [\n         {\n            \"amount\" : 1,\n            \"recipient\" : \"9509df17-9979-4b36-9942-e8c4cbf09830\",\n            \"sender\" : \"0\"\n         }\n      ]\n   }\n]\n```\n\nSender \"0\" means it's an award for mining.\n\nTo send a transaction: \n```\ncurl -X POST -d '{\"amount\": 10.0, \"sender\": \"349857dhkfjg\", \"recipient\": \"234098dflsdf\"}' -H \"Content-type: application/json\" http://localhost:8080/transactions/new\n```\n\nThe transaction will be added to the next mined block.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigorithm%2Fblockchain-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigorithm%2Fblockchain-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigorithm%2Fblockchain-rs/lists"}