SubstrateClient
Deprecated, the client was merged into https://github.com/itering/scale.rb
This is a library of interfaces for communicating with Substrate nodes. It provides application developers the ability to query a node and interact with the Substrate chains using Ruby.
Installation
Add this line to your application's Gemfile:
gem 'substrate_client'And then execute:
$ bundle
Or install it yourself as:
$ gem install substrate_client
Usage
Supported rpc methods
require "substrate_client"
client = SubstrateClient.new("wss://kusama-rpc.polkadot.io/")
client.methodsreturns like:
[
"account_nextIndex",
"author_hasKey",
...
"chain_getBlock",
"chain_getBlockHash",
...
]The rpc methods can be dynamically called by its name, so you can call it like:
client.chain_getBlockHash(1024)Origin rpc methods
account_nextIndex
author_hasKeyauthor_hasSessionKeysauthor_insertKeyauthor_pendingExtrinsicsauthor_removeExtrinsicauthor_rotateKeysauthor_submitExtrinsicbabe_epochAuthorshipchain_getBlock(block_hash = nil)chain_getBlockHash(block_id)chain_getFinalisedHeadchain_getFinalizedHeadchain_getHeadchain_getHeader(block_hash = nil)chain_getRuntimeVersion(block_hash = nil)childstate_getKeyschildstate_getStoragechildstate_getStorageHashchildstate_getStorageSizegrandpa_roundStateoffchain_localStorageGetoffchain_localStorageSetpayment_queryInfostate_callstate_callAtstate_getKeysstate_getKeysPagedstate_getKeysPagedAtstate_getMetadata(block_hash = nil)state_getPairsstate_getReadProofstate_getRuntimeVersionstate_getStorage(storage_key, block_hash = nil)state_getStorageAtstate_getStorageHashstate_getStorageHashAtstate_getStorageSizestate_getStorageSizeAtstate_queryStoragestate_queryStorageAtsystem_accountNextIndexsystem_addReservedPeersystem_chainsystem_chainTypesystem_dryRunsystem_dryRunAtsystem_healthsystem_localListenAddressessystem_localPeerIdsystem_namesystem_networkStatesystem_nodeRolessystem_peerssystem_propertiessystem_removeReservedPeer
system_version
Wrap methods
These methods will encode the parameters and decode the returned data
-
get_block_number(block_hash) -
get_metadata(block_hash) -
get_block(block_hash=nil) -
get_block_events(block_hash) -
get_storage(module_name, storage_name, params = nil, block_hash = nil)client.get_storage("Balances", "TotalIssuance", nil, nil) client.get_storage("System", "Account", ["0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"], nil) client.get_storage("ImOnline", "AuthoredBlocks", [2818, "0x749ddc93a65dfec3af27cc7478212cb7d4b0c0357fef35a0163966ab5333b757"], nil)
-
compose_call(module_name, call_name, params, block_hash=nil)client.compose_call "Balances", "Transfer", { dest: "0x586cb27c291c813ce74e86a60dad270609abf2fc8bee107e44a80ac00225c409", value: 1_000_000_000_000 }, nil
Docker
-
update to latest image
docker pull itering/substrate_client:latest -
Run image:
docker run -it itering/substrate_client:latestThis will enter the container with a linux shell opened.
/usr/src/app # -
Type
rspecto run all tests/usr/src/app # rspec ................... Finished in 0.00883 seconds (files took 0.09656 seconds to load) 5 examples, 0 failures
-
Or, type
./bin/consoleto enter the ruby interactive environment and run any decode or encode code/usr/src/app # ./bin/console [1] pry(main)> client = SubstrateClient.new("wss://kusama-rpc.polkadot.io/") => #<SubstrateClient:0x000055a78f124f58 ... [2] pry(main)> client.methods => ... [3] pry(main)> client.chain_getHead => "0xb3c3a220d4639b7c62f179f534b3a66336a115ebc18f13db053f0c57437c45fc"
Development
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.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/substrate_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the SubstrateClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.