I've been trying to send testnet and when I attempt to push it onto the network, I get an error that says the fees are too high. So, is there a way for me to set the fee myself rather than input - output? If not, can someone please help me understand why this won't work? Here's the code:
createWallet = (e) => {
e.preventDefault()
var keyPair = bitcoin.ECPair.makeRandom({network: testnet});
console.log(keyPair.toWIF());
console.log(keyPair.getAddress());
this.setState({
address: 'mphWVWbPgGKuaMpSpGNA3Ffrpva5cRChqP',
privateKey: 'cW6dLEqkk2HAbQTSJaHnn4w3kd2iJfhBREccEE3vzrq8kcVE5TqS',
});
}
createTransaction = (e) => {
e.preventDefault()
const {address, privateKey} = this.state;
var hashURL = `https://api.blockcypher.com/v1/btc/test3/addrs/${address}`
axios.get(hashURL).then((response) => {
this.setState({
hash: response.data.txrefs[0].tx_hash
})
}).then((result) => {
var tx = new bitcoin.TransactionBuilder(testnet);
var txId = this.state.hash;
console.log(txId);
tx.addInput(txId, 0)
tx.addOutput(this.state.add, 1000000)
var keyPair2 = bitcoin.ECPair.fromWIF(privateKey, testnet);
tx.sign(0, keyPair2);
console.log(tx.build().toHex());
}
)
}
input - output is how you manually set the fee.
Yes. Please look up the concept of “change”
If you don’t include a change output (an extra output sending the remainder of the input to yourself) then all of the remainder goes to fees.
You manually set fees implicitly by adjusting the change input so that the leftovers is the fee you wish to send.
Most helpful comment
Yes. Please look up the concept of “change”
If you don’t include a change output (an extra output sending the remainder of the input to yourself) then all of the remainder goes to fees.
You manually set fees implicitly by adjusting the change input so that the leftovers is the fee you wish to send.