eth-rb 0.1.3 → 0.1.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eth.rb +12 -9
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8dbe26f555f0a514a50fa207168790fc634c91ec6d2a22b04a0728867baa20d
4
- data.tar.gz: 409b0054a7c75ef99b748218374fc3f62343217f1b7f8b07e187289275b0f3cf
3
+ metadata.gz: 6406b8a909ffa800ee2ca237fd58b97fa5c07602aec7db483bc93aed5e50c1a4
4
+ data.tar.gz: 649564b79457d90806d0c31127c2a24953497c4679384ed71284a30b5b4b8093
5
5
  SHA512:
6
- metadata.gz: 7201eeaa0a133fc2630705f0dc7bd653aeef35fd26e3c87219a2825273244708ae2dba2a393762acc69362255691ed712d066a2d83b1ac43acbf2c80effb17ee
7
- data.tar.gz: 4d5a98d0be06e0212b9e3408f325d01c06d9b0a539c1ebcd48e432d38ededc48c893bff66c8216babed2f037788042b5459ea25104e4d49daa49c689dcd2d683
6
+ metadata.gz: 771b14da3a273e6f25da6b2e65eb0b2838b3fd23122cd716c801463eaf838c41862d1115a5a7ca556d517f6ad5a343d2a6bdf111d78e93c72dfd5226921cf753
7
+ data.tar.gz: 94cf8b5447f44c1c04128b7881838351ef19c349084cf5504572eb3d11280b5586a1640e69acec3cf8b8983f37948969abd5ab19bc570325b3477068eb067943
data/lib/eth.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env ruby
1
2
  # frozen_string_literal: true
2
3
 
3
4
  # eth.rb — Ethereum blockchain queries via Alchemy JSON-RPC
@@ -8,7 +9,7 @@
8
9
  # ./eth.rb --price — show current ETH/USD price
9
10
  # ./eth.rb --version or -v — show version
10
11
  # ./eth.rb send <key> <to> <amount> — send ETH (amount in ETH)
11
- # ./eth.rb send <key> <to> $<amount> — send ETH (amount in USD, converted at current price)
12
+ # ./eth.rb send <key> <to> \$<amount> — send ETH (amount in USD, converted at current price)
12
13
  # ./eth.rb --help — show this usage info
13
14
 
14
15
  require "net/http"
@@ -21,7 +22,7 @@ require "digest/keccak"
21
22
  ALCHEMY_URL = "https://eth-mainnet.g.alchemy.com/v2/alch_PhpVkmsabZhYV69otj1rF"
22
23
  COINGECKO_URL = "https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"
23
24
  CHAIN_ID = 1 # Ethereum mainnet
24
- VERSION = "0.1.3"
25
+ VERSION = "0.1.5"
25
26
 
26
27
  # ── JSON-RPC ────────────────────────────────────────────────────────────────
27
28
 
@@ -144,7 +145,9 @@ def private_key_to_address(priv_hex)
144
145
  end
145
146
 
146
147
  def normalize_hex(str)
147
- str.start_with?("0x") || str.start_with?("0X") ? str[2..] : str
148
+ hex = str.start_with?("0x") || str.start_with?("0X") ? str[2..] : str
149
+ hex = "0#{hex}" if hex.bytesize.odd?
150
+ hex
148
151
  end
149
152
 
150
153
  # ── Transaction signing ─────────────────────────────────────────────────────
@@ -217,19 +220,16 @@ def build_and_sign_tx(private_key_hex, to_address, amount_wei)
217
220
 
218
221
  v = 35 + CHAIN_ID * 2 + rec_id
219
222
 
220
- # RLP-encode r, s as 32-byte big-endian
221
- pad32 = ->(b) { b.bytesize >= 32 ? b : "\x00" * (32 - b.bytesize) + b }
222
- r_bytes = pad32.call(to_big_endian(low_sig.r))
223
- s_bytes = pad32.call(to_big_endian(s))
224
-
225
223
  # Signed transaction: rlp([nonce, gp, gl, to, value, data, v, r, s])
226
- tx_list = [nonce, gas_price, gas_limit, to_bytes, value, data, v, r_bytes, s_bytes]
224
+ # r and s are encoded as integers (not padded byte strings) per Ethereum spec
225
+ tx_list = [nonce, gas_price, gas_limit, to_bytes, value, data, v, low_sig.r, s]
227
226
  rlp_encode(tx_list)
228
227
  end
229
228
 
230
229
  # ── Send command ────────────────────────────────────────────────────────────
231
230
 
232
231
  def cmd_send(args)
232
+ # p args
233
233
  if args.length < 3
234
234
  puts "Usage: ./eth.rb send <private_key_hex> <to_address> <amount>"
235
235
  puts " amount: number (ETH) or $number (USD, converted to ETH at current price)"
@@ -239,6 +239,7 @@ def cmd_send(args)
239
239
  private_key = args[0]
240
240
  to_address = args[1]
241
241
  raw_amount = args[2]
242
+ exit if raw_amount.to_f == 0 && raw_amount[1..].to_f == 0
242
243
 
243
244
  # Parse amount: $X → USD, otherwise treat as ETH
244
245
  if raw_amount.start_with?("$")
@@ -251,6 +252,7 @@ def cmd_send(args)
251
252
  end
252
253
 
253
254
  amount_wei = (eth_amount * 1_000_000_000_000_000_000).to_i
255
+ # puts "Wei: #{amount_wei}"
254
256
 
255
257
  puts "Building and signing transaction..."
256
258
  signed_tx = build_and_sign_tx(private_key, to_address, amount_wei)
@@ -342,4 +344,5 @@ def run_cli(args)
342
344
  end
343
345
  end
344
346
 
347
+ # p ARGV
345
348
  run_cli(ARGV) if __FILE__ == $0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eth-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khalid Shaikh