I'm trying to create a transcation on the the bitcoin test network. When I run insight.getUnspentUtxos() it return an error.
var bitcore = require('bitcore-lib');
var explorers = require('bitcore-explorers');
var insight = new explorers.Insight('testnet');
var value = Buffer.from('I am trying to create new private key');
var hash = bitcore.crypto.Hash.sha256(value);
var BN = bitcore.crypto.BN.fromBuffer(hash);
var privateKeyNew = bitcore.PrivateKey(BN, 'testnet')
var myAddress = privateKeyNew.toAddress()
console.log(myAddress);
var newValue = Buffer.from('I am trying to create new private key but that can be risky');
var newhash = bitcore.crypto.Hash.sha256(newValue);
var newBN = bitcore.crypto.BN.fromBuffer(newhash);
var privateKey = bitcore.PrivateKey(newBN, 'testnet')
var address = privateKey.toAddress();
console.log(address);
insight.getUnspentUtxos(myAddress, ( err, utxo ) => {
if(err) {
console.log(err);
return err;
} else {
let tx = bitcore.Transaction()
tx.from(utxo);
tx.to(address,10000);
tx.fee(50000);
tx.change(myAddress);
tx.sign(privateKeyNew);
tx.serialize();
insight.broadcast(tx.toString(), (error, txid) => {
if(error) {
return error;
} else {
console.log(txid);
}
})
}
})
As the UnspentUtxos() execute it give some long massive error. Which describe error 525 Origin SSL Hanshake Error
bitcoreis usingbitpayas the default provider server, and for some reason, it is not working. They also recommend changing the default server in the docs. Try changing the provider tozelcorelike this:More explanation here