Skip to content

Instantly share code, notes, and snippets.

@Anderson-Juhasc
Last active July 21, 2017 13:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anderson-Juhasc/daa4e4cb974257dac6536ee0ab542d41 to your computer and use it in GitHub Desktop.
Save Anderson-Juhasc/daa4e4cb974257dac6536ee0ab542d41 to your computer and use it in GitHub Desktop.
O dinheiro em novo formato
const Bitcore = require('bitcore-lib');
if (true) Bitcore.Networks.defaultNetwork = Bitcore.Networks.testnet;
var fromAddress = 'mrhcLBUaiNNu4icP4ytVw25iGuCJ73nMA3'
, toAddress = 'mtsQKn4RWLzXJAndBMoUWUy5FGZ5XfbHUo'
, amount = 1000000
, changeAddress = 'mqgBjbyqVbSwBv1PHHYjKD5nsS1Bww5Mz3'
, transactionFee = 1000000;
var Insight = require('bitcore-explorers').Insight
, insight = new Insight()
, privatekey = Bitcore.PrivateKey.fromString('2487f438d720ee741708f53815f5f90582d76501de414448e039e414728fca3c');
insight.getUnspentUtxos(fromAddress, function(err, utxos) {
var transaction = new Bitcore.Transaction()
.from(utxos)
.to(toAddress, amount)
.change(changeAddress)
.fee(transactionFee)
.sign(privatekey);
var txSerialized = transaction.serialize();
insight.broadcast(txSerialized, function(err, transactionHash) {
if (err) {
console.log(err);
} else {
console.log(transactionHash);
}
});
});
const Bitcore = require('bitcore-lib')
, PrivateKey = Bitcore.PrivateKey;
if (true) Bitcore.Networks.defaultNetwork = Bitcore.Networks.testnet;
var privateKey = new PrivateKey()
, publicKey = privateKey.toPublicKey()
, address = publicKey.toAddress();
console.log('Private:', privateKey.toString());
console.log('Public address:', address.toString());
{
"name": "money-in-new-format",
"version": "1.0.0",
"description": "",
"keywords": "money, new, format, bitcoin, cryptocurrency",
"main": "broadcast.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gist.github.com/daa4e4cb974257dac6536ee0ab542d41.git"
},
"author": "Anderson Juhasc",
"license": "ISC",
"bugs": {
"url": "https://gist.github.com/daa4e4cb974257dac6536ee0ab542d41"
},
"homepage": "https://gist.github.com/daa4e4cb974257dac6536ee0ab542d41",
"dependencies": {
"bitcore-explorers": "^1.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment