pycoin icon indicating copy to clipboard operation
pycoin copied to clipboard

Cannot import name spendables_for_address

Open Alkhara opened this issue 6 years ago • 2 comments

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 from pycoin.services.blockchain_info import spendables_for_address ImportError: cannot import name spendables_for_address

I have pycoin installed and it works for generating addresses and keys, not sure if I am missing a dependency or something.

Thanks

Alkhara avatar Sep 03 '17 16:09 Alkhara

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.

Alkhara avatar Sep 03 '17 16:09 Alkhara

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.

skaravind avatar Feb 24 '18 15:02 skaravind

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.

richardkiss avatar Feb 16 '23 19:02 richardkiss