Class: Klaytn::Client

Inherits:
Base
  • Object
show all
Defined in:
lib/klaytn/client.rb

Direct Known Subclasses

Contract, JsonRpc, Token, Transaction, Wallet

Constant Summary

Constants inherited from Base

Base::FUNCTION_NOT_FOUND, Base::INVALID_CLIENT, Base::MISSING_ABI, Base::MISSING_ACCOUNT_POOL_KRN, Base::MISSING_ACCOUNT_WALLET, Base::MISSING_CONTRACT, Base::MISSING_JSONRPC_METHOD, Base::MISSING_KAS_CREDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.

Raises:



5
6
7
8
9
10
11
12
# File 'lib/klaytn/client.rb', line 5

def initialize(opts = {})
  raise INVALID_CLIENT if opts == {}

  @contract_address = opts[:contract_address]
  @chain_id = setup_chain_id(opts)
  @headers = Authentication.new.headers(chain_id)
  @basic_auth = setup_basic_auth(opts)
end

Instance Attribute Details

#basic_authObject (readonly)

Returns the value of attribute basic_auth.



3
4
5
# File 'lib/klaytn/client.rb', line 3

def basic_auth
  @basic_auth
end

#chain_idObject (readonly)

Returns the value of attribute chain_id.



3
4
5
# File 'lib/klaytn/client.rb', line 3

def chain_id
  @chain_id
end

#contract_addressObject (readonly)

Returns the value of attribute contract_address.



3
4
5
# File 'lib/klaytn/client.rb', line 3

def contract_address
  @contract_address
end

#headersObject (readonly)

Returns the value of attribute headers.



3
4
5
# File 'lib/klaytn/client.rb', line 3

def headers
  @headers
end

Instance Method Details

#setup_basic_auth(opts) ⇒ Object

Raises:



18
19
20
21
# File 'lib/klaytn/client.rb', line 18

def setup_basic_auth(opts)
  raise MISSING_KAS_CREDS unless opts[:kas_access_key].present? && opts[:kas_secret_access_key].present?
  Authentication.new.auth_params(opts[:kas_access_key], opts[:kas_secret_access_key])
end

#setup_chain_id(opts) ⇒ Object



14
15
16
# File 'lib/klaytn/client.rb', line 14

def setup_chain_id(opts)
  opts[:chain_id] || 1001 # default to baobab testnet
end