{"id":13834632,"url":"https://github.com/zh/rbanano","last_synced_at":"2025-05-15T14:30:55.233Z","repository":{"id":48691856,"uuid":"273876050","full_name":"zh/rbanano","owner":"zh","description":"Ruby library for working with Banano currency","archived":false,"fork":false,"pushed_at":"2021-07-14T01:34:56.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-25T00:39:10.162Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-21T09:50:32.000Z","updated_at":"2021-07-14T01:34:52.000Z","dependencies_parsed_at":"2022-09-08T08:11:27.995Z","dependency_job_id":null,"html_url":"https://github.com/zh/rbanano","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zh%2Frbanano","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zh%2Frbanano/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zh%2Frbanano/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zh%2Frbanano/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zh","download_url":"https://codeload.github.com/zh/rbanano/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254358548,"owners_count":22057939,"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-08-04T14:00:48.650Z","updated_at":"2025-05-15T14:30:55.198Z","avatar_url":"https://github.com/zh.png","language":"Ruby","funding_links":[],"categories":["Client Libraries"],"sub_categories":["Ruby"],"readme":"# Banano\n\nThe current Gem trying to make as easy as possible working with [Banano currency](https://banano.cc/).\nMore information about the Banano currency networking can be found on the [Banano Currency Wiki pages](https://github.com/BananoCoin/banano/wiki/Network-Specifications).\nThe current library is still work in progress, but the basic functionallity is already implemented:\n\n- Good part of the RPC protocol for working with Banano nodes\n- Wallet, Account operations - send and receive payments etc.\n- Conversion between units - RAW to Banano and Banano to RAW\n\nSome parts of the library are heavily influenced by the great [nanook Ruby library](https://github.com/lukes/nanook) for working with the similar [NANO currency](https://nano.org/en/).\n\nEverybody is welcome to contrubute to the project. Have fun and use Ruby and Banano.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'banano'\n```\n\nAnd then execute:\n\n```sh\nbundle install\n```\n\nOr install it yourself as:\n\n```sh\ngem install banano\n```\n\n## Usage\n\nThe code is divided on following the parts:\n\n- `Banano::Protocol` - including all other parts. Can be used also for some syntax sugar (to avoid sending node parameter to constructors)\n- `Banano::Client` - very thin wrapper around [Faraday HTTP Client](https://github.com/lostisland/faraday) for easy JSON-based communications\n- `Banano::Node` - Banano Node abstraction - mostly encapsulate JSON communications\n- `Banano::Wallet` - wallets holding for Banano accounts on the current node\n- `Banano::Account` - uniq 'ban_...' addresses used for currency tokens exchange\n- `Banano::WalletAccount` - link between `Account` and `Wallet` - check if account exists in the wallet etc.\n- `Banano::Key` - account key management\n- `Banano::Block` - low level work with individual blocks\n- `Banano::WorkPeer` - do work on peers\n- `Banano::Unit` - conversion between [RAW and Banano units](https://nanoo.tools/banano-units)\n\n### Banano::Protocol\n\nUsually everything starts here. By default the library will work with [locally running Banano node](https://github.com/BananoCoin/banano/wiki/Running-a-Docker-Bananode).\nIf it is impossible to be done, you can use the [Public bananode RPC API](https://nanoo.tools/bananode-api). Example below is for that case:\n\n```rb\nBETA_URL = 'https://api-beta.banano.cc'\n@banano = Banano::Protocol.new(uri: BETA_URL)\n# From here it is easy to create other object, without sending URI to them\nwallet = @banano.wallet('WALLET15263636...')\naccount = @banano.account('ban_1...')\n```\n\n### Banano::Client\n\nNot used directly, better use `Banano::Node` instead\n\n```rb\nclient = Banano::Client.new(uri: BETA_URL)\nclient.rpc_call(action: :version)\n```\n\n### Banano::Node\n\nMost of the information about the running node is encapsulated here. The other parts using  mostly the `Banano::Node.rpc()` method, not the low level client one:\n\n```rb\nBanano::Node.account_count # number of node accounts\nBanano::Node.block_count   # check here if there are still non-syncronized blocks\nBanano::Node.peers         # other nodes connected to that one\n# accounts with voting power\nBanano::Node.representatives\nBanano::Node.representatives_online\n# Is your node synced already\nBanano::Node.synchronizing_blocks\nBanano::Node.sync_progress\n```\n\n### Banano::Wallet\n\nWallets are like a bags of accounts. Accounts can be only local, created on the current node. They will not be visible for other nodes.\n\n```rb\nwallet = Banano::Wallet.create   # create new wallet\nwallet.restore(seed: 'XVVREGNN...') # restore some wallet and its accounts\nwallet.accounts                  # current wellet accounts\nwallet.contains?('ban_1...')     # check if the account exists in the current wallet\nwallet.export                    # export wallet to JSON\nwallet.destroy                   # remove the wallet\n# Accounts with voting power\nwallet.default_representative\nwallet.change_default_representative('ban_1...')\n# Security\nwallet.change_password('SomePassword')   # protect your wallet\nwallet.lock                              # no more payments\nwallet.locked?\nwallet.unlock('SomePassword')            # resume receiving payments\n# Payments\nblock_id = wallet.pay(from: 'ban_1...', to: 'ban_3...', amount: '1.23', raw: false, id: 'x123')\nwallet.pending(limit: 10, detailed: true)  # waiting payments (does not work well unless enable_control = true)\nwallet.receive(into: 'ban_1', block: block_id)  # receive the pending banano into some wallet account\nwallet.balance                           # check how many banano the whole wallet have, RAW units\nwallet.balance(raw: false)               # wallet balance in Banano units\nwallet.balance(account_break_down: true) # banano per acount, RAW units\n```\n\n### Banano::Account\n\nAccount are holding units with unique address, where the banano tokens are accumulated. They can be local for the current node and not accessable for other nodes.\n\n```rb\naccount = Banano::Account(node: @banano.node, address: 'ban1_...')  # create new account on that node\naccount.exists?   # check if account exists\n# some account attributes\naccount.last_modified_at\naccount.public_key\naccount.representative\naccount.balance             # in RAW units\naccount.balance(raw: false)  # in banano units\n# Payments\naccount.pending(limit: 100, detailed: true)  # detailed information about the pending payments\naccount.history(limit: 10)  # the latest payments - send and receive\n```\n\n### Banano::WalletAccount\n\nBecause accounts and wallets so closly connected, some linkage object is very helpful.\n\n```rb\nwallet = @banano.wallet('XBHHNN...')\n# create wallet \u003c-\u003e accounts connection\nwallet_acc = Banano::WalletAccount(node: @banano.node, wallet: wallet.id)\nwallet_acc.create     # create new account in the wallet\nwallet_acc.create(3)  # create additional 3 accounts inside the same wallet\n# Working with specific account\naccount = @banano.account('ban_1')\nwallet_other_acc = Banano::WalletAccount(node: @banano.node, wallet: wallet.id, account: account.id)\nblock_id = wallet_other_acc.pay(to: 'ban_1...', amount: 10, raw: false, id: 'x1234')  # send some banano\nwallet_other_acc.receive(block_id)   # receive some banano\n\n```\n\n### Banano::Key\n\nMost of the information is identicat with the [NANO currency docs](https://docs.nano.org/integration-guides/key-management/).\n\n```rb\nkey_builder = @banano.key    # create new key (still unpopulated, cannot be used)\nkey_builder.generate         # generate private, public key and account address\n{:private=\u003e\"43E6B...\",\n :public=\u003e\"7EBC0C...\",\n :account=\u003e\"ban_1zow3...\"}\nSEED = 'ABF56EBB...'         # Random seed\nkey_builder.generate(seed: SEED, index: 0)    # will always generate SAME pair of keys and address\nkey_builder.generate(seed: SEED, index: 1)\nnew_builder = @banano.key(saved_private_key)  # generate keys from saved private key\nnew_builder.expand                            # return private, public key and account address\n```\n\n### Banano::WorkPeer\n\nDelegate block validating work to some network peers:\n\n```rb\nwork = Banano::WorkPeer(@banano.node)\nwork.add(address: '::ffff:1.2.3.4', port: '7071')  # add peer to the work flow\nwork.list  # list of working peers\nwork.clear # remove all peers\n```\n\n### Banano::Block\n\nBlocks, also known as transactions are the building items of the banano network.\nEvery block have uniq ID, which can be used for processing the block\n\n```rb\nblock = Banano::Block(node: @banano.node, block: 'F1B7EDB1...')\nblock.account           # account associated with the block\nblock.successors(limit: 10)\nblock.chain(limit: 10)  # also 'block.ancestors' - blocks chain, leading to the current one\nblock.history           # more detailed chain history\nblock.info              # information about the block\nblock.confirm           # block confirmation from the online representatives\nwork = block.generate_work(use_peers: true) # start some work\nblock.is_valid_work?(work) # check if the work done is valid\nblock.cancel_work       # stop generating work for block\nblock.pending?          # is the block in pending state. not work very well...\nblock.publish('send')   # dependes what kind of block is this: 'send', 'receive' etc.\n```\n\n### Banano::Unit\n\nUsing [Ruby bigdecimal library](https://apidock.com/ruby/BigDecimal) for all operations:\n\n```rb\nBanano::Unit.ban_to_raw(1)    # -\u003e BigDecimal('100000000000000000000000000000')\nBanano::Unit.raw_to_ban('1')  # -\u003e BigDecimal('0.00000000000000000000000000001')\n```\n\nThe library also is checking some currency related limits, for example total supply limit: `3402823669.20938463463374607431768211455` banano max\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nClone the gem source code and start experimenting:\n\n```sh\ngit clone https://github.com/zh/rbanano\n```\n\n`rspec` is used for testing. To run all tests execute:\n\n```sh\nbundle exec rspec spec\n```\n\nStill a lot of tests needed. For now `Banano::Unit` and `Banano:Util` are ready. The other parts tests will be added soon.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at [https://github.com/zh/rbanano](https://github.com/zh/rbanano).\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzh%2Frbanano","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzh%2Frbanano","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzh%2Frbanano/lists"}