online resources

How to make transaction with many inputs and one output in BitcoinJ?

I'm trying to send all coins from my accounts (generated by HD Wallet) to one account with this code: fun sendAllFundsOnAddress(address: String) { val receiver = Address.fromString(params, address) val tx = Transaction(params) val balance = Coin.valueOf(walletAppKit.wallet().unspents.map { it.value.value }.sum()) tx.addOutput(balance, receiver) walletAppKit.wallet().unspents.forEach { val key = walletAppKit.wallet().findKeyFromAddress(Address.fromString(params, it.scriptPubKey.getToAddress(params).toString())) tx.addSignedInput(it.outPointFor, it.scriptPubKey, key, Transaction.SigHash.ALL, true) } walletAppKit.wallet().commitTx(tx) val sendRequest = SendRequest.forTx(tx) walletAppKit.wallet().completeTx(sendRequest) } But I get NullPointerException, while it calculates witness (in input signing process). Could you give any ideas, what's wrong?

Continue Reading How to make transaction with many inputs and one output in BitcoinJ?

Add bitcoin payments to java app using BitcoinJ

I need to add Bitcoin payment to my application using the BitcoinJ library, but I'm new to using Bitcoin. I have one thought To create a new address for each new user, but I don't know if this is the right approach or not. Please tell me how to implement it correctly. (I need to determine from which user the payment was received and in what amount)

Continue Reading Add bitcoin payments to java app using BitcoinJ

(bitcoinj) How to determine which key/address to use to send funds?

I'm using Bitcoinj and am confused as to the numerous addresses it's generating. I want to be able to send funds from my wallet (for which I have my private and public key) but I am unsure as to what address I should be using. For example, I have an ECKey from which I can debug print a private or public key, but the wallet allows me to get four different addresses: wallet.currentAddress(KeyChain.KeyPurpose.AUTHENTICATION) wallet.currentAddress(KeyChain.KeyPurpose.REFUND) wallet.currentAddress(KeyChain.KeyPurpose.CHANGE) wallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS) I understand I may not need to specify an address when creating the transaction (it seems that bitcoinj handles this?) but what address is…

Continue Reading (bitcoinj) How to determine which key/address to use to send funds?

Importing bitcoinj mnemonic into electrum or deriving private keys from mnemonic

I am having a really hard time backing up my bitcoinj mnemonic and importing it somewhere else. I am backing up the mnemonic like so: Wallet wallet = Wallet.createDeterministic(params, Script.ScriptType.P2WPKH); DeterministicSeed seed = wallet.getKeyChainSeed(); System.out.println("seed: " + seed.toString()); System.out.println("creation time: " + seed.getCreationTimeSeconds()); System.out.println("mnemonicCode: " + Utils.SPACE_JOINER.join(seed.getMnemonicCode())); This gives me: cram approve decline tobacco truly giant remember author install dirt spare law The wallet dump for this wallet/mnemonic looks like this: Keys: Earliest creation time: 2020-09-10T23:01:55Z Seed birthday: 1599778915 [2020-09-10T23:01:55Z] Ouput script type: P2PKH Key to watch: xpub685v329L5UXezQQmCRgftKRud7hYHHR2U9RPCzRVwQNNWQuTHawgzBXD5RgAYLroJFiqTxEhF5jmbXJAWB341x8r3hdUFWfZd1Rh9uycNR3 Lookahead siz/thr: 100/33 addr:13ScJMSbxg6JYVaWNJAawZMaKW9KDdsz2H hash160:1ac81dec190ab5981f5b8d9627136c806b013ff8 (M, root) addr:18jGHhTXzKJcU1TqpMkozYQQBKHsnExT1H hash160:54c71cd14809d8e4695d0ab8881b9c971c28d833 (M/0H, account) addr:1HJbGGSZ42tG9nrTU6aGS2xJwCSEb6rKfg…

Continue Reading Importing bitcoinj mnemonic into electrum or deriving private keys from mnemonic

How to SignRawTransaction from p2sh with bitcoinj?

Looking for demo to signrawtransaction from p2sh with bitcoinj!!! This is bitcoinj code: org.bitcoinj.core.Transaction public TransactionInput addSignedInput(TransactionOutPoint prevOut, Script scriptPubKey, ECKey sigKey, Transaction.SigHash sigHash, boolean anyoneCanPay) throws ScriptException { Preconditions.checkState(!this.outputs.isEmpty(), "Attempting to sign tx without outputs."); TransactionInput input = new TransactionInput(this.params, this, new byte[0], prevOut); this.addInput(input); int inputIndex = this.inputs.size() - 1; TransactionSignature signature; if (ScriptPattern.isP2PK(scriptPubKey)) { signature = this.calculateSignature(inputIndex, sigKey, scriptPubKey, sigHash, anyoneCanPay); input.setScriptSig(ScriptBuilder.createInputScript(signature)); input.setWitness((TransactionWitness)null); } else if (ScriptPattern.isP2PKH(scriptPubKey)) { signature = this.calculateSignature(inputIndex, sigKey, scriptPubKey, sigHash, anyoneCanPay); input.setScriptSig(ScriptBuilder.createInputScript(signature, sigKey)); input.setWitness((TransactionWitness)null); } else { if (!ScriptPattern.isP2WPKH(scriptPubKey)) { throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR, "Don't know how to sign for this kind of scriptPubKey:…

Continue Reading How to SignRawTransaction from p2sh with bitcoinj?

How to get transaction info by hash using bitcoinj?

I have a transaction hash (transaction does not belong to my wallet). How can I get information about this transaction through bitcoinj API? I need information like: number of confirmations sender & receiver addresses

Continue Reading How to get transaction info by hash using bitcoinj?

getheaders request being ignored by peers [closed]

It seems my 'getheaders' request is being ignored by peers. I've followed the implementation: https://en.bitcoin.it/wiki/Protocol_documentation#getheaders without success. If I change it to 'getblocks' then it returns an inv[500] message just fine. But for some reason, it's not returning a 'headers' packet when requesting headers. I'm connected to over 100 peers, and still no success. Has anyone else had similar trouble before? Any guidance is appreciated. The request values are as follows: magic=3908297187 command=getheaders length=69 checksum=1021834552 payload=[version=70013, hashCount=1, blockLocatorHash=[00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048], hashStop=0000000000000000000000000000000000000000000000000000000000000000] and the encoded bytes are: e3e1f3e876657273696f6e000000000069000000a4d49d4e7d11010004000000000000002cb0db5d73010000000000000000000000000000000000000000ffff7f000001208d000000000000000000000000000000000000ffff0fa518f420a100ecfbdaa2585542132f626974636f696e6a2d73763a302e302e372f0000000000 Just to note, when serializing, i reverse the blockLocatorHash bytes as mentioned in the wiki.…

Continue Reading getheaders request being ignored by peers [closed]

End of content

No more pages to load