Class: Etherlite::Account::PrivateKey
- Defined in:
- lib/etherlite/account/private_key.rb
Instance Attribute Summary
Attributes inherited from Base
#connection, #normalized_address
Instance Method Summary collapse
-
#initialize(_connection, _pk) ⇒ PrivateKey
constructor
A new instance of PrivateKey.
- #send_transaction(_options = {}) ⇒ Object
Methods inherited from Base
#==, #call, #next_nonce, #transfer_to
Methods included from Etherlite::Api::Address
Constructor Details
#initialize(_connection, _pk) ⇒ PrivateKey
Returns a new instance of PrivateKey.
6 7 8 9 |
# File 'lib/etherlite/account/private_key.rb', line 6 def initialize(_connection, _pk) @key = Eth::Key.new priv: _pk super _connection, Etherlite::Utils.normalize_address(@key.address) end |
Instance Method Details
#send_transaction(_options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/etherlite/account/private_key.rb', line 11 def send_transaction( = {}) = .slice(:replace, :nonce) nonce_manager.with_next_nonce_for(normalized_address, ) do |nonce| tx = Eth::Tx.new( value: .fetch(:value, 0), data: .fetch(:data, ''), gas_limit: .fetch(:gas, 90_000), gas_price: .fetch(:gas_price, gas_price), to: (Etherlite::Utils.encode_address_param([:to]) if .key?(:to)), nonce: nonce ) # Since eth gem does not allow configuration of chains for every tx, we need # to globally configure it before signing. This is not thread safe so a mutex is needed. sign_with_connection_chain tx Etherlite::Transaction.new @connection, @connection.eth_send_raw_transaction(tx.hex) end end |