blockcypher / blockcypher-python Goto Github PK
View Code? Open in Web Editor NEWPython library for the BlockCypher web services
Home Page: https://www.blockcypher.com/dev/bitcoin
License: Apache License 2.0
Python library for the BlockCypher web services
Home Page: https://www.blockcypher.com/dev/bitcoin
License: Apache License 2.0
Hello, I have sent a support request related to a held or interrupted transaction. I have not received a response and hoped to have assistance to correct this error befor the fork. Does the support team of blockcypher respond to clients/ members.
This is main reference, i try to use simple_send()
i try to navigate at callbacks, and see that it always error on this place, because method ecdsa_raw_verify(), always get tuple type (None, Int, Int), and we get in v None always, and then compare it between 27 and 34
Sir i was told you already my address are correct i was send you already a screenshot of coinbase sending payment then why you don't solve my problem and unstuck my money i hope you will solve my problem soon as possible
LPTeFL5ALEP9xV9NdqUdb1fYXtEHaQM7tR
See my pybitcointools code, which did away with manually setting testnet
for all cases (blockhash, address, utxo txid) except pushtx
Or, at the most basic, IMO a global flag should be able to be set, which is trivial. The conventions for btc/main
/ btc/test3
/ etc may seem straightforward, but IMO it is cumbersome
How can we resend the results of webhook again manually
Must be a .rst file instead
Error: blockcypher 1.0.73 has requirement requests==2.4.3, but you'll have requests 2.5.2 which is incompatible.
I can't downgrade requests as other libraries (like docker) are dependant on 2.5.2
Im getting an assertion error when I try most of the functions. In python 2.7.6
blockcypher.get_num_confirmed_transactions('1BTCorgHwCg6u2YSAWKgS17qUad6kHmtQW')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/JC/src/blockcypher/blockcypher/api.py", line 202, in get_num_confirmed_transactions
coin_symbol=coin_symbol)['n_tx']
File "/Users/JC/src/blockcypher/blockcypher/api.py", line 154, in get_address_overview
coin_symbol=coin_symbol)
AssertionError
I'm running into an issue when using the python module vs using requests.get(https://api.blockcypher/...)
When checking an address via requests, if the address is invalid a dict item is still returned.
{"error": "Address <invalid_address> is invalid: Address <invalid address> is of unknown size."}
When using the module, an assertion error is thrown for get_address_details() that will crash the script.
>>> response = blockcypher.get_address_details("<invalid addr>")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\X\AppData\Local\Programs\Python\Python38-32\lib\site-packages\blockcypher\api.py", line 122, in get_address_details
assert is_valid_address_for_coinsymbol(
AssertionError: <invalid addr>
This is rather inconvenient when iterating over a list of several addresses, if one happens to have a typo, be invalid etc. Would be easy to handle if the same dict["error"] was returned as in first example.
Please forgive if there's something simple I'm missing here.
Genrating address in python gives the warning with the response. is it right to use the response address for further processing? The api and response is given below:
blockcypher.generate_new_address(api_key='b68a3087d11b4285b041564d26bda061')
Generating private key details server-side. You really should do this client-side. See https://github.com/sbuss/bitmerchant for an example.
{u'wif': u'L2fVHT7uz8ZnWcopKTeQouyHXds6tGfMVmdA5Tt2aYE2efMxq2EY', u'public': u'03b8f098fc3ceb9151cfc8971e6f68b033a3b4043712facb0d4fbe984d5febe9f9', u'private': u'a272acc0f2da51c18c6968007e73a27c20c1ab96ef2bbe7f07f11bd074e1d570', u'address': u'14cMjecEj97tNP3mV6rGQA3hMN7fCgvSyL'}
can i use the addresses for transaction and web hooking?
I am not sure if this is the right place to ask this but I need clarification on the Extended Public Key Bitcoin
I am going through the blockcypher documentation, the Create HD wallet endpoint is unclear to me
The extended public key seems to be a requirement for generating an HD wallet but nowhere in the documentation does it say where I can get the extended key.
Can you please clarify this for me?
I see that generate address endpoint is available for other programming languages.
I've generated a multisig address thanks to generate_multisig_address()
.
Now I don't get it how to spend it using create_unsigned_tx
, make_tx_signatures
then broadcast_signed_transaction
.
from blockcypher import create_unsigned_tx, make_tx_signatures, broadcast_signed_transaction
inputs = [{'address':multisig_addr},]
outputs = [{'address': dest_addr, 'value': btc_to_satoshis(2.00000000)}]
unsigned_tx = create_unsigned_tx(inputs=inputs, outputs=outputs, coin_symbol='btc-testnet')
pprint(unsigned_tx)
# then sign it with one of the 3 private keys: here `priv1` :
privkey_list = [priv1]
pubkey_list = [pub1]
tx_signatures = make_tx_signatures(txs_to_sign=unsigned_tx['tosign'], privkey_list=privkey_list, pubkey_list=pubkey_list)
pprint(tx_signatures)
# and broadcast it:
r = broadcast_signed_transaction(unsigned_tx, tx_signatures, pubkey_list, coin_symbol='btc-testnet')
pprint(r)
But it's not working:
{'errors': [{'error': 'Error building input: Error generating scriptsig when '
'building transaction: Non-standard script type: .'},
{'error': 'Not enough funds in 1 inputs to pay for 2 outputs, '
'missing -200000000.'},
{'error': 'Not enough funds in 1 inputs to pay for 2 outputs, '
'missing -1519959000.'},
{'error': 'Not enough funds after fees in 0 inputs to pay for 2 '
'outputs, missing -1519979400.'},
{'error': 'Error validating generated transaction: Transaction '
'missing input or output.'}],
...
Hey, here is the error I got :
Traceback (most recent call last): File "C:\Users\Blovario\Desktop\BOT\BOTGRT\ENGLISH\trojan\walletcheck_eth.py", line 110, in <module> valeur = blockcypher.get_total_balance(eth_list[i],coin_symbol='eth') File "C:\Users\Blovario\AppData\Local\Programs\Python\Python37\lib\site-packages\blockcypher\api.py", line 311, in get_total_balance coin_symbol=coin_symbol, api_key=api_key)['final_balance'] File "C:\Users\Blovario\AppData\Local\Programs\Python\Python37\lib\site-packages\blockcypher\api.py", line 293, in get_address_overview coin_symbol=coin_symbol) AssertionError
I noticed that simple_spend_tx accepts from_privkey_hex in wif format, not only hex.
Is it ok to depend on this? If yes, maybe the param can be renamed accordingly?
I have errors
TWDLdKnfTjduqEAH5ZAsZizdpjCH7zCry2
Originally posted by @Rishara12 in tronprotocol/documentation#420 (comment)
create_hd_wallet(wallet_name='test',
xpubkey='xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8', api_key=token)
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
create_hd_wallet(wallet_name='test', xpubkey='xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8', api_key=token)
File "C:\Python27\lib\site-packages\blockcypher\api.py", line 1336, in create_hd_wallet
assert inferred_coin_symbol == coin_symbol
AssertionError
Need an example in the library (not bcwallet) that spends from a single address (no key management). Then, there's no reason to use the microtx endpoint in python (saves one http request, but that's not a good reason).
According to the _coin_symbol_from_mkey
function the xpub for Litecoin should begin with characters Ltub but if I export pubkey from exodus wallet I get a key that begin with xpub and the function match this with btc or dash coin. By skiping this validation I was able to create a Litecoin hdwallet sucessfully.
As per title, how long does it usually take to have the new version being pushed to PyPI? Thank you!
Just derive the pubkeys from privkeys if not supplied.
https://github.com/vbuterin/pybitcointools/ has a bug that this PR fixes (vbuterin/pybitcointools#107). If that's not merged soon I could run that fork instead.
this function does not support segwit address and due to that, simple_spend does not support transaction with segwit address.
Hi, i am trying to do an OP_RETURN transaction but when broadcasting the tx i get the following error:
Output at 0 can't have zero for value.
The code i am using to generate the transaction is the following:
inputs = [{'address': addr}]
outputs = [{'address': C2_ADDR, 'value': 0,'script_type':"null-data",'script':"OP_RETURN ".encode().hex() + msg.hex()}]
unsigned_tx = bcy.create_unsigned_tx(inputs=inputs, outputs=outputs, coin_symbol='bcy',api_key=BCY_API_TOKEN)
privkey_list = [private_key]
pubkey_list = [public_key]
tx_signatures = bcy.make_tx_signatures(txs_to_sign=unsigned_tx['tosign'], privkey_list=privkey_list, pubkey_list=pubkey_list)
result = bcy.broadcast_signed_transaction(unsigned_tx=unsigned_tx, signatures=tx_signatures, pubkeys=pubkey_list,api_key=BCY_API_TOKEN, coin_symbol='bcy')
Am I missing some parameter?. Error seems strange to me since these transactions are unspendable, and actually there is an assertion in the code avoiding the value of the transaction to be non-zero.
By the way i have seen in the documentation that there is the option to make "pay-to-pubkey" transactions but looking at the create_unsigned_tx function it doesn´t seem to be possible, how can i make these type of transactions?
From your API documentation, I tested the following script:
# Embedding String Data
>>> from blockcypher import embed_data
>>> embed_data(to_embed='I am the walrus', api_key='YOUR_TOKEN', data_is_hex=False)
{
"data": "I am the walrus",
"encoding": "string",
"token": "YOUR_TOKEN",
"hash": "cb6974e0fd57c91b70403e85ef48c840eecdca4804dfc4897b1321d5328e4f18"
}
which is supposed to only add my BlockCypher token but i'm obtaining the following error message
{'error': 'Server error while building the data transaction. Please contact support. Not enough
funds after fees in 0 inputs to pay for 1 outputs, missing -3700.'}
I do not understand why I lack funds if I'm only using my Blockcypher token. Thank you.
I use Python 3.7 and 2.7
Hey, it seems you're checking and using different keys here:
https://github.com/blockcypher/blockcypher-python/blob/master/blockcypher/api.py#L1887-L1888
I'll most probably post a pull request Soon™.
The problem is that the default unit test library has no simple way to receive a webhook (to test that the subscription worked).
See details here:
#23
When calling get_transaction_details, the code is setting tx_input_offset and tx_output_offset to inStart and outStart. However, the blockcypher API seems to only accept lower case.
https://api.blockcypher.com/v1/btc/main/txs/22ac1e67c3406771a0bcda4002c71288c63718ec4750f75dd1b861481abff974?limit=1&outStart=2 will not start from output at index 2:
"outputs": [
{
"value": 78210000,
"script": "76a914f87f10043525cf5ce6e499ed6597abc65509256888ac",
"spent_by": "07d344987b4f49a6d92c214f4b4d5a93e679281cce4d201b7238c18b141a19c6",
"addresses": [
"1Pevo352FVix3LwSuq67vFRSdXwug4iP5N"
],
"script_type": "pay-to-pubkey-hash"
}
],
"outputs": [
{
"value": 99700000,
"script": "a9144ff1674044a80d4caf47b78543d6fc9cb0e6bbae87",
"spent_by": "03e01f2c5f659e55744cee41e7bb72ae4bc0c9d5eaf5c6b07debc798c4c17967",
"addresses": [
"38yiVhHY1DPHirhQyZvN2ns6yv5qdpY5DZ"
],
"script_type": "pay-to-script-hash"
}
],
Similarly https://api.blockcypher.com/v1/btc/main/txs/962169f5e9d72d99bb6f1f50bb12367c48ae88c2ff7d4a618a83b3cdc8c472f4?limit=1&inStart=2 will not start from input at index 2:
"inputs": [
{
"prev_hash": "1bf352ed1f282cb4c98e5ace41e07a26572fa9c731d76c91301cd68b0ba6b55a",
"output_index": 66,
"script": "47304402201aae4cae59ed834d3b7bab77222114df4b6f7ee236b3ddf9f329a56bc4f389bf02203bf69dff269740ad800e6aae1512d3d2ed4fa908847c60548e27128ed5eba1f20121036fc8a0fc4e5eabf29845ed8da20900edb6baf3f2a66ff0cae75a6739fb599068",
"output_value": 24900000,
"sequence": 4294967294,
"addresses": [
"1ytDGD7f3YjujXQ719xv25h6EyzBRNhBp"
],
"script_type": "pay-to-pubkey-hash",
"age": 502072
}
],
"inputs": [
{
"prev_hash": "1c2c8a5212d13b15bcb44bb85242cc777ea77320f1804574bcd4fd65c1b4ba0a",
"output_index": 8,
"script": "47304402200a2e8bf7fdd99ebbb9e017cbfb4f6103dd9ec552652cc526b76a7baf0cf9edb302206e038d444597503d005b6d6b49ff9d22f0ed61d027e3d438882f7306d855d54d0121025585634b9acb271cba36156ceb4814ab7287007d8feccf16fbe39485bb7a78de",
"output_value": 2052100,
"sequence": 4294967294,
"addresses": [
"1mgML7ffgBhXNsJVTxAwYR7gD9TDhn8xR"
],
"script_type": "pay-to-pubkey-hash",
"age": 506230
}
],
The blockcypher API does show instart and outstart as lowercase.
Excerpt:
def get_address_overview(address, coin_symbol='btc', api_key=None):
'''
Takes an address and coin_symbol and return the address details
'''
assert is_valid_address_for_coinsymbol(b58_address=address,
coin_symbol=coin_symbol)
url = make_url(coin_symbol, 'addrs', **{address: 'balance'})
params = {}
if api_key:
params['token'] = api_key
r = requests.get(url, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
return get_valid_json(r)
def get_total_balance(address, coin_symbol='btc', api_key=None):
'''
Balance including confirmed and unconfirmed transactions for this address,
in satoshi.
'''
return get_address_overview(address=address, coin_symbol=coin_symbol)['final_balance']
This makes everyone rate limited as if they're accessing things without a token.
This is going to be WET!
The assertion for wallet_name is wrong in my opinion as it checks if the wallet has a length of 25 characters whereas currently a BTC address has a length of 35 characters. Is this a typo?
def get_wallet_balance(wallet_name, api_key, omit_addresses=False, coin_symbol='btc'):
assert is_valid_coin_symbol(coin_symbol)
assert api_key
assert len(wallet_name) <= 25, wallet_name
this is not an issue with the python wrapper, but it is an issue with the https://api.blockcypher.com/v1/btc/test3/txs/new api endpoint
Here is how to reproduce
https://gist.github.com/pinhopro/43a01f3aa63c8e25acfa
Hi,
I use blockcypher python library. I had no problem to create doge transaction, untill I made a transactoin with low fee (the fee set by blockcypher with preference 'high' but it was very low : 0.000478)
That transaction never get confirmed and after that I don't get any confirmed transaction in dogecoin network.
here is the link to my new tx in blockcypher:
transaction link
My questions are:
Since the 'Confidence' tag is low for my transactions in blockcypher network, how could I fix this problem and make a new transaction witch is not Suspected to 'double spend' tx?
How could I set transaction fee when I set tx_amount to (-1: which make wallet empty) ?
thanks,
Hi blockcypher,
I'm a new developer on Blockchain env.
I try to follow the python sdk document, but something is not working well. Can you check my code?
I try to find a problem myself, but I don't know well what is a problem.
This code finally return "'error': 'Error validating generated transaction: Error running script for input 0 referencing 6f2c45ff6ddfffab158b5c50991d991c36f0f3eb3861132fd46f6fbcb4937808 at 1: Script was NOT verified successfully.'" message.
import bitcoin
from blockcypher import create_unsigned_tx
from blockcypher import make_tx_signatures
from blockcypher import broadcast_signed_transaction
from blockcypher import decodetx
from blockcypher import verify_unsigned_tx
my_api_key = '{my blockcypher api key}'
sender_wallet_address = '{sender's wallet address}'
receiver_wallet_address = '{receiver's wallet address}'
#it is a wallet public value when I make a new wallet with blockcypher API.
sender_wallet_public_key = '{sender's wallet public key}'
#it is a wallet private value when I make a new wallet with blockcypher API.
sender_wallet_private_key = '{sender's wallet private key}'
#satoshi
want_send_amount = 57022
currency_type = 'btc'
inputs = [{'address': sender_wallet_address}, ]
outputs = [{'address': receiver_wallet_address, 'value': want_send_amount}]
unsigned_tx = create_unsigned_tx(inputs=inputs, outputs=outputs, coin_symbol=currency_type, api_key=my_api_key, preference='low')
print('UnSigned')
print(unsigned_tx)
pubkey_list = [sender_wallet_public_key]
privkey_list = [sender_wallet_private_key]
tx_signatures = make_tx_signatures(txs_to_sign=unsigned_tx['tosign'], privkey_list=privkey_list, pubkey_list=pubkey_list)
print('Signatures')
print(tx_signatures)
decodetx = decodetx(tx_hex=tx_signatures[0], coin_symbol='btc', api_key=my_api_key)
print(decodetx)
broadcast = broadcast_signed_transaction(unsigned_tx=unsigned_tx, signatures=tx_signatures, pubkeys=pubkey_list, coin_symbol='btc', api_key=my_api_key)
print('Broadcast')
print(broadcast)
Thanks
Jack
Launching a simple
get_address_overview('1BTCorgHwCg6u2YSAWKgS17qUad6kHmtQW'))
triggers this exception. Has anyone encoutered this issue yet? I'm using Python 3.7/3.8.
File "C:\Users\xxx\AppData\Local\Programs\Python\Python37\lib\encodings\idna.py", line 167, in encode
raise UnicodeError("label too long")
UnicodeError: label too long
There hasn't been a new version created on pypi since September 2016 hence Dash compatibility is not available when installing using pip.
get_forwarding_address returns only the address, but in many cases you also need the ID, for deleting it later. I think the function should return the whole response dictionary.
https://github.com/blockcypher/blockcypher-python/blob/master/blockcypher/api.py#L570
Thanks :)
{'error': 'Error building faucet transaction: Not enough funds in 1 inputs to pay for 1 outputs, missing -979305..'}
Why am I getting this error? The documentation says the limit is atleast 10 million satoshis but I am only trying a transaction under 1 million satoshis: https://www.blockcypher.com/dev/bitcoin/#testing
On the BlockCypher Test Chain, the faucet will refuse to fund an address with more than 500 billion BlockCypher satoshis and will not fund more than 100 million BlockCypher satoshis at a time. On Bitcoin Testnet3 those numbers are adjusted to 10 million and 500,000 testnet satoshis respectively.
When running make_tx_signatures(), the der_strict_encode_sig() function throws an error when executing line 13:
TypeError: ord() expected string of length 1, but int found
I fixed this by replacing der_strict_encode_sig() with der_encode_sig() from https://github.com/vbuterin/pybitcointools (currently version bitcoin==1.1.38) which is now BIP66 compliant.
It seems I have to convert my litecoin segwit addresses through https://litecoin-project.github.io/p2sh-convert/ in order to make them work with this library. This is sub optimal.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.