Class: Paleth::Web3

Inherits:
Object
  • Object
show all
Includes:
Liar
Defined in:
lib/paleth/web3.rb

Overview

Main Paleth class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Liar

#make_promise

Constructor Details

#initialize(web3) ⇒ Web3

Initialize a Paleth:Web3 instance using a javascript `Web3` instance. You shouldn't call this directly but use `Paleth.make` insteat


20
21
22
# File 'lib/paleth/web3.rb', line 20

def initialize(web3)
  @web3 = web3
end

Instance Attribute Details

#web3Object (readonly)

Returns the value of attribute web3


17
18
19
# File 'lib/paleth/web3.rb', line 17

def web3
  @web3
end

Instance Method Details

#api_versionObject


24
25
26
# File 'lib/paleth/web3.rb', line 24

def api_version
  web3.JS[:version].JS[:api]
end

#connected?Boolean

Check if a connection to a node exists

Returns:

  • (Boolean)

49
50
51
# File 'lib/paleth/web3.rb', line 49

def connected?
  web3.JS.isConnected
end

#db(name) ⇒ Object


85
86
87
# File 'lib/paleth/web3.rb', line 85

def db(name)
  Paleth::Db.new(self, name)
end

#ethObject


77
78
79
# File 'lib/paleth/web3.rb', line 77

def eth
  @eth ||= Paleth::Eth.new(self)
end

#ethereum_versionObject


36
37
38
# File 'lib/paleth/web3.rb', line 36

def ethereum_version
  version(:ethereum)
end

#netObject


73
74
75
# File 'lib/paleth/web3.rb', line 73

def net
  @net ||= Paleth::Net.new(self)
end

#network_versionObject


40
41
42
# File 'lib/paleth/web3.rb', line 40

def network_version
  version(:network)
end

#node_versionObject


32
33
34
# File 'lib/paleth/web3.rb', line 32

def node_version
  version(:node)
end

#personalObject


81
82
83
# File 'lib/paleth/web3.rb', line 81

def personal
  @personal = Paleth::Personal.new(self)
end

#providerObject

Return the current instance provider


54
55
56
# File 'lib/paleth/web3.rb', line 54

def provider
  web3.JS.currentProvider
end

#provider=(new_provider) ⇒ Object

Replace the current instance provider


59
60
61
62
# File 'lib/paleth/web3.rb', line 59

def provider=(new_provider)
  web3.JS.setProvider(new_provider)
  provider
end

#reset!(keep_is_syncing = false) ⇒ Object

Should be called to reset state of web3. Resets everything except manager. Uninstalls all filters. Stops polling.

  • keep_is_syncing : If true it will uninstall all filters, but will keep the web3.eth.isSyncing() polls


69
70
71
# File 'lib/paleth/web3.rb', line 69

def reset!(keep_is_syncing = false)
  web3.JS.reset(keep_is_syncing)
end

#version(item) ⇒ Object


28
29
30
# File 'lib/paleth/web3.rb', line 28

def version(item)
  make_promise(web3.JS[:version], "get#{item.capitalize}")
end

#whisper_versionObject


44
45
46
# File 'lib/paleth/web3.rb', line 44

def whisper_version
  version(:whisper)
end