Sha256: afb69e6bec1f15a71e77bf526e573401bcc5df93bb85343efed85ccb212c5475

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

#!/usr/bin/env ruby

# This is an example of using the raw xdr objects to post a transaction
# notice that we must manually hash/sign the structures and we must manually
# fill out all the fields. 
#
# Look at mid_level_transaction_post.rb to see a friendlier form

require 'rbnacl'
require 'stellar-base'
require 'faraday'
require 'digest/sha2'

master      = RbNaCl::SigningKey.new("allmylifemyhearthasbeensearching")
destination = RbNaCl::SigningKey.new("allmylifemyhearthasbeensearching")

tx            = Stellar::Transaction.new
tx.account    = master.verify_key.to_bytes
tx.max_fee    = 1000
tx.seq_num    = 1
tx.max_ledger = 1000
tx.min_ledger = 0

payment = Stellar::PaymentOp.new
payment.destination = destination.verify_key.to_bytes
payment.currency = Stellar::Currency.new(:native)
payment.path = []
payment.amount = 200_000000
payment.send_max = 200_000000
payment.source_memo = ""
payment.memo = ""

op = Stellar::Operation.new
op.body = Stellar::Operation::Body.new(:payment, payment)

tx.operations = [op]

raw       = tx.to_xdr
tx_hash   = Digest::SHA256.digest raw
signature = master.sign(tx_hash)

env = Stellar::TransactionEnvelope.new
env.tx = tx
env.signatures = [Stellar::DecoratedSignature.new({
  hint:master.verify_key.to_bytes[0...4], 
  signature:signature
})]

env_hex = env.to_xdr.unpack("H*").first

result = Faraday.get('http://localhost:39132/tx', blob: env_hex)
puts result.body

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
stellar-base-0.0.6 examples/low_level_transaction_post.rb
stellar-base-0.0.5 examples/low_level_transaction_post.rb
stellar-base-0.0.4 examples/low_level_transaction_post.rb
stellar-base-0.0.3 examples/low_level_transaction_post.rb
stellar-base-0.0.2 examples/low_level_transaction_post.rb
stellar-base-0.0.1 examples/low_level_transaction_post.rb