Bitcoin Forum
December 06, 2016, 08:04:18 PM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Generate address  (Read 1807 times)
andrehorta
Legendary
*
Offline Offline

Activity: 1120

Compre e venda bitcoins: www.bitcointoyou.com


View Profile WWW
March 09, 2012, 10:21:06 PM
 #1

Dears

How can i generate random address and private key using BitcoinJ?

Thank you

Compre e venda bitcoin com segurança de uma empresa séria: https://www.bitcointoyou.com
Transações e confirmações rápidas!
1481054658
Hero Member
*
Offline Offline

Posts: 1481054658

View Profile Personal Message (Offline)

Ignore
1481054658
Reply with quote  #2

1481054658
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481054658
Hero Member
*
Offline Offline

Posts: 1481054658

View Profile Personal Message (Offline)

Ignore
1481054658
Reply with quote  #2

1481054658
Report to moderator
jim618
Legendary
*
Offline Offline

Activity: 1708



View Profile WWW
March 09, 2012, 10:30:59 PM
 #2

There are some good examples of using bitcoinj in the com.google.examples package.

For instance if you look at the 'ToyWallet' you can see a new ECKey being generated (new private key) and then its translation into an address:

http://code.google.com/p/bitcoinj/source/browse/src/com/google/bitcoin/examples/toywallet/ToyWallet.java

These are Java but I think from your posting on the bitcoinj mailing list you are using C# so you will have to change things accordingly.


MultiBit HD   Lightweight desktop client.                    Bitcoin Solutions Ltd   Bespoke software. Consultancy.
andrehorta
Legendary
*
Offline Offline

Activity: 1120

Compre e venda bitcoins: www.bitcointoyou.com


View Profile WWW
March 12, 2012, 01:21:43 AM
 #3

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")))
            {

Compre e venda bitcoin com segurança de uma empresa séria: https://www.bitcointoyou.com
Transações e confirmações rápidas!
jim618
Legendary
*
Offline Offline

Activity: 1708



View Profile WWW
March 12, 2012, 07:57:50 AM
 #4

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.html

It 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)


MultiBit HD   Lightweight desktop client.                    Bitcoin Solutions Ltd   Bespoke software. Consultancy.
andrehorta
Legendary
*
Offline Offline

Activity: 1120

Compre e venda bitcoins: www.bitcointoyou.com


View Profile WWW
March 12, 2012, 07:53:40 PM
 #5

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.html

It 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)



Compre e venda bitcoin com segurança de uma empresa séria: https://www.bitcointoyou.com
Transações e confirmações rápidas!
jim618
Legendary
*
Offline Offline

Activity: 1708



View Profile WWW
March 12, 2012, 08:22:16 PM
 #6

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/README

The 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.


MultiBit HD   Lightweight desktop client.                    Bitcoin Solutions Ltd   Bespoke software. Consultancy.
andrehorta
Legendary
*
Offline Offline

Activity: 1120

Compre e venda bitcoins: www.bitcointoyou.com


View Profile WWW
March 13, 2012, 01:56:23 AM
 #7

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/README

The 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.



Compre e venda bitcoin com segurança de uma empresa séria: https://www.bitcointoyou.com
Transações e confirmações rápidas!
andrehorta
Legendary
*
Offline Offline

Activity: 1120

Compre e venda bitcoins: www.bitcointoyou.com


View Profile WWW
March 13, 2012, 12:33:37 PM
 #8

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 peers



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/README

The 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.



Compre e venda bitcoin com segurança de uma empresa séria: https://www.bitcointoyou.com
Transações e confirmações rápidas!
jim618
Legendary
*
Offline Offline

Activity: 1708



View Profile WWW
March 13, 2012, 12:35:49 PM
 #9

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.java

Have 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.


MultiBit HD   Lightweight desktop client.                    Bitcoin Solutions Ltd   Bespoke software. Consultancy.
andrehorta
Legendary
*
Offline Offline

Activity: 1120

Compre e venda bitcoins: www.bitcointoyou.com


View Profile WWW
March 13, 2012, 12:49:46 PM
 #10

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.java

Have 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.



Compre e venda bitcoin com segurança de uma empresa séria: https://www.bitcointoyou.com
Transações e confirmações rápidas!
jim618
Legendary
*
Offline Offline

Activity: 1708



View Profile WWW
March 13, 2012, 12:56:28 PM
 #11

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 ?


MultiBit HD   Lightweight desktop client.                    Bitcoin Solutions Ltd   Bespoke software. Consultancy.
andrehorta
Legendary
*
Offline Offline

Activity: 1120

Compre e venda bitcoins: www.bitcointoyou.com


View Profile WWW
March 15, 2012, 11:49:03 AM
 #12

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 ?



Compre e venda bitcoin com segurança de uma empresa séria: https://www.bitcointoyou.com
Transações e confirmações rápidas!
jim618
Legendary
*
Offline Offline

Activity: 1708



View Profile WWW
March 16, 2012, 01:01:31 PM
 #13

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 !

:-)

MultiBit HD   Lightweight desktop client.                    Bitcoin Solutions Ltd   Bespoke software. Consultancy.
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!