astroband / ruby-stellar-base

The stellar-base library is the lowest-level stellar helper library. It consists of classes to read, write, hash, and sign the xdr structures that are used in stellar-core
Apache License 2.0
21 stars 19 forks source link

The transaction failed when submitted to the stellar network #30

Closed LDS1 closed 6 years ago

LDS1 commented 6 years ago

What am I doing wrong? (Using version 0.11.0)

    hot_account_keypair = Stellar::KeyPair.from_raw_seed(raw_seed)
    recipient_keypair = Stellar::KeyPair.from_address(to) #random address here
    amount = [:native, amount.to_f]

    payment = Stellar::Transaction.payment({
      account:     hot_account_keypair,
      destination: recipient_keypair,
      sequence:    hot_account_next_sequence,
      amount:      amount,
      memo:        command.to_i
    })

    tx_blob = payment.to_envelope(hot_account_keypair).to_xdr(:base64)

    submit(tx_blob) # POST to https://horizon.stellar.org/transactions

Horizon replies with:

tx_bad_auth
LDS1 commented 6 years ago

I should be using Stellar.default_network = network_passphrase before script, it's on testnet by default.

steveklebanoff commented 6 years ago

@LDS1 -- what do you use for the network_passphrase value for https://horizon.stellar.org ?

steveklebanoff commented 6 years ago

OK, figured it out:

# This uses Stellar::Client from https://github.com/stellar/ruby-stellar-sdk
stellar_client = (
  if use_testnet
    Stellar.default_network = Stellar::Networks::TESTNET
    Stellar::Client.default_testnet
  else
    Stellar.default_network = Stellar::Networks::PUBLIC
    Stellar::Client.default
  end
)

@LDS1 you are a life saver. I was stumped on this and this github issue saved me. thank you!