4

This is a follow-up question to What does the ATTACH TO TANGLE button do?

When using the js-/Python-API, I assume that you have to specify the receive address as the target of the 0-value transaction.

The question is, with the API, which address do I use as the source?

Is it OK to reuse a source address for attachments? Let's say I choose the address of index 1000 as the source address for attachments, and never ever transfer any value to it, so that I don't care if it does get compromised when I use it to attach several target addresses to the tangle. Is this a bad idea? Or can I use an arbitrary source address, like the 9999...-address?

How does the wallet do it?

2 Answers 2

3

Unlike other systems like Bitcoin, IOTA transactions do not distinguish between source and destination addresses. Every transaction in a bundle has exactly one address. If the transaction value is negative, it is considered a spending transaction and the address is considered a source address (and it will need a signature of the bundle hash). If the transaction value is zero or positive, the address is considered a destination address (and no signature is needed). The sum of all the values in a bundle has to be zero. So when sending a zero-value transaction, this transaction alone is a valid bundle (and only has a destination address). When there is a positive value transaction, there has to be another negative-value transaction in the same bundle which is a spending transaction.

High-level API functions like sendTransfer will automatically check if the value is non-zero and find appropriate input transactions (and maybe a change transaction). When using low-level API functions, you are responsible for crafting your bundle yourself. In that case, just do not include any spending transactions in your bundle if all you want to do is attach an address to the tangle.

1
  • Ok, thanks, I think I succeeded with it. So basically api.attach_to_tangle is not to be used here, but api.send_transfer.
    – Daniel F
    Commented Feb 7, 2018 at 4:03
2

The following Python code can be used to attach an address to the tangle

import time

from iota import Iota
from iota import Address
from iota import ProposedTransaction

''' both work, with and without checksum '''
address = 'KO9CVYUHZSZGHCXSRXDHBTT9U9WUJROIBSRNYKUBXOWONSGKIEHBOXBPKVG9FCHFCJ9QZQTRBYTESRQLCEGNFPFEVD'
address = 'KO9CVYUHZSZGHCXSRXDHBTT9U9WUJROIBSRNYKUBXOWONSGKIEHBOXBPKVG9FCHFCJ9QZQTRBYTESRQLC'

api = Iota('http://localhost:14123/', '') # no seed required

start = time.time()
result = api.send_transfer(
  depth = 6,
  transfers = [
    ProposedTransaction(
      address = Address(address),
      value = 0,
    ),
  ],
)
stop = time.time()

print ''
if 'bundle' in result:
  print 'ok'
  print ''
  print 'attached address', address
  print 'with transaction', str(result['bundle'].transactions[-1].hash)
  print '       in bundle', str(result['bundle'].hash)
  print '          within', round(stop - start, 1), 'seconds'
else:
  print 'probably failed'
print ''

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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