andrehorta (OP)
Legendary
Offline
Activity: 1261
Merit: 1000
|
|
March 09, 2012, 10:21:06 PM |
|
Dears
How can i generate random address and private key using BitcoinJ?
Thank you
|
|
|
|
|
|
|
|
"Governments are good at cutting off the heads of a centrally
controlled
networks like Napster, but pure P2P networks like Gnutella and Tor seem
to be holding their own." -- Satoshi
|
|
|
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
|
|
|
|
andrehorta (OP)
Legendary
Offline
Activity: 1261
Merit: 1000
|
|
March 12, 2012, 01:21:43 AM |
|
OK, thank you, now i created the pair of keys and the address. But, i can´t download the blockchain, still showing for me: "Bad version number: 250"
var @params = NetworkParameters.TestNet();// : NetworkParameters.ProdNet();
EcKey chaves = resgatarParChaves(chavePrimaria); Wallet carteira = criarCarteira(chaves); using (var blockStore = new BoundedOverheadBlockStore(@params, new FileInfo(@"C:\Users\André\AppData\Roaming\Bitcoin\testnet\blk0001.dat"))) {
//error on this line: using (var blockStore = new BoundedOverheadBlockStore(@params, new FileInfo(@"C:\Users\André\AppData\Roaming\Bitcoin\testnet\blk0001.dat"))) {
|
|
|
|
jim618
Legendary
Offline
Activity: 1708
Merit: 1066
|
|
March 12, 2012, 07:57:50 AM |
|
The format and contents of the blockchain in the Satoshi client and in bitcoinj are completely different. I would advise keeping your files in a separate directory in your roaming profile directory. By calling the bitcoinj blockchain blk001.dat and putting it in the bitcoin directory you risk getting the wrong files being used by your program and the Satoshi client. This is most likely what is causing your error report. For your application I would create a directory specially for it in your roaming profile as you will no doubt want to put your configuration data and settings in there as you develop your app. It is a bit idiosyncratic where the user application data is stored on different operating systems. I have written a little help note for it for multibit (which you can easily adapt) here: http://multibit.org/help_troubleshooting.htmlIt is just a convention but both bitcoinj and multibit (based on bitcoinj) call their blockchains: *.blockchain You also want to distinguish between the production and test blockchains (you are doing this already in your path name but I wanted to mention it)
|
|
|
|
andrehorta (OP)
Legendary
Offline
Activity: 1261
Merit: 1000
|
|
March 12, 2012, 07:53:40 PM |
|
Thank you for your help... I downloaded the multitbit (it´s very nice!) and run -testnet. Later a put my program to C:\Users\André\AppData\Roaming\MultiBit.blockchain and when ai try:Address endereco = new Address(@params, destino); or peerGroup.DownloadBlockChain(); the error message apper: Mismatched version number, trying to cross networks? 0 vs 111 The format and contents of the blockchain in the Satoshi client and in bitcoinj are completely different. I would advise keeping your files in a separate directory in your roaming profile directory. By calling the bitcoinj blockchain blk001.dat and putting it in the bitcoin directory you risk getting the wrong files being used by your program and the Satoshi client. This is most likely what is causing your error report. For your application I would create a directory specially for it in your roaming profile as you will no doubt want to put your configuration data and settings in there as you develop your app. It is a bit idiosyncratic where the user application data is stored on different operating systems. I have written a little help note for it for multibit (which you can easily adapt) here: http://multibit.org/help_troubleshooting.htmlIt is just a convention but both bitcoinj and multibit (based on bitcoinj) call their blockchains: *.blockchain You also want to distinguish between the production and test blockchains (you are doing this already in your path name but I wanted to mention it)
|
|
|
|
jim618
Legendary
Offline
Activity: 1708
Merit: 1066
|
|
March 12, 2012, 08:22:16 PM |
|
Hi Andre, The startup parameters to get multibit to run in test is slightly different from the Satoshi client - it is set in a properties file. The details are here: https://github.com/jim618/multibit/blob/master/READMEThe test blockchain has a 'test' in the name to distinguish it from the production "multibit.blockchain" which I think is the one you are using.
|
|
|
|
andrehorta (OP)
Legendary
Offline
Activity: 1261
Merit: 1000
|
|
March 13, 2012, 01:56:23 AM |
|
I change the propert file as you said, but: 1) When i use: NetworkParameters.TestNet() On this line: Address endereco = new Address(@params, destino); This error message: Mismatched version number, trying to cross networks? 0 vs 111 or On this line: peerGroup.DownloadBlockChain(); This error message: Non-negative number required. Parameter name: maximumCount 2) When i use: NetworkParameters.ProdNet() On this line: peerGroup.DownloadBlockChain(); This error message: Non-negative number required. Parameter name: maximumCount or Line: var sendTx = carteira.SendCoins(peerGroup, endereco, carteira.GetBalance()); Error: Failed to broadcast tx to all connected peers Can you help me? Thks Hi Andre, The startup parameters to get multibit to run in test is slightly different from the Satoshi client - it is set in a properties file. The details are here: https://github.com/jim618/multibit/blob/master/READMEThe test blockchain has a 'test' in the name to distinguish it from the production "multibit.blockchain" which I think is the one you are using.
|
|
|
|
andrehorta (OP)
Legendary
Offline
Activity: 1261
Merit: 1000
|
|
March 13, 2012, 12:33:37 PM |
|
OK, now the first problem i was found the solution: 1)This error message: Mismatched version number, trying to cross networks? 0 vs 111 I tried to use a test address with a production network, and it can´t do. Test address with test network and production address with production network, now this is fine. But, the error bellow still continue: On this line: peerGroup.DownloadBlockChain(); This error message: Non-negative number required. Parameter name: maximumCount or Line: var sendTx = carteira.SendCoins(peerGroup, endereco, carteira.GetBalance()); Error: Failed to broadcast tx to all connected peersI change the propert file as you said, but: 1) When i use: NetworkParameters.TestNet() On this line: Address endereco = new Address(@params, destino); This error message: Mismatched version number, trying to cross networks? 0 vs 111 or On this line: peerGroup.DownloadBlockChain(); This error message: Non-negative number required. Parameter name: maximumCount 2) When i use: NetworkParameters.ProdNet() On this line: peerGroup.DownloadBlockChain(); This error message: Non-negative number required. Parameter name: maximumCount or Line: var sendTx = carteira.SendCoins(peerGroup, endereco, carteira.GetBalance()); Error: Failed to broadcast tx to all connected peers Can you help me? Thks Hi Andre, The startup parameters to get multibit to run in test is slightly different from the Satoshi client - it is set in a properties file. The details are here: https://github.com/jim618/multibit/blob/master/READMEThe test blockchain has a 'test' in the name to distinguish it from the production "multibit.blockchain" which I think is the one you are using.
|
|
|
|
jim618
Legendary
Offline
Activity: 1708
Merit: 1066
|
|
March 13, 2012, 12:35:49 PM |
|
With your PeerGroup errors I think it is due to initialisation. If you have a look at the multibit class that does my PeerGroup initialisation it will help: https://github.com/jim618/multibit/blob/v0.3/src/main/java/org/multibit/network/MultiBitService.javaHave a look at the constructor and createNewPeerGroup method. The main points are: + You need to set the maximum number of Peers for the PeerGroup. (This is probably causing your error). + You need to specify either the Peers to connect to (i.e. explicitly) or set the method of PeerDiscovery. (how to find peers). When the PeerGroup starts up it will take a few seconds to discovery the peers, open a socket to them etc. You will not be able to send straight away so the best thing to do is attach a PeerEventListener which tells you things like: + PeerGroup found a new peer + PeerGroup lost a peer + number of active peers. Once your PeerGroup is initialised and has an active Peer you will be in a position to send. (P.S. The bitcoinj code - which I presume the C# code is a port of - does not allow for the addition of fees to sends. It is on Mike's todo list. If you want to do a simple 'just add 0.005 BTC" have a look at the method: https://github.com/jim618/multibit/blob/v0.3/src/main/java/com/google/bitcoin/core/Wallet.java completeTx It simply sends a little bit more/ does not take as much back in change to give the miner the fee.
|
|
|
|
andrehorta (OP)
Legendary
Offline
Activity: 1261
Merit: 1000
|
|
March 13, 2012, 12:49:46 PM |
|
OK, i will read carefull... One question, what ip address i need to put here: peerGroup.AddAddress(new PeerAddress(IPAddress.Loopback)); With your PeerGroup errors I think it is due to initialisation. If you have a look at the multibit class that does my PeerGroup initialisation it will help: https://github.com/jim618/multibit/blob/v0.3/src/main/java/org/multibit/network/MultiBitService.javaHave a look at the constructor and createNewPeerGroup method. The main points are: + You need to set the maximum number of Peers for the PeerGroup. (This is probably causing your error). + You need to specify either the Peers to connect to (i.e. explicitly) or set the method of PeerDiscovery. (how to find peers). When the PeerGroup starts up it will take a few seconds to discovery the peers, open a socket to them etc. You will not be able to send straight away so the best thing to do is attach a PeerEventListener which tells you things like: + PeerGroup found a new peer + PeerGroup lost a peer + number of active peers. Once your PeerGroup is initialised and has an active Peer you will be in a position to send. (P.S. The bitcoinj code - which I presume the C# code is a port of - does not allow for the addition of fees to sends. It is on Mike's todo list. If you want to do a simple 'just add 0.005 BTC" have a look at the method: https://github.com/jim618/multibit/blob/v0.3/src/main/java/com/google/bitcoin/core/Wallet.java completeTx It simply sends a little bit more/ does not take as much back in change to give the miner the fee.
|
|
|
|
jim618
Legendary
Offline
Activity: 1708
Merit: 1066
|
|
March 13, 2012, 12:56:28 PM |
|
Not sure that that loopback address is for . . .
Generally if you are adding explicit IP addresses then you are hardwiring a connection to a particular node. Perhaps that code example is assuming you are connecting to a bitcoind running on localhost ?
|
|
|
|
andrehorta (OP)
Legendary
Offline
Activity: 1261
Merit: 1000
|
|
March 15, 2012, 11:49:03 AM |
|
I think equals you. But the question still continue, what IP is correct to fill? Not sure that that loopback address is for . . .
Generally if you are adding explicit IP addresses then you are hardwiring a connection to a particular node. Perhaps that code example is assuming you are connecting to a bitcoind running on localhost ?
|
|
|
|
jim618
Legendary
Offline
Activity: 1708
Merit: 1066
|
|
March 16, 2012, 01:01:31 PM |
|
if you were NOT intending to run a bitcoind for your application, then you do not need to add it to the PeerGroup. If you ARE and your network configuration on your computer is simple, probably 127.0.0.1 will do it.
If you have multiple network cards on your PC, then I do not know !
:-)
|
|
|
|
|