Coder Social home page Coder Social logo

Comments (9)

alishaagupta avatar alishaagupta commented on July 30, 2024 1

what are the units of value in the targets? I believe it could be that issue

from coinselect.

dcousens avatar dcousens commented on July 30, 2024

Show your code

from coinselect.

alishaagupta avatar alishaagupta commented on July 30, 2024
let coinSelect = require('coinselect/blackjack')
var utxo = 
[{"txid":"afb9fba00cb7324567a582684d1ab76fca6697c49327bb1f9b81580e5347cd38","vout":0,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0022,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"6bd287720f09229ec6a7f46979f52df5650509d6de2c91e23c4e60b62184c150","vout":1,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0021,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"32800034f85f2a58bdc69c43ebec8375af082fa405c836d4e251d96b8b6ae255","vout":1,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0022,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"870c85930ce38c53a59ab2fe8eba4ffaf13059e3c650e341744eb281ce3e6287","vout":1,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0021,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"3195afe4de7479fb39e7552c4b21dbb46d09966f9b67c3235d1480b69742ee8d","vout":1,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.50966016,"confirmations":4,"spendable":false,"solvable":false,"safe":true},{"txid":"4149bb1d8d9398bb841b155b6173b677f8f7605dfdb55e02017f66796547d692","vout":0,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0023,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"dd0edd417bde9fbb6eb890ad161b117c3418dbb10f89d4335da8e6fc535a1496","vout":0,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0022,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"5ec55becfca7bbc9aea711aead34dbd75d0e735f4f8ded5e2201669bb96755a7","vout":1,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0023,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"dda5a2ebbbc27d09590f0c8b54bafcaa988f1894f7f729c499fb0243a93f56bd","vout":1,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0022,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"1365201aa0d83aa18845b6e94afe2abf027ee98361f60175a673482cc263d8c0","vout":0,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0021,"confirmations":0,"spendable":false,"solvable":false,"safe":false},{"txid":"c86b5bf1d5f42eec5ca84a2c80ea9c387790957c6997592c77d45023b76ec9d2","vout":1,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0023,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"9aea0b284cda841463c5a431678885098721fcec946cce8206bbe2451d2175d4","vout":1,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0023,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"6f3efbb5e2a3a8c62b1dcf63024aa129ade7ab7f464f3421a72371424bc21fef","vout":1,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0022,"confirmations":1,"spendable":false,"solvable":false,"safe":true},{"txid":"1fd21fe59d3dd887ca2b7a17e273fad92b107bd7a9aea9432129054969750bfd","vout":0,"address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH","account":"","scriptPubKey":"76a914c71f6c7dcc76d87440e47d3fd2623625f9d0e4c788ac","amount":0.0022,"confirmations":1,"spendable":false,"solvable":false,"safe":true}]


let feeRate = 1 // satoshis per byte
let utxos = utxo
let targets = [
  {
    address: 'mn6jRt7sg54DdQy3DbmCGr79rHDtU6hP2q',
    value: 0.01
  } ,
  {
  	address: 'myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH',
  	value: 0.52846016
  }
]
 
// ...
let { inputs, outputs, fee } = coinSelect(utxos, targets, feeRate)
 
// the accumulated fee is always returned for analysis
console.log(fee)

console.log('output' + JSON.stringify(outputs));
// .inputs and .outputs will be undefined if no solution was found
if (!inputs || !outputs) return



let txb = new bitcoin.TransactionBuilder()

inputs.forEach(input => txb.addInput(input.txId, input.vout))
outputs.forEach(output => {
  // watch out, outputs may have been added that you need to provide
  // an output address/script for
  if (!output.address) {
    output.address = wallet.getChangeAddress()
    wallet.nextChangeAddress()
  }

  txb.addOutput(output.address, output.value)
})

from coinselect.

alishaagupta avatar alishaagupta commented on July 30, 2024

@dcousens

from coinselect.

dcousens avatar dcousens commented on July 30, 2024

