Closed benzmuircroft closed 9 years ago
Previous outputs "amount" is expected to be in BTC units for backwards compatibility, you can specify "satoshis", which is preferred.
Floating point numbers are not supported as units: https://github.com/bitpay/bitcore/blob/master/CONTRIBUTING.md#g3---internal-amounts-must-be-integers-representing-satoshis
This is due to unsafe representation with floating point, example:
0.1 * 0.1
@benzmuircroft Transaction.to
should have amount in satoshis
@braydonf satoshis
in UnspentOutput isn't preffered...
@fanatid How am I suppost to get the new bicore.Transaction
to be in BTC using Transaction.to
?
"amount" is converted into "satoshis" in UnspentOutput and at some point we may want to deprecate the "amount" field just so it's clear, though several explorers will have that format, and hence why it exists there.
Why does bitcore expect me to add amounts in satoshi then automatically mess up the prevTx amounts ??!
The output raw transaction is not accepted on blockchain.info or blockr.io with messed up amounts
These are equivalent:
var unspents = [
{
txid: '67b22a1874be2e748b2c904e2181f85a9d6503001e58c374e17b1161cd5a36f4',
outputIndex: 0,
address: 'myHtNgECiAjBctWz1tM2TN2PupWwfHtgMi',
scriptPubKey: '76a914c2f9958848c465efd042fcb76fef519f03a83ec288ac',
amount: 0.001,
confirmations: 54
}
];
(from various block explorers)
var unspents = [
{
txId: '67b22a1874be2e748b2c904e2181f85a9d6503001e58c374e17b1161cd5a36f4',
outputIndex: 0,
script: '76a914c2f9958848c465efd042fcb76fef519f03a83ec288ac',
satoshis: 100000
}
];
(bitcore internal representation)
Entering satoshis into the "amount" property will then multiply 100000
by 1e8
and give the incorrect value 10000000000000
from above, and is likely the source of the problem.
Also there is a community forum at https://labs.bitpay.com/ for questions and discussion.
hello i need a verdit on this close argument
I would like to construct a raw tx to ( push tx ) send to blockr.io or blockchain.info but they reconize BTC not satoshi
My unspent outputs:
var unspents= [ { txid: '67b22a1874be2e748b2c904e2181f85a9d6503001e58c374e17b1161cd5a36f4', outputIndex: 0, address: 'myHtNgECiAjBctWz1tM2TN2PupWwfHtgMi', scriptPubKey: '76a914c2f9958848c465efd042fcb76fef519f03a83ec288ac', amount: 0.001, confirmations: 54 } ];
Causes error:
But if I set it all up with
satoshis
instead I get no error message but the prevTxId outputs are completely messed upcan you see "satoshis":10000000000000 and "satoshis":9999999890000 they are messed up massive numbers.
They should be: Total Inputs 1.10000000 tBTC Total Outputs 1.09990000 tBTC
as seen here (testnet) https://www.blocktrail.com/tBTC/tx/67b22a1874be2e748b2c904e2181f85a9d6503001e58c374e17b1161cd5a36f4