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

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)
| improve this answer | |
  • Using bundle as input to prepare_transfer indeed works, however according to the api (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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.