Method of get UTXO
getUtoxs(address){ var options;
if(Global.btc.network === "testnet"){
options = {
url: testnet.apiBaseUrl + "/api/addr/" + address + "/utxo"
}; }else{
options = {
url: livenet.apiBaseUrl + "/addr/" + address + "/utxo"
};
}
return fetch(options.url)
.then((res) => res.json())
.then((data) =>data)
.catch((error) =>{
console.error(error);
});
}
Method of send btc
sendingBTC(utxos, tx) {
try {
var options;
var transaction = new bitcore.Transaction()
.from(utxos) //this line gets error
.to(tx.to,tx.value*100000000)
.change(tx.from)
.sign(tx.password)
.serialize();
/*.......................*/
} catch (e) {
console.error(e);
}
}
this methods are getting an error. What is the wrong in this methods ?
Try using bitcore-insight to make the getUtxos work.
The preferable way to do this would be to return a promise in the getUtxos() function which you can then consume, preferably using async-await in the sendingBtc() function.
Here's an excerpt of code to help you out.
Hope this piece of code helps you out, remember you also need to derive your private key to sign the transaction and set up a change address (optional but recommended)!