3

I am trying to construct a simple transaction: prepare_transfer should get as input transfers: Iterable[ProposedTransaction], and two other optional parameters.

How could one make an Iterable out of a ProposedTransaction object? Is there somewhere a simple working example of using this basic prepare_transfer function? Thanks

Nir
  • 177
  • 5

1 Answers1

2

prepare_transfer needs an Iterable because IOTA transfers are bundles: A collection of input, output and 0-value transactions. An Iterable of ProposedTransactions is for example a ProposedBundle.

Example

from iota import Iota, ProposedTransaction, ProposedBundle, Address, Tag, TryteString
api = Iota('http://yournode.net:14265',seed = b'SEED9GOES9HERE')

output = ProposedTransaction( # receiving address of the transfer address = Address( b'ADDRESS9GOES9HERE99999999999999999999999999999999999TESTVALUE9DONTUSEINPRODUCTION' ),

# Amount of Iota you want to send
value = 1,

# Optional Tag (27-trytes)
tag = Tag(b'HELLO9WORLD'),

# Message (2187-trytes)
message = TryteString.from_string('Hello world!')
)

bundle = ProposedBundle()

bundle.add_transaction(output)

prepared_bundle = api.prepare_transfer(bundle)

Zauz
  • 4,454
  • 15
  • 42
  • Using bundle as input to prepare_transfer indeed works, however according to the api (https://pyota.readthedocs.io/en/latest/api.html#prepare-transfer), I would have expected that ProposedTransaction would be ok, too. – Nir Jan 15 '18 at 15:54
  • 1
    I havent tried it, but just passing a list with ProposedTransactions like this: api.prepare_transfer([output]) will probably work as well. – Zauz Jan 15 '18 at 15:57