Last active
March 7, 2019 15:55
-
-
Save fuyuton/3378ccba3bfba82adc1678e8ee0e5574 to your computer and use it in GitHub Desktop.
send ethereum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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