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
- #build_raw_transaction(_options = {}) ⇒ Object
-
#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.to_s) end |
Instance Method Details
#build_raw_transaction(_options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/etherlite/account/private_key.rb', line 11 def build_raw_transaction( = {}) nonce = nonce_manager.next_nonce_for(normalized_address, **.slice(:replace, :nonce)) tx = Eth::Tx.new( chain_id: @connection.chain_id, 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 ) tx.sign @key tx end |
#send_transaction(_options = {}) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/etherlite/account/private_key.rb', line 28 def send_transaction( = {}) tx = build_raw_transaction() nonce_manager.with_next_nonce_for(normalized_address, nonce: tx.signer_nonce) do |_| Etherlite::Transaction.new @connection, @connection.eth_send_raw_transaction("0x#{tx.hex}") end end |