eth-rb 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/eth.rb +23 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7cad4ab46c86f240e38bf48d77832f0c067582133d1bbdb4e1690cd5b52afa77
|
|
4
|
+
data.tar.gz: 54bafb01cd2fa6c8cf5dbbd50ec9e1831de9b1aee9dbc2a1b8c6a96eb59a113c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c851f58edc21271766a2e9da90a14a47b90cde4ef48bcd9d99f0a178e7c4c5b9b74f3776e8c6660d5b477d38690c288ccff584c3839e27549ab6fc51c72dcde
|
|
7
|
+
data.tar.gz: ccc8efb8c5b74378088eca855d613320049a5abdaa7efe52f20847fb784928a653399a5b0f0ffce2f000afb884e0acb74709255b2e35730dfcd8892a4cf5a4ff
|
data/lib/eth.rb
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
# Usage:
|
|
7
7
|
# ./eth.rb — show latest block number
|
|
8
8
|
# ./eth.rb <address> — show ETH balance of <address>
|
|
9
|
+
# ./eth.rb <private_key> — derive public key + address, show its balance
|
|
9
10
|
# ./eth.rb --price — show current ETH/USD price
|
|
10
11
|
# ./eth.rb --genkey or -g — generate a new private key + address
|
|
11
12
|
# ./eth.rb --pubkey <key> — derive public key + address from <key>
|
|
@@ -24,7 +25,7 @@ require "digest/keccak"
|
|
|
24
25
|
ALCHEMY_URL = "https://eth-mainnet.g.alchemy.com/v2/alch_PhpVkmsabZhYV69otj1rF"
|
|
25
26
|
COINGECKO_URL = "https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"
|
|
26
27
|
CHAIN_ID = 1 # Ethereum mainnet
|
|
27
|
-
VERSION = "0.1.
|
|
28
|
+
VERSION = "0.1.8"
|
|
28
29
|
|
|
29
30
|
# ── JSON-RPC ────────────────────────────────────────────────────────────────
|
|
30
31
|
|
|
@@ -314,6 +315,22 @@ def show_block_number
|
|
|
314
315
|
puts "Hex: #{hex_block}"
|
|
315
316
|
end
|
|
316
317
|
|
|
318
|
+
# True if str is a 64-hex-digit private key (0x prefix optional)
|
|
319
|
+
def private_key?(str)
|
|
320
|
+
normalize_hex(str).match?(/\A[0-9a-fA-F]{64}\z/)
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Derive the public key and address from a private key, then show the balance
|
|
324
|
+
def show_balance_from_key(priv_hex)
|
|
325
|
+
pub_hex = "0x#{private_key_to_pubkey(priv_hex).unpack1('H*')}"
|
|
326
|
+
addr = "0x#{private_key_to_address(priv_hex).unpack1('H*')}"
|
|
327
|
+
|
|
328
|
+
puts "Public Key: #{pub_hex}"
|
|
329
|
+
puts "Address: #{addr}"
|
|
330
|
+
puts ""
|
|
331
|
+
show_balance(addr)
|
|
332
|
+
end
|
|
333
|
+
|
|
317
334
|
def show_balance(address)
|
|
318
335
|
hex_wei = rpc_call("eth_getBalance", [address, "latest"])
|
|
319
336
|
wei = hex_wei.to_i(16)
|
|
@@ -387,7 +404,11 @@ def run_cli(args)
|
|
|
387
404
|
elsif args[0] == "--send" || args[0] == "send"
|
|
388
405
|
cmd_send(args[1..])
|
|
389
406
|
else
|
|
390
|
-
|
|
407
|
+
if private_key?(args[0])
|
|
408
|
+
show_balance_from_key(args[0])
|
|
409
|
+
else
|
|
410
|
+
show_balance(args[0])
|
|
411
|
+
end
|
|
391
412
|
end
|
|
392
413
|
end
|
|
393
414
|
|