Skip to content
CITA library for the Ruby language
Branch: develop
Clone or download
classicalliu Merge pull request #31 from cryptape/support-v2-tx
feat: add support for transaction v2
Latest commit 925625e May 22, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
cita-proto @ 6c11e06
lib feat: add support for transaction v2 May 22, 2019
secp256k1 @ 1e6f1f5 add secp256k1 as submodule & and to .travis.yml Sep 29, 2018
spec feat: add support for transaction v2 May 22, 2019
.gitignore
.gitmodules
.pryrc add rubocop Oct 8, 2018
.rspec init project Sep 28, 2018
.rubocop.yml Rename to cita-sdk Jan 11, 2019
.travis.yml
CODE_OF_CONDUCT.md init project Sep 28, 2018
Gemfile Rename to cita-sdk Jan 11, 2019
Gemfile.lock feat: add support for transaction v2 May 22, 2019
LICENSE.txt
README.md
Rakefile init project Sep 28, 2018
cita.gemspec Support ruby 2.6 Mar 4, 2019

README.md

cita-sdk-ruby

Build Status Documentation

CITA Ruby SDK

Installation

Add this line to your application's Gemfile:

gem 'cita-sdk-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cita-sdk-ruby

Usage

See keccak256, to_hex and other utils methods in CITA::Utils module

RPC calls RPC list

cita = CITA::Client.new("your url")

cita.rpc.block_number
cita.rpc.get_block_by_number("0x0", true)
# or
cita.rpc.getBlockByNumber("0x0", true) 

sign and unsign

# make a Transaction object first
transaction = CITA::Transaction.new(
  to: "8ff0f5b85fba9a6429e2e256880291774f8e224f",
  nonce: "e4f195c409fe47c58a624de37c730679",
  quota: 30000,
  valid_until_block: 1882078,
  data: "",
  value: "0x3e8",
  chain_id: "1",
  version: 1
)

# sign transaction with your private key
content = CITA::TransactionSigner.encode(transaction, "you private key")

# you can unsign content by `decode` method
CITA::TransactionSigner.decode(content) 
# you can set `recover` to false if you don't want to recover from address and public key
CITA::TransactionSigner.decode(content, recover: false)

send transaction

cita.rpc.send_transaction(transaction, private_key)

transfer tokens

cita.rpc.transfer(to: "to address", value: 1000, private_key: "your private key")

contract

contract = cita.contract_at(abi, contract_address)
# for RPC call (constant functions)
response = contract.call_func(method: :symbol)
# for RPC sendTransaction
response = contract.send_func(tx: tx, private_key: private_key, method: :transfer, params: [address, tokens])

CHANGELOG

v0.24.0

  • support transaction version = 2
  • set default transaction version to 2

v0.23.0

  • add getVersion and peersInfo RPC methods

v0.22.0

  • support CITA v0.22

v0.21.0

  • add recover option for decode transaction, for CITA v0.21 provide from in getTransaction rpc call
  • rename protobuf Crypto enum

v0.20.0

  • rename to cita-sdk-ruby
  • rename top module name to CITA

v0.2

  • supports CITA 0.20 and 0.19
  • set default transaction version to 1
  • update TransactionSinger.decode output type to hash with symbol keys
  • parse TransactionSinger.decode hash value to hex string if it's bytes.

v0.1

  • supports CITA 0.19

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/cryptape/cita-sdk-ruby. 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 cita-sdk-ruby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

You can’t perform that action at this time.