Project

laksa

0.01
No release in over 3 years
Low commit activity in last 3 years
LaksaRuby -- Zilliqa Blockchain Library
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Laksa

Laksa -- Zilliqa Blockchain Ruby Library

The project is still under development.

Requirement

Ruby(2.5.3)

Installation

Add this line to your application's Gemfile:

gem 'laksa'

And then execute:

$ bundle

Or install it yourself as:

$ gem install laksa

Usage

Generate A new address

private_key = Laksa::Crypto::KeyTool.generate_private_key
public_key = Laksa::Crypto::KeyTool.get_public_key_from_private_key(private_key)
address = Laksa::Crypto::KeyTool.get_address_from_private_key(private_key)

Validate an address

address = '2624B9EA4B1CD740630F6BF2FEA82AAC0067070B'
Laksa::Util::Validator.address?(address)

Validate checksum address

checksum_address = '0x4BAF5faDA8e5Db92C3d3242618c5B47133AE003C'
Laksa::Util::Validator.checksum_address?(checksum_address)

Deploy and Call a transaction

private_key = "e19d05c5452598e24caad4a0d85a49146f7be089515c905ae6a19e8a578a6930"

provider = Laksa::Jsonrpc::Provider.new('https://dev-api.zilliqa.com')
wallet = Laksa::Account::Wallet.new(provider)
address = wallet.add_by_private_key(private_key)

factory = Laksa::Contract::ContractFactory.new(provider, wallet)

contract = factory.new_contract(TEST_CONTRACT, [
  {
    vname: 'owner',
    type: 'ByStr20',
    value: '0x124567890124567890124567890124567890',
  },
],
ABI,
)

deploy_params = Laksa::Contract::DeployParams.new(nil, Laksa::Util.pack(8, 8), nil, 1000, 1000, nil)
tx, deployed = contract.deploy(deploy_params)    

assert tx.confirmed?
assert deployed.deployed?
assert_equal Laksa::Contract::ContractStatus::DEPLOYED, deployed.status

assert /[A-F0-9]+/ =~ contract.address

# call a deployed contract
call_tx = deployed.call(
      'setHello',
      [
        { vname: 'msg', type: 'String', value: 'Hello World!' },
      ],
      {
        version: Laksa::Util.pack(8, 8),
        amount: 0,
        gasPrice: 1000,
        gasLimit: 1000
      })


receipt = call_tx.tx_params.receipt

the definition of TEST_CONTRACT and ABI can be found in this folder.