288f24d

Units are in satoshis.

from coinselect.

dcousens avatar dcousens commented on July 30, 2024

Please read and follow the examples, the utxos need a .value field too (in satoshis).

from coinselect.

alishaagupta avatar alishaagupta commented on July 30, 2024

@dcousens I editted my code but still it shows undefined.

let coinSelect = require('coinselect/blackjack')
let feeRate = 1 // satoshis per byte
let utxos =
[
{txId:"afb9fba00cb7324567a582684d1ab76fca6697c49327bb1f9b81580e5347cd38","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:0, value: 220000 },

{txId:"6bd287720f09229ec6a7f46979f52df5650509d6de2c91e23c4e60b62184c150","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:1, value: 210000},

{txId:"32800034f85f2a58bdc69c43ebec8375af082fa405c836d4e251d96b8b6ae255","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:1, value: 220000},

{txId:"870c85930ce38c53a59ab2fe8eba4ffaf13059e3c650e341744eb281ce3e6287","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:1, value: 210000},

{txId:"3195afe4de7479fb39e7552c4b21dbb46d09966f9b67c3235d1480b69742ee8d","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:1, value: 50966016},

{txId:"4149bb1d8d9398bb841b155b6173b677f8f7605dfdb55e02017f66796547d692","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:0, value: 230000},

{txId:"dd0edd417bde9fbb6eb890ad161b117c3418dbb10f89d4335da8e6fc535a1496","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:0, value: 220000},

{txId:"5ec55becfca7bbc9aea711aead34dbd75d0e735f4f8ded5e2201669bb96755a7","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:1, value: 230000},

{txId:"dda5a2ebbbc27d09590f0c8b54bafcaa988f1894f7f729c499fb0243a93f56bd","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:1, value: 220000},

{txId:"1365201aa0d83aa18845b6e94afe2abf027ee98361f60175a673482cc263d8c0","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:0, value: 210000},

{txId:"c86b5bf1d5f42eec5ca84a2c80ea9c387790957c6997592c77d45023b76ec9d2","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:1, value: 230000},

{txId:"9aea0b284cda841463c5a431678885098721fcec946cce8206bbe2451d2175d4","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:1, value: 230000},

{txId:"6f3efbb5e2a3a8c62b1dcf63024aa129ade7ab7f464f3421a72371424bc21fef","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:1, value: 220000},

{txId:"1fd21fe59d3dd887ca2b7a17e273fad92b107bd7a9aea9432129054969750bfd","address":"myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH", vout:0, value: 220000}
]

let targets = [
{
address: 'mn6jRt7sg54DdQy3DbmCGr79rHDtU6hP2q',
// value: 0.01
value: 1000000 //satoshis
} ,
{
address: 'myfpQbH489pyt7nDFrWz8ZrrkcnmtrbyKH',
// value: 0.52846016
value: 52846010 //satoshis
}
]

// ...
let { inputs, outputs, fee } = coinSelect(utxos, targets, feeRate)

// the accumulated fee is always returned for analysis
console.log(fee)

console.log('output ' + JSON.stringify(inputs));
// .inputs and .outputs will be undefined if no solution was found
if (!inputs || !outputs) return

let txb = new bitcoin.TransactionBuilder()

inputs.forEach(input => txb.addInput(input.txId, input.vout))
outputs.forEach(output => {
// watch out, outputs may have been added that you need to provide
// an output address/script for
if (!output.address) {
output.address = wallet.getChangeAddress()
wallet.nextChangeAddress()
}

txb.addOutput(output.address, output.value)
})

console.log('tx ' + txb);

from coinselect.

alishaagupta avatar alishaagupta commented on July 30, 2024

@dcousens I can understand there must be some silly mistake but I could not figure out . Need help urgently!

from coinselect.

dcousens avatar dcousens commented on July 30, 2024

Have you tried a non exact algorithm? (Something other than blackjack)

from coinselect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.