Closed anjalialance closed 5 years ago
Please be more precise in your question.
Thanks.
Hi,
Thanks for the reply I am providing you the main code for transaction-
const bitcoin = require('bitcoinjs-lib')
const blockexplorer = require('blockchain.info/blockexplorer').usingNetwork(3)
const wif = 'cRboSi32o7hRLQ2VQMfSDc3SSBayMpxaPvpvPuiX65NXZMwLw1zT'
const key = bitcoin.ECPair.fromWIF(wif, bitcoin.networks.testnet)
const wallet = bitcoin.payments.p2pkh({
pubkey: key.publicKey,
network: bitcoin.networks.testnet
})
// wallet.address === motCmpWMeMC6BTRUtryxMATUBCvGorAjcs
blockexplorer.getUnspentOutputs(wallet.address).then(result => {
wallet.utxos = result.unspent_outputs
const sending = 10000
console.log(sending)
const txb = new bitcoin.TransactionBuilder(bitcoin.networks.testnet)
txb.setVersion(2)
var input = 0
for (let utx of wallet.utxos) {
txb.addInput(utx.tx_hash_big_endian, utx.tx_output_n)
input += utx.value
if (input >= sending) break
}
const change1 = 17466476 - sending
const fee = 1000
const change = input - (sending + fee)
txb.addOutput('myQdZsy9wRd4A7deRBm88RZX9rv19NDGyB', sending)
if (change) txb.addOutput('motCmpWMeMC6BTRUtryxMATUBCvGorAjcs', change)
txb.sign(0, key)
const raw = txb.build().toHex()
console.log(raw)
})
This is the code of transaction
and the code for wallet creation is-
var keyPair = bitcoin.ECPair.makeRandom();
var testnet = bitcoin.networks.testnet;
var {address} = bitcoin.payments.p2pkh({pubkey : keyPair.publicKey, network: testnet});
var privateKey=keyPair.toWIF();
blockchain info API is broken.
Please ask them to fix it. (This issue looks related: https://github.com/blockchain/api-v1-client-node/issues/90 )
This is irrelevant to our library, so I will close it. Thanks.
Okay Thanks!
Hello,
I am new to bitcoin transactions. I am using bitcoinjs-lib and blockexplorer for the transaction. The thing that is happening with me is that if I am entering new address that is generated by bip32 and bip39
The address and private key are-
sender address - motCmpWMeMC6BTRUtryxMATUBCvGorAjcs private key - L1Eoyo3BN41AAxZE1wrJrHYNoxHZhNrtKtgTHVG1axiXJcs6TCkj receiver address - myQdZsy9wRd4A7deRBm88RZX9rv19NDGyB
then it is giving me error. Also, if i am entering the address which I have previously used in transaction procedures. It is generating same transaction ids again and again.
The address that i am using for this is -
sender address - mkX9cVJDWjPxxfwNvYg58fbR2vHRfuU6XJ private key - KwV364bGF83ie4wJSwzV4hccbLeyMnFSVwyPvdMEnU8cr6Nyu25U receiver address - mthGgBTX1kxibjXwXxy5jraBNtTsajpqSx
This is the error.
and Here, is the code.
Thank you in advance.!