Class: IOSTSdk::Http::SendTx

Inherits:
Object
  • Object
show all
Defined in:
lib/iost_sdk/http/send_tx.rb

Instance Method Summary collapse

Instance Method Details

#invoke(base_url:, transaction:, account_name:, key_pair:) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/iost_sdk/http/send_tx.rb', line 9

def invoke(base_url:, transaction:, account_name:, key_pair:)
  # sign the transaction first
  signed_txn = IOSTSdk::Models::Query::SignedTransaction.from_transaction(transaction: transaction)
  final_txn = signed_txn.sign(account_name: , key_pair: key_pair)

  resp = HTTParty.post(
    "#{base_url}/sendTx",
    body: JSON.generate(final_txn.raw_data),
    headers: { 'Content-Type' => 'application/json' }
  )
  raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
    resp.code == 200

  JSON.parse(resp.body)
end