Last active
February 27, 2018 14:51
-
-
Save hm0429/5781f1b83e8bfb05ceaf6f7b062fecfe to your computer and use it in GitHub Desktop.
generate Ethereum address by Ruby
This file contains hidden or 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 'openssl' | |
require 'base16' | |
require 'digest/sha3' | |
def eth_address(public_key) | |
s = public_key[2, 128] | |
s.downcase! | |
s = Base16.decode16(s) | |
h = Digest::SHA3.hexdigest(s, 256) | |
a = '0x' + h[-40..-1] | |
return a | |
end | |
ec = OpenSSL::PKey::EC.new('secp256k1') | |
ec.generate_key | |
public_key = ec.public_key.to_bn.to_s(16) | |
private_key = ec.private_key.to_s(16) | |
eth_address = eth_address(public_key) | |
puts "address: #{eth_address}" | |
puts "private_key: #{private_key}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/piyolab/playground/blob/master/ethereum_ruby/ethereum_address_generator.rb