TezosClient

Maintainability

Build Status

Tezos Client interracts with tezos nodes using RPC commands.

Requirements:

Tezos client requires liquidity to be installed in order to work properly. For installing on linux, you can basically follow the steps coded in travis-script folder.

Installation

Add this line to your application's Gemfile:

gem 'tezos_client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tezos_client

Usage

Generate Tezos key paris

Generate a prefectly 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"
#    }

Transfer funds

client = TezosClient.new 

client.transfer(
    amount: 1,
    from: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
    to: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
    secret_key: "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN"
)

Call a contract

client = TezosClient.new  
client.transfer(
    amount: 5,
    from: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
    to: "KT1MZTrMDPB42P9yvjf7Cy8Lkjxjj4jetbCt",
    secret_key: "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN",
    parameters: '"pro"'
)

Originate a contract written in liquidity

script = File.expand_path("./spec/fixtures/demo.liq")
source = "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq"
secret_key = "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN"
amount =  0
init_params = '"test"'
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]}"

Call a contract written in liquidity

TezosClient.new.call_contract(
  from: "tz1ZWiiPXowuhN1UqNGVTrgNyf5tdxp4XUUq",
  amount: 0,
  script: File.expand_path("./spec/fixtures/demo.liq"),
  secret_key: "edsk4EcqupPmaebat5mP57ZQ3zo8NDkwv8vQmafdYZyeXxrSc72pjN",
  to: "KT1STzq9p2tfW3K4RdoM9iYd1htJ4QcJ8Njs",
  parameters: [ "manage", "(Some { destination = tz1YLtLqD1fWHthSVHPD116oYvsd4PTAHUoc; amount = 1tz })" ]
)

Options

Liquidity options

TezosClient.new(..., liquidity_options: { options... })

Available options :

  • verbose (boolean) : enable verbose mode of Liquidity commands.

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]/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.

License

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

Code of Conduct

Everyone interacting in the TezosClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.