{"id":14980142,"url":"https://github.com/demining/bitcoin-ruby-google-colab","last_synced_at":"2025-04-12T12:50:58.090Z","repository":{"id":144620869,"uuid":"460550829","full_name":"demining/bitcoin-ruby-Google-Colab","owner":"demining","description":"bitcoin utils and protocol in ruby Google Colab","archived":false,"fork":false,"pushed_at":"2022-07-02T01:18:53.000Z","size":8235,"stargazers_count":1,"open_issues_count":0,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T07:36:16.394Z","etag":null,"topics":["bitcoin","bitcoin-api","bitcoin-core","bitcoin-payment","bitcoin-transaction","bitcoin-wallet","colab","colab-notebook","colab-notebooks","colab-tutorial","colaboratory","google-colab","google-colab-notebook","google-colab-notebooks","google-colab-tutorial","google-colaboratory","google-colaboratory-notebooks"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/demining.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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":"2022-02-17T18:04:12.000Z","updated_at":"2024-08-12T20:20:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"8acf09bd-4d39-40ec-ab9a-d90730e7ed49","html_url":"https://github.com/demining/bitcoin-ruby-Google-Colab","commit_stats":{"total_commits":1080,"total_committers":71,"mean_commits":"15.211267605633802","dds":0.5953703703703703,"last_synced_commit":"932a80734fb4220b51b54512f33dfd173775b9ba"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demining%2Fbitcoin-ruby-Google-Colab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demining%2Fbitcoin-ruby-Google-Colab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demining%2Fbitcoin-ruby-Google-Colab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demining%2Fbitcoin-ruby-Google-Colab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/demining","download_url":"https://codeload.github.com/demining/bitcoin-ruby-Google-Colab/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571340,"owners_count":21126516,"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":["bitcoin","bitcoin-api","bitcoin-core","bitcoin-payment","bitcoin-transaction","bitcoin-wallet","colab","colab-notebook","colab-notebooks","colab-tutorial","colaboratory","google-colab","google-colab-notebook","google-colab-notebooks","google-colab-tutorial","google-colaboratory","google-colaboratory-notebooks"],"created_at":"2024-09-24T14:01:21.613Z","updated_at":"2025-04-12T12:50:58.040Z","avatar_url":"https://github.com/demining.png","language":"Ruby","readme":"\n-------------------------\n### Run bitcoin-ruby-Google-Colab\n\nhttps://colab.research.google.com/drive/1OShIMVcFZ_khsUIBOIV1lzrqAGo1gfm_?usp=sharing\n\n-------------------------\n\nThis is a ruby library for interacting with the bitcoin protocol/network.\n\nSome of the main features are:\n\n* Bitcoin::Key provides a high-level API for creating and handling keys/addresses\n* Bitcoin::Util provides the basic bitcoin utility functions for base58, ECC, etc.\n* Bitcoin::Protocol can parse/create all protocol messages\n* Bitcoin::Script implementation, create/run scripts and verify signatures\n* Bitcoin::Builder provides a high-level API for creating transactions (and blocks)\n* Bitcoin::Litecoin implements all the litecoin-specific differences\n\n== Compatible with...\n\n* ruby 2.4.x\n* ruby 2.5.x\n* ruby 2.6.x\n\n== Installation\n\n gem install bitcoin-ruby\n # OR\n git clone https://github.com/lian/bitcoin-ruby.git; cd bitcoin-ruby; bundle install\n\nNote that some aspects of the library (such as networking, storage, etc.) need\nadditional dependencies which are not specified in the gemspec. The core requirements are\nintentionally kept to a minimum, so nobody has to install unneeded dependencies.\n\n* +rspec+ to run the specs\n* +scrypt+ to use a much faster scrypt hash implementation for Litecoin\n\nIf you would like to install using Bundler, put it in your Gemfile and run bundle install\n gem 'bitcoin-ruby', git: 'https://github.com/lian/bitcoin-ruby', branch: 'master', require: 'bitcoin'\n\n== Library Usage\n\nThere are different aspects to the library which can be used separately or in combination.\nHere are some ideas of what you could do. There are also some demo scripts in examples/,\nsee EXAMPLES.\n\n=== Keys/Addresses\n\nGenerate a Bitcoin::Key\n\n key = Bitcoin::Key.generate\n key.priv\n key.pub\n key.addr\n sig = key.sign(\"data\")\n key.verify(\"data\", sig)\n recovered_key = Bitcoin::Key.from_base58(key.to_base58)\n\n=== Blocks / Transactions parsing\n\nParse a Bitcoin::Protocol::Block\n\n raw_block = File.open('spec/bitcoin/fixtures/rawblock-0.bin', 'rb') {|f| f.read}\n blk = Bitcoin::Protocol::Block.new(raw_block)\n blk.hash #=\u003e 00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048\n blk.tx.count #=\u003e 1\n blk.to_hash #=\u003e ...\n Bitcoin::Protocol::Block.from_json( blk.to_json )\n\nParse a Bitcoin::Protocol::Tx\n\n raw_tx = File.open('spec/bitcoin/fixtures/rawtx-01.bin', 'rb') {|f| f.read}\n tx = Bitcoin::Protocol::Tx.new(raw_tx)\n tx.hash #=\u003e 6e9dd16625b62cfcd4bf02edb89ca1f5a8c30c4b1601507090fb28e59f2d02b4\n tx.in.size #=\u003e 1\n tx.out.size #=\u003e 2\n tx.to_hash #=\u003e ...\n Bitcoin::Protocol::Tx.from_json( tx.to_json )\n\n Bitcoin::Script.new(tx.out[0].pk_script).to_string\n #=\u003e \"OP_DUP OP_HASH160 b2e21c1db922e3bdc529de7b38b4c401399e9afd OP_EQUALVERIFY OP_CHECKSIG\"\n\n=== Transaction verification / Scripts\n\nGet the matching transactions (in this example tx1 is the spending transaction)\n\n rawtx1 = File.open(\"spec/bitcoin/fixtures/rawtx-f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16.bin\", 'rb') {|f| f.read}\n rawtx2 = File.open(\"spec/bitcoin/fixtures/rawtx-0437cd7f8525ceed2324359c2d0ba26006d92d856a9c20fa0241106ee5a597c9.bin\", 'rb') {|f| f.read}\n tx1 = Bitcoin::Protocol::Tx.new(rawtx1)\n tx2 = Bitcoin::Protocol::Tx.new(rawtx2)\n\nThen simply ask the transaction to verify an input\n\n tx1.verify_input_signature(0, tx2) #=\u003e true\n\n=== Scripts\n\nIf you want to control the Bitcoin::Script yourself, you can do so\n\n txin = tx1.in.first\n txout = tx2.out[txin.prev_out_index]\n script = Bitcoin::Script.new(txin.script_sig + txout.pk_script)\n\n result = script.run do |pubkey, sig, hash_type|\n   hash = tx1.signature_hash_for_input(0, nil, txout.pk_script)\n   Bitcoin.verify_signature(hash, sig, pubkey.unpack(\"H*\")[0])\n end\n result #=\u003e true\n\n=== Create Transactions\n\nYou need to know the previous output you want to spend (tx hash and output index),\nas well as the private key for the address required to sign for it.\n\n # use testnet so you don't accidentally blow your whole money!\n Bitcoin.network = :testnet3\n \n # make the DSL methods available in your scope\n include Bitcoin::Builder\n \n # the previous transaction that has an output to your address\n prev_hash = \"6c44b284c20fa22bd69c57a9dbff91fb71deddc8c54fb2f5aa41fc78c96c1ad1\"\n \n # the number of the output you want to use\n prev_out_index = 0\n \n # fetch the tx from whereever you like and parse it\n prev_tx = Bitcoin::P::Tx.from_json(open(\"http://test.webbtc.com/tx/#{prev_hash}.json\"))\n \n # the key needed to sign an input that spends the previous output\n key = Bitcoin::Key.from_base58(\"92ZRu28m2GHSKaaF2W7RswJ2iJYpTzVhBaN6ZLs7TENCs4b7ML8\")\n \n # create a new transaction (and sign the inputs)\n new_tx = build_tx do |t|\n \n   # add the input you picked out earlier\n   t.input do |i|\n     i.prev_out prev_tx\n     i.prev_out_index prev_out_index\n     i.signature_key key\n   end\n \n   # add an output that sends some bitcoins to another address\n   t.output do |o|\n     o.value 50000000 # 0.5 BTC in satoshis\n     o.script {|s| s.recipient \"mugwYJ1sKyr8EDDgXtoh8sdDQuNWKYNf88\" }\n   end\n \n   # add another output spending the remaining amount back to yourself\n   # if you want to pay a tx fee, reduce the value of this output accordingly\n   # if you want to keep your financial history private, use a different address\n   t.output do |o|\n     o.value 49000000 # 0.49 BTC, leave 0.01 BTC as fee\n     o.script {|s| s.recipient key.addr }\n   end\n \n end\n \n # examine your transaction. you can relay it through http://test.webbtc.com/relay_tx\n # that will also give you a hint on the error if something goes wrong\n puts new_tx.to_json\n\n== Documentation\n\nAlways trying to improve, any help appreciated! If anything is unclear to you, let us know!\n\nDocumentation is generated using yardoc:\n\n rake doc\n\nThe specs are also a good place to see how something works.\n\n== Specs\n\nSpecs require libsecp256k1 in order to be fully run. Therefore, the first step\nin running the specs is to build this library if you haven't already:\n\n  rake build_libsecp256k1\n\nThe majority of specs can be run with\n\n rake rspec\n\nor, if you want to run a single spec\n\n bundle exec rspec spec/bitcoin/bitcoin_spec.rb\n\nIf you make changes to the code or add functionality, please also add specs.\n\nTo run specs for changes that monkey patch significant functionality, you\nshould run the specs individually. For example, to run the Dogecoin specs:\n\n  rake coin_spec[dogecoin]\n\nIf support is added for any new coins a corresponding coin spec should also be\nadded to test specific functionality of that coin.\n\n== Development\n\nAny help or feedback is greatly appreciated! From getting knee-deep into elliptic-curve acrobatics,\nto cleaning up high-level naming conventions, there is something for everyone to do.\nEven if you are completely lost, just pointing out what is unclear helps a lot!\n\nIf you are curious or like to participate in development, drop by \\#bitcoin-ruby on irc.freenode.net!\n\n\n----\n\n|  | Donation Address |\n| --- | --- |\n| ♥ __BTC__ | 1Lw2kh9WzCActXSGHxyypGLkqQZfxDpw8v |\n| ♥ __ETH__ | 0xaBd66CF90898517573f19184b3297d651f7b90bf |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemining%2Fbitcoin-ruby-google-colab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdemining%2Fbitcoin-ruby-google-colab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemining%2Fbitcoin-ruby-google-colab/lists"}