I wanted to create a website where I could broadcast Bitcoin transactions, so I modified some of the code for this site and ran it in my browser with the following error:
Error: Cannot find module 'bitcore-explorers'
I bower install
bitcore-lib and bitcore-explorers with reference to the document in a JavaScript library called BitCore, but what is the reason why I can't find the module?
index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<metacharset="utf-8">
<script src="bower_components/bitcore-lib/bitcore-lib.min.js">/script>
<script src="bower_components/bitcore-explorers/bitcore-explorers.min.js">/script>
</head>
<body>
<script type="text/javascript">
var bitcore=require('bitcore-lib');
var explorers=require('bitcore-explorers');
varinsight=new explorers.Insight();
vara_address="; // A address
private key for var privateKey="";//A
getUTXO(a_address, function(utxos){
utxos.forEach(function(utxo){console.log(utxo.toJSON()));});
// Transaction generation
var transaction=new bitcore.Transaction().fee(10000)
.from(utxos)
.addData('')
.change(')//Sets up a change address where the rest of the funds will go
.sign(privateKey)
console.log("transaction", transaction.toJSON());
broadcast(transaction, function(id){
console.log(id);
});
});
function getUTXO(address, done)
{
// Get utxos
Insight.getUnspentUtxos(address, function(err,utxos){
if(err){
console.log(err);
}
done(utxos);
});
}
function broadcast(tx, done)
{
// Broadcast
Insight.broadcast(tx, function(err,id){
if(err){
console.log(err);
}
done(id);
});
}
</script>
</body>
</html>
This is a self-answer.
When I installed bitcore-explorers from GitHub, I was able to require them without any problems.
© 2024 OneMinuteCode. All rights reserved.