Skip to content

Instantly share code, notes, and snippets.

@fuyuton fuyuton/send_eth.rb
Last active Mar 7, 2019

Embed
What would you like to do?
send ethereum
require 'ethereum'
host = "host address"
port = "port number"
client = Ethereum::HttpClient.new(host, port)
formatter = Ethereum::Formatter.new
#eth.accounts
res = client.accounts
addr_list = res['result']
addr_list.each do |addr|
#web3.from_wei(eth.getBalance(account), "ether")
res = client.get_balance(addr, 'latest')
vol = res['result']
puts "#{addr}: #{vol}, #{formatter.from_wei(vol.hex)}"
end
send_vol = 1 #unit: ether
wei = formatter.to_wei(send_vol)
vol_hex = formatter.to_twos_complement(wei)
wei_hex = "0x#{vol_hex}"
#p wei
#p wei_hex
from_addr = addr[0]
to_addr = addr[1]
#p from_addr
#p to_addr
#personal.unlockAccount
password = 'from_addr password'
res = client.unlock_account(from_addr, password)
p res
#eth.sendTransaction
res = client.send_transaction("from" => from_addr, "to" => to_addr, "value" => wei_hex)
p res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.