def test(chat_id=chat_id, coin=coin): if coin == 'btc': b = bc.generate_new_address(api_key=self.token, coin_symbol='bcy') addr = b['address'] priv = b['private'] self.record_to_addressdb(chat_id, coin, addr, priv) elif coin == 'ltc': b = bc.generate_new_address(api_key=self.token, coin_symbol='bcy') addr = b['address'] priv = b['private'] self.record_to_addressdb(chat_id, coin, addr, priv) return addr
def generateAddress(): address_object = blockcypher.generate_new_address( coin_symbol='btc-testnet', api_key='141dbdc7350f4275900fd063fd56b6d3') address = address_object['address'] public_key = address_object['public'] private_key = address_object['private'] print("address: ", address, "public_key: ", public_key, "private_key: ", private_key)
def test_generate_single_addr(self): for coin_symbol in ('btc', 'btc-testnet', 'doge', 'ltc', 'bcy'): response_dict = generate_new_address( coin_symbol=coin_symbol, api_key=BC_API_KEY, ) assert is_valid_address(response_dict['address']), response_dict assert uses_only_hash_chars(response_dict['private']), response_dict assert uses_only_hash_chars(response_dict['public']), response_dict assert 'wif' in response_dict, response_dict
def test_generate_single_addr(self): for coin_symbol in ('btc', 'btc-testnet', 'doge', 'dash', 'ltc', 'bcy'): response_dict = generate_new_address( coin_symbol=coin_symbol, api_key=BC_API_KEY, ) assert is_valid_address(response_dict['address']), response_dict assert uses_only_hash_chars(response_dict['private']), response_dict assert uses_only_hash_chars(response_dict['public']), response_dict assert 'wif' in response_dict, response_dict
def generate_new_address(user, coin_symbol): if isinstance(user, get_user_model()) and get_wallet_model(coin_symbol): r = blockcypher.generate_new_address(coin_symbol=coin_symbol, api_key=get_api_key()) obj = get_wallet_model(coin_symbol).objects.create( user=user, private=r['private'], public=r['public'], address=r['address'], wif=r['wif']) return obj else: return None
def newWallet(request): try: resp = generate_new_address(coin_symbol=blockchainName, api_key=token) assert is_valid_address(resp['address']), resp if resp: result = str(resp['address']) deposit = Deposits(address=result, key=request.session.session_key) deposit.save() else: raise Exception('Ocorreu um erro, por favor tente novamente') except Exception as e : result = 'Ocorreu um erro, por favor tente novamente' print(e) return render(request, 'index.html', {'result': result})
def generate_address(self): self.address = blockcypher.generate_new_address( api_key=config.BLOCKCYPHER_TOKEN)
import blockcypher addr = blockcypher.generate_new_address( coin_symbol='btc-testnet', api_key='32b0191e07db4a2eaf11dc6568c644b4') print(addr) #{'private': 'fc6bcef57f9ae29e25928641a9f70cfc2acbd734a5a445a94fa884bbdb20fb84', 'public': '02c18671d24509524bf64be7688b0cf745029951310de03e371e8eba743cca4cb6', 'address': 'muFrB2JPfA2yEAgi6y8eBo7SZQTCSvjXXV', 'wif': 'cW3NirDSBK8CJjRSDBJbpfpbSY9Kxvkm1Ljr8LB2S8ySySkQt6xx'} #Specify the inputs and outputs below #For convenince you can specify an address, and the backend will work out what transaction output that address has available to spend #You do not need to list a change address, by default the transaction will be created with all change (minus the fees) going to the first input address inputs = [{'address': 'muFrB2JPfA2yEAgi6y8eBo7SZQTCSvjXXV'}] outputs = [{'value': 0, 'script_type': "null-data", 'script': ""}] # outputs = [{'address': 'mpamtqLA66JFVSQNDaPHZ5xMiCz6T2MeNn', 'value': 100}] "add" print("OP_RETURN mjqf76".hex()) print(b'OP_RETURN mjqf76'.hex()) #The next line creates the transaction shell, which is as yet unsigned unsigned_tx = blockcypher.create_unsigned_tx( inputs=inputs, outputs=outputs, coin_symbol='btc-testnet', api_key='32b0191e07db4a2eaf11dc6568c644b4') #You can edit the transaction fields at this stage, before signing it. # # Now list the private and public keys corresponding to the inputs # private_keys=['fc6bcef57f9ae29e25928641a9f70cfc2acbd734a5a445a94fa884bbdb20fb84'] # public_keys=['02c18671d24509524bf64be7688b0cf745029951310de03e371e8eba743cca4cb6'] # #Next create the signatures