Sha256: 86a8259a4da68c0eaa7917fd324f86baf14f2502a22bbcebb690377acdb3f574

Contents?: true

Size: 785 Bytes

Versions: 11

Compression:

Stored size: 785 Bytes

Contents

module Klaytn
  class Wallet < Client
    BASE_URL = 'https://api-cypress-v2.scope.klaytn.com/v2/accounts'.freeze
    PEB_DIVISOR = 1000000000000000000.freeze # friendly 'get_balance' result, ex: "5" == 5 KLAY

    attr_reader :divisor

    # no params needed, overrides Klaytn::Client
    def initialize(peb_divisor: true)
      @divisor = peb_divisor ? PEB_DIVISOR : 1
    end

    def get(address)
      resp = HTTParty.get(BASE_URL + "/#{address}", headers: headers)
      data = JSON.parse(resp.body)
    rescue => e
      raise e.message
    end

    def get_balance(address)
      data = get(address)
      data.dig('result', 'balance').to_f / divisor
    rescue => e
      raise e.message
    end

    def headers
      { origin: 'https://scope.klaytn.com' }
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
klaytn-0.1.2 lib/klaytn/wallet.rb
klaytn-0.1.1 lib/klaytn/wallet.rb
klaytn-0.1.0 lib/klaytn/wallet.rb
klaytn-0.0.9 lib/klaytn/wallet.rb
klaytn-0.0.8 lib/klaytn/wallet.rb
klaytn-0.0.7 lib/klaytn/wallet.rb
klaytn-0.0.6 lib/klaytn/wallet.rb
klaytn-0.0.5 lib/klaytn/wallet.rb
klaytn-0.0.4 lib/klaytn/wallet.rb
klaytn-0.0.3 lib/klaytn/wallet.rb
klaytn-0.0.2 lib/klaytn/wallet.rb