Author

Topic: Generate address (Read 2094 times)

legendary
Activity: 1708
Merit: 1066
March 16, 2012, 08:01:31 AM
#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 !

:-)
legendary
Activity: 1261
Merit: 1000
March 15, 2012, 06: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 ?


legendary
Activity: 1708
Merit: 1066
March 13, 2012, 07:56:28 AM
#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 ?

legendary
Activity: 1261
Merit: 1000
March 13, 2012, 07:49:46 AM
#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.


legendary
Activity: 1708
Merit: 1066
March 13, 2012, 07:35:49 AM
#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.

legendary
Activity: 1261
Merit: 1000
March 13, 2012, 07:33:37 AM
#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.


legendary
Activity: 1261
Merit: 1000
March 12, 2012, 08:56:23 PM
#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.


legendary
Activity: 1708
Merit: 1066
March 12, 2012, 03: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.

legendary
Activity: 1261
Merit: 1000
March 12, 2012, 02: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)


legendary
Activity: 1708
Merit: 1066
March 12, 2012, 02: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)

legendary
Activity: 1261
Merit: 1000
March 11, 2012, 08:21:43 PM
#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")))
            {
legendary
Activity: 1708
Merit: 1066
March 09, 2012, 05: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.

legendary
Activity: 1261
Merit: 1000
March 09, 2012, 05:21:06 PM
#1
Dears

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

Thank you
Jump to: