- Zilliqa API doc
- The project is still under development.
- Ruby(2.5.3)
Add this line to your application's Gemfile:
gem 'zilliqa'
And then execute:
$ bundle
Or install it yourself as:
$ gem install zilliqa
private_key = Zilliqa::Crypto::KeyTool.generate_private_key
public_key = Zilliqa::Crypto::KeyTool.get_public_key_from_private_key(private_key)
address = Zilliqa::Crypto::KeyTool.get_address_from_private_key(private_key)
address = '2624B9EA4B1CD740630F6BF2FEA82AAC0067070B'
Zilliqa::Util::Validator.address?(address)
checksum_address = '0x4BAF5faDA8e5Db92C3d3242618c5B47133AE003C'
Zilliqa::Util::Validator.checksum_address?(checksum_address)
provider = Zilliqa::Jsonrpc::Provider.new('https://dev-api.zilliqa.com')
to_addr = 'zil1lpw9fc8p4tse55r85fa37gscnkxf6xq5ahe8uj'
pub_key = '032cfec301c57acc2a4b18f47247687a1ec51e61336a7d5936e455b7dab3ae712e'
testnet = 21_823_489
tx_params = {
version: testnet,
amount: '0',
to_addr: to_addr,
gas_price: '1000',
gas_limit: 1,
sender_pub_key: pub_key
}
wallet = Zilliqa::Account::Wallet.new(provider)
transaction = Zilliqa::Account::Transaction.new(tx_params, provider)
wallet.add_by_private_key(private_key)
tx = wallet.sign(transaction)
tx.submit!
provider = Zilliqa::Jsonrpc::Provider.new('https://dev-api.zilliqa.com')
wallet = Zilliqa::Account::Wallet.new(provider)
wallet.add_by_private_key(private_key)
wallet.transfer('zil1lpw9fc8p4tse55r85fa37gscnkxf6xq5ahe8uj', 10 ** 12)
Successfull output
{
"ContractAddress"=>"1e366b36e5a17dec83c46f19d8d6b43434bd1dbb",
"Info"=>"Contract Creation txn, sent to shard",
"TranID"=>"411c1108800ac85118fcd9a44568d208276dcbdd5287c99119c69167912f344a"
}
private_key = "e19d05c5452598..."
provider = Zilliqa::Jsonrpc::Provider.new('https://dev-api.zilliqa.com')
wallet = Zilliqa::Account::Wallet.new(provider)
address = wallet.add_by_private_key(private_key)
factory = Zilliqa::Contract::ContractFactory.new(provider, wallet)
contract = factory.new_contract(TEST_CONTRACT, [
{
vname: 'owner',
type: 'ByStr20',
value: '0x124567890124567890124567890124567890',
},
],
ABI,
)
gas_limit = TEST_CONTRACT.bytes.size + ABI.to_s.bytes.size
gas_price = 10 ** 12 # 1 zil
testnet_ver = 21_823_489
pub_key = '032cfec301...'
deploy_params = Zilliqa::Contract::DeployParams.new(nil, testnet_ver, nil, gas_price, gas_limit, pub_key)
tx, deployed = contract.deploy(deploy_params)
assert tx.confirmed?
assert deployed.deployed?
assert_equal Zilliqa::Contract::CONTRACT_STATUSES[: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: Zilliqa::Util.pack(8, 8),
amount: 0,
gasPrice: 1000,
gasLimit: 1000
})
receipt = call_tx.receipt