Skip to content

Instantly share code, notes, and snippets.

@discountry
Last active July 21, 2018 20:49
Show Gist options
  • Select an option

  • Save discountry/3b7b52811fc4c350c9aaffdfd7e4ef2b to your computer and use it in GitHub Desktop.

Select an option

Save discountry/3b7b52811fc4c350c9aaffdfd7e4ef2b to your computer and use it in GitHub Desktop.
var run = async function () {
var bitcore = require('bitcore');
var RpcClient = require('bitcoind-rpc');
var config = {
protocol: 'http',
user: 'bitcoin',
pass: 'local321',
host: '127.0.0.1',
port: '18332',
};
var rpc = new RpcClient(config);
var txids = [];
const Networks = bitcore.Networks;
var address = bitcore.Address.fromString('2N2Ww3EPc9gC8hPycHn8rxZLjy1eEfsbw5y', Networks.testnet);
var utxo = {};
rpc.getAddressUtxos({
addresses: [address.toString()]
}, function (err, res) {
// console.log(res)
utxo = {
"txId": res.result[0].txid,
"outputIndex": res.result[0].outputIndex,
"address": res.result[0].address,
"script": res.result[0].script,
"satoshis": res.result[0].satoshis,
};
console.log('utxo', utxo)
var alice_privateKey = new bitcore.PrivateKey();
console.log(alice_privateKey)
var bob_privateKey = new bitcore.PrivateKey();
console.log(bob_privateKey)
var alice_publicKey = new bitcore.PublicKey(alice_privateKey);
console.log(alice_publicKey)
var bob_publicKey = new bitcore.PublicKey(bob_privateKey);
console.log(bob_publicKey)
var publicKeys = [alice_publicKey, bob_publicKey];
var threshold = 2;
/**
* Create MultiSig Wallet
*/
// var address = new bitcore.Address(publicKeys, threshold, Networks.testnet);
// console.log(address)
/**
* First Step Signature
*/
var multiSigTx = new bitcore.Transaction()
.from(utxo, publicKeys, threshold)
.to('mm67v72VEg4QnQyXHiSnwVYyTugp1JYWVj', 10 * 100000000)
.change('2N2Ww3EPc9gC8hPycHn8rxZLjy1eEfsbw5y')
.sign(alice_privateKey);
console.log('multiSigTx', multiSigTx)
var serialized = multiSigTx.toObject();
/**
* Second Step Signature
*/
var nextSigTx = new bitcore.Transaction(serialized)
.sign(bob_privateKey);
console.log('nextSigTx', nextSigTx)
console.log(nextSigTx.isFullySigned());
/**
* Bordcast to the Network
*/
rpc.sendRawTransaction(nextSigTx.toString(), function (err, res) {
console.log(res)
rpc.sendToAddress('2N2Ww3EPc9gC8hPycHn8rxZLjy1eEfsbw5y', 25, function (err, res) {
console.log(res)
rpc.generate(1, function (err, res) {
console.log(res)
})
})
})
})
// rpc.sendToAddress(address.toString(), 25, function(err, res){
// console.log(res)
// })
// rpc.generate(1, function(err, res){
// console.log(res)
// })
// let new_address = ''
// rpc.getnewaddress(function(err, res){
// new_address = res.result
// console.log(res)
// })
// rpc.sendToAddress(address.toString(), 25, function(err, res){
// console.log(res)
// })
};
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment