send bitcoin url over nfc


SUBMITTED BY: Guest

DATE: Nov. 18, 2013, 9:02 p.m.

FORMAT: Text only

SIZE: 948 Bytes

HITS: 889

  1. import nfc, nfc.snep
  2. import threading
  3. import argparse
  4. def send_uri(llc, uri):
  5. snep = nfc.snep.SnepClient(llc)
  6. snep.put(nfc.ndef.Message(nfc.ndef.UriRecord(uri)))
  7. class Main(object):
  8. def __init__(self):
  9. parser = argparse.ArgumentParser()
  10. parser.add_argument("address", help="bitcoin receiver address")
  11. parser.add_argument("amount", type=float, help="amount to send")
  12. args = parser.parse_args()
  13. self.uri = "bitcoin:{address}?amount={amount}".format(
  14. address=args.address, amount=args.amount)
  15. def on_connect(self, llc):
  16. threading.Thread(target=send_uri, args=(llc, self.uri)).start()
  17. return llc
  18. def run(self):
  19. clf = nfc.ContactlessFrontend('usb')
  20. clf.connect(llcp={'on-connect': self.on_connect})
  21. if __name__ == '__main__':
  22. Main().run()

comments powered by Disqus