pycoin
pycoin copied to clipboard
Cannot import name spendables_for_address
Hello,
I am working off of https://21.co/learn/embedding-data-blockchain-op-return/#creating-and-sending-the-transaction which uses pycoin. When attempting the send-op-return.py script I get:
Traceback (most recent call last):
File "send-op-return.py", line 3, in
I have pycoin installed and it works for generating addresses and keys, not sure if I am missing a dependency or something.
Thanks
In /pycoin/services/blockchain_info.py I can see the lines:
def spendables_for_address(self, bitcoin_address):
"""
Return a list of Spendable objects for the
given bitcoin address.
"""
URL = "https://blockchain.info/unspent?active=%s" % bitcoin_address
r = json.loads(urlopen(URL).read().decode("utf8"))
spendables = []
for u in r["unspent_outputs"]:
coin_value = u["value"]
script = h2b(u["script"])
previous_hash = h2b(u["tx_hash"])
previous_index = u["tx_output_n"]
spendables.append(Spendable(coin_value, script, previous_hash, previous_index))
return spendables
Which makes me think I do have the needed code on my machine, not sure why it won't import.
The spendables_for_adress in blockchain_info.py is inside a class BlockchainInfoProvider
So you have to import BlockchainInfoProvider and then write the code "BlockchainInfoProvider.spendables_for_address" to call the function.
I'm assuming this is just a misunderstanding, so I'm going to close it. Feel free to reopen with more info if you still need help.