Rspec Tests codecov Maintainability Gem Downloads GitHub license

Hyperledger Fabric Gateway gRPC SDK generated directly from protos found at: https://github.com/hyperledger/fabric-protos.


Add this line to your application's Gemfile:

gem 'fabric-gateway'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install fabric-gateway


Note, there is an issue with the grpc library for MacOS (https://github.com/grpc/grpc/issues/28271). It results in a segfault in ruby when trying to make a connection.

Workaround: Either run on linux or use a docker container as a workaround.

Will update to new version of grpc when fix is released.


This is an alpha stage library suitable for early adopters. The basic evaluate and submit gateway functions are implemented. Chaincode events monitoring is not yet implemented.

$ bin/console

# for running in application or script; not needed from bin/console
require 'fabric' 

def load_certs
  data_dir ='/your/certs/directory' # aka test-network/organizations
  files = [
  files.map { |f| File.open(File.join(data_dir, f)).read }

# needed if you are connecting via a different dns name or IP address
client_opts = {
  channel_args: {
    GRPC::Core::Channel::SSL_TARGET => 'peer0.org1.example.com'
# optional, if you want to set deadlines to the individual calls (in seconds)
default_call_options = {
  endorse_options: { deadline: GRPC::Core::TimeConsts.from_relative_time(5) },
  evaluate_options: { deadline: GRPC::Core::TimeConsts.from_relative_time(5) },
  submit_options: { deadline: GRPC::Core::TimeConsts.from_relative_time(5) },
  commit_status_options: { deadline: GRPC::Core::TimeConsts.from_relative_time(5) },
  chaincode_events_options: { deadline: GRPC::Core::TimeConsts.from_relative_time(60) }
creds = GRPC::Core::ChannelCredentials.new(load_certs[0])
client=Fabric::Client.new('localhost:7051', creds, default_call_options: default_call_options, **client_opts)

identity = Fabric::Gateway::Identity.new(
    msp_id: 'Org1MSP',
    private_key: Fabric::Gateway.crypto_suite.key_from_pem(load_certs[1]),
    pem_certificate: load_certs[2],

gateway = identity.new_gateway(client)
network = gateway.new_network('my_channel')
contract = network.new_contract('basic')

# Evaluate
puts contract.evaluate_transaction('GetAllAssets')

# Submit
puts contract.submit_transaction('CreateAsset', ['asset13', 'yellow', '5', 'Tom', '1300'])
puts contract.submit_transaction('UpdateAsset', %w[asset999 yellow 5 Tom 5555])

# Chaincode Events - Not Yet Implemented!

Please refer to the full reference documentation for complete usage information.


After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

To rebuild the proto code, run the regenerate script:

$ bin/regenerate

Effort has been made to follow the design patterns and naming convention where possible from the official Hyperledger Fabric Gateway SDK while at the same time producing an idiomatic ruby gem. Our intention is to produce a gem that would be compatible with the documentation of the official SDK while natural to use for a seasoned ruby developer.

Development References & Resources

These are the libraries and knowledge necessary for developing this gem:


Bug reports and pull requests are welcome on GitHub at https://github.com/ethicalidentity/fabric-gateway. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.



  • [x] Add license
  • [x] Add ChangeLog
  • [x] Create Gem
  • [x] Add testing & CI/CD
  • [x] Add rubocop and linting
  • [x] Add usage instructions
  • [x] Setup auto-generation of API docs on rubydoc.info
  • [x] Abstract connection and calls such that the protos aren't being interacted directly
  • [x] Implement, Document & Test Evaluate
  • [x] Implement, Document & Test Endorse
  • [x] Implement, Document & Test Submit
  • [x] Implement, Document & Test CommitStatus
  • [ ] Implement, Document & Test ChaincodeEvents
  • [ ] Support Submit Async (currently blocks waiting for the transaction to be committed)
  • [ ] Consider adding error handling, invalid transaction proposals will result in random GRPC::FailedPrecondition type errors
  • [ ] Consider adding transaction_id information to Fabric::Errors that are raised; would help a lot for debugging.
  • [ ] Consider adding integration tests against blockchain; might be a ton of stuff to setup
  • [ ] Implement off-line signing - https://github.com/hyperledger/fabric-gateway/blob/1e4a926ddb98ec8ee969da3fc1500642ab389d01/node/src/contract.ts#L63
  • [ ] Support for offline transaction signing (write scenario test for this) - https://github.com/hyperledger/fabric-gateway/blob/cf78fc11a439ced7dfd2f9b55886c55c73119b25/pkg/client/offlinesign_test.go


The gem is available as open source under the terms of the MIT License.

Portions of the code are from https://github.com/kirshin/hyperledger-fabric-sdk.

Code of Conduct

Everyone interacting in the Fabric::Gateway project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.