Tezos Client interacts with Tezos nodes using RPC commands.
Tezos client requires SmartPy to be installed in order to work properly. To install it on Linux, you can basically follow the steps coded in travis-script folder.
sudo apt-get install nodejs
npm i -g michelson-to-micheline
sh <(curl -s https://smartpy.io/releases/20210317-bc925bb73dc885ac2b4dde9689e805d9b0bc6125/cli/install.sh)
export PATH=$PATH:$HOME/smartpy-cli/
npm install -g typescript
Add this line to your application's Gemfile:
gem "tezos_client"
And then execute:
$ bundle
Or install it yourself as:
$ gem install tezos_client
Generate a perfectly random key pair:
client = TezosClient.new
key = subject.generate_key
expect(key[:address]).to eq "tz1RfnzRopJXH32SSDap2wMYGULBAnmHxdP1"
# => {
# secret_key: "edsk4T2fHv5RLL3VSXHz82SQiyFx7vZ4wwtA2u67AvAaw5yqNEvuU2",
# public_key: "edpkuncp7KSVhV57Qg7odwhMFcnAHnNrMppbitBPKBfvdg6fFVeNjr",
# address: "tz1a97x7GAvMDyrwwKTLQo131CoidXyUef48"
# }
Generate a key pair from a seed and a BIP 44 Path:
key = subject.generate_key(wallet_seed: "000102030405060708090a0b0c0d0e0f", path: "m/44'/1729'/0'/0'/0'")
expect(key[:address]).to eq "tz1RfnzRopJXH32SSDap2wMYGULBAnmHxdP1"
# => {
# secret_key: "edsk4T2fHv5RLL3VSXHz82SQiyFx7vZ4wwtA2u67AvAaw5yqNEvuU2",
# public_key: "edpkuncp7KSVhV57Qg7odwhMFcnAHnNrMppbitBPKBfvdg6fFVeNjr",
# address: "tz1a97x7GAvMDyrwwKTLQo131CoidXyUef48"
# }
Generate a key pair from a BIP-39 mnemonic sentence and a BIP 44 Path:
key = subject.generate_key(
mnemonic: "below dove cushion divide future artefact orange congress maple fiscal flower enable",
path: "m/44'/1729'/0'/0'/0'")
expect(key[:address]).to eq "tz1RfnzRopJXH32SSDap2wMYGULBAnmHxdP1"
# => {
# secret_key: "edsk4T2fHv5RLL3VSXHz82SQiyFx7vZ4wwtA2u67AvAaw5yqNEvuU2",
# public_key: "edpkuncp7KSVhV57Qg7odwhMFcnAHnNrMppbitBPKBfvdg6fFVeNjr",
# address: "tz1a97x7GAvMDyrwwKTLQo131CoidXyUef48"
# }
client = TezosClient.new
client.transfer(
amount: 1,
from: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
to: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
secret_key: "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN"
)
client = TezosClient.new
client.transfer(
amount: 5,
from: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
to: "KT1MZTrMDPB42P9yvjf7Cy8Lkjxjj4jetbCt",
secret_key: "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN",
parameters: '"pro"'
)
script = File.expand_path("./spec/fixtures/demo.py")
source = "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq"
secret_key = "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN"
amount = 0
init_params = "MyContract()"
client = TezosClient.new
res = client.originate_contract(
from: source,
amount: amount,
script: script,
secret_key: secret_key,
init_params: init_params
)
puts "Origination operation: #{res[:operation_id]}"
puts "Contract address: #{res[:originated_contract]}"
TezosClient.new.call_contract(
from: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
secret_key: "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN",
to: "KT1STzq9p2tfW3K4RdoM9iYd1htJ4QcJ8Njs",
amount: 0,
entrypoint: "myEntryPoint",
params: { int: 1 },
params_type: :micheline
)
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.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tezos_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.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the TezosClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.