Is it possible to create wallet via API?

Hi,

I want to create a wallet by using API. Blockchain.info has a create wallet API. I prefered to use similar one. https://blockchain.info/api/create_wallet

I already read counter party's API document but it does not seem to provide it. http://counterparty.io/docs/counterpartyd/#sign-tx

Any help will be appreciated.

Thanks.
3

Hi


Go to Github and look up the way Counterwallet creates address when  you click on Create New Wallet.

Cheers
@something

Thank you so much for your answer. Could I ask one more question? As far as I searched a whole day, having my own federated node seems to be necessary for running Counterwallet. Is it right?
 
I expected that I can create a new wallet or sending assets to someone by connecting public system like devtest.counterparty.io. It is very hard to prepare my own federated node for me...

What I want to do are following 3 things:

1. Check the amount of asset by address. 
> No problem. I can use blockscan api.

2. Send asset to someone by address. 
> counterpartyd's reference client written by python seems to be useful. But I may have to run my own federated node.

3. Create new wallet via API. 
> I can refer the counterparty wallet. But this is also I may need to run my own federated node.

Thanks
10

@zono, the wallet may need to read a variety of different blocks from the bitcoin blockchain (e.g. a user logs in and how can CW tell his BTC balance on any particular address?) so there’s quite a lot of interaction between the two.

I think (I haven’t tried) there’s an option to select one of online blockchain API’s and use that (so, no need for bitcoind), but in that case you have to be ready for potentially slower response and other issues. You can check setup_federated_node.py in counterpartyd_build repo on Github to see the contents of the setup wizard (or just download and execute the script and see whether you can pick a Web-based blockchain API).

Regarding #3, I think you’ll see the wallet creating code can be isolated into your own page/script, you don’t need to run CW just to create a new wallet. So if you want to have your own secure method to allow people to access their assets and send them to other people, you could use your own scripts/code and just use the part of Counterwallet that you need.
@something

Thank you again. I realized that I had a little understanding of counterparty and bitcoin system. OK, I will try to setup counterpartyd tomorrow and I will read all of the documents.

Regarding #3. I understood that I don't need to run CW just to create a new wallet. But counterpartyd is still needed, right?
 
I have an Android app. I am trying to use my counterparty's asset into the app. When the users of the app do something, they can get our asset as a point.

I wanted to use public API like Blockchain.info even though we will face slower response and other issues. The main reason is I don't want to have my own server. However, I think there is no options for now. I will make my own scripts/code and I will call it from the Android app.

Thanks,
6
@something

Hi, I think I could install counterpartyd and run it properly. However, I got a connection refused error like below even though counterpartyd is running. I would be grateful if you could give me any advices.

What I did:

1. Clean install Ubuntu 14.04 amd64

2. wget and execute "sudo python3 setup_federated_node.py"

3. Check rpc user/password from counterpartyd.conf and then execute the curl command.

That's all..

----------------------------------

$ ps -ef | grep counterparty
root      2779  7304  0 08:45 ?        00:00:00 runsv counterpartyd

$ ps -ef | grep ng
root     17453  7304  0 09:00 ?        00:00:00 runsv nginx

$ curl http://127.0.0.1:4000/api/ --user rpc:xxxxx -H 'Content-Type: application/json; charset=UTF-8' -H 'Accept: application/json, text/javascript' --data-binary '{"jsonrpc":"2.0","id":0,"method":"get_running_info"}'
curl: (7) Failed to connect to 127.0.0.1 port 4000: Connection refused

$ netstat -at
(port 4000 does not exist)

Thanks,

@zono


I assume you also setup Bitcoin Core according to this:
http://counterparty.io/docs/build-system/set-up-bitcoind/
To build Bitcoin Core with Addrindex see this guide (the part for Ubuntu 14.04):
https://wiki.counterparty.io/w/Bitcoind_v0.92_with_addrindex_patch_(Windows_2012_R2_and_Ubuntu_14.04)
NOTE: don’t forget, you need addrindex=1 in your bitcoin.conf!

If you have 40GB free in /home/xcp, then you can start bitcoind:
$ sudo bitcoind -conf=/home/xcp/.bitcoin/bitcoin.conf

Now you need to wait for 1 day :slight_smile:

$ tail -f /home/xcp/.bitcoin/debug.log

bitcoind will take a long time until it catches up (e.g. block (“height” in debug.log) 336000.

As soon as bitcoind is working (it doesn’t need to be up to date), you can start counterpartyd as the “xcp” user:

$ counterpartyd server

Then as the user xcp monitor counterpartyd log:

$ tail -f /home/xcp/.config/counterpartyd/counterpartyd.log

If counterpartyd fails, check your counterpartyd.conf and bitcoin.conf (see the bottom of this page):
https://wiki.counterparty.io/w/Bitcoind_v0.92_with_addrindex_patch_(Windows_2012_R2_and_Ubuntu_14.04) <= this is all one URL
Remember to use your own passwords and not the default values.

counterpartyd server will do nothing until the blockchain is up to 288000, so it will just stay connected. Around the block 288000 it will start showing transactions. You can download a recent version of counterparty DB (see http://support.counterparty.io/support/solutions/articles/5000006746-download-and-creation-of-counterparty-db-is-too-slow-) but it will not save you much time because bitcoind takes a long time to download around 30GB of data.
If you download the DB, you need to have counterpartyd stopped and then move the downloaded file to 

/home/xcp/.config/counterpartyd/counterpartyd

Then in that directory decompress it with “tar xfzv FILENAME”. Then you can start counterpartyd (counterpartyd server).
The server can be stopped with CTRL+C.

Once both bitcoind and counterpartyd are up to date, open another console and try to use it. 

Let me know if you have any problems!

@something

Hi, blockchain downloading has been completed. It took 2 days... Anyway, I got an another error when I tried to start counterpartyd. Could you take a look below?

My problem:

I cannot start counterpartyd server

What I did:

1. command "counterpartyd server"

$ counterpartyd server
Traceback (most recent call last):
  File "/home/xcp/counterpartyd_build/dist/counterpartyd/counterpartyd.py", line 613, in
    force=args.force)
  File "/home/xcp/counterpartyd_build/dist/counterpartyd/counterpartyd.py", line 235, in set_options
    raise exceptions.ConfigurationError('backend RPC password not set. (Use configuration file or --backend-rpc-password=PASSWORD)')
AttributeError: 'module' object has no attribute 'ConfigurationError'

2. command "counterpartyd server" with config-file

$ counterpartyd server --config-file=/home/xcp/.config/counterpartyd/counterpartyd.conf 
usage: counterpartyd [-h] [-V] [-v] [--testnet] [--testcoin]
                     [--carefulness CAREFULNESS] [--unconfirmed]
                     [--encoding ENCODING] [--fee-per-kb FEE_PER_KB]
                     [--regular-dust-size REGULAR_DUST_SIZE]
                     [--multisig-dust-size MULTISIG_DUST_SIZE]
                     [--op-return-value OP_RETURN_VALUE] [--unsigned]
                     [--data-dir DATA_DIR] [--database-file DATABASE_FILE]
                     [--config-file CONFIG_FILE] [--log-file LOG_FILE]
                     [--backend-rpc-connect BACKEND_RPC_CONNECT]
                     [--backend-rpc-port BACKEND_RPC_PORT]
                     [--backend-rpc-user BACKEND_RPC_USER]
                     [--backend-rpc-password BACKEND_RPC_PASSWORD]
                     [--backend-rpc-ssl] [--backend-rpc-ssl-verify]
                     [--blockchain-service-name BLOCKCHAIN_SERVICE_NAME]
                     [--blockchain-service-connect BLOCKCHAIN_SERVICE_CONNECT]
                     [--rpc-host RPC_HOST] [--rpc-port RPC_PORT]
                     [--rpc-user RPC_USER] [--rpc-password RPC_PASSWORD]
                     [--rpc-allow-cors]
                     {server,send,order,btcpay,issuance,broadcast,bet,dividend,burn,cancel,callback,rps,rpsresolve,publish,execute,reparse,rollback,kickstart}
                     ...
counterpartyd: error: unrecognized arguments: --config-file=/home/xcp/.config/counterpartyd/counterpartyd.conf

FYI

1. I also tried followings but I got same results.

$ counterpartyd server --config_file=/home/xcp/.config/counterpartyd/counterpartyd.conf 

$ counterpartyd server --backend-rpc-password=hoge

$ counterpartyd server --backend_rpc_password=hoge

2 I don't know if it is affected or not..
 
My server has two users; xcp and zono. I run "sudo bitcoind" in zono's home directory. And then blockchain is stored in /home/zono/.bitcoin/blocks

Thanks for your thoughtful responses.

Zono

@zono, you made a mistake reading the config file option.


It’s 
–config-file /home/xcp/.config/counterpartyd/counterpartyd.conf
not
–config-file=/home/xcp/.config/counterpartyd/counterpartyd.conf

Also omit “=” in other parameters. You can create a script in /home/xcp such as counterpartyd-start.sh.

#!/bin/bash
counterpartyd -config /home/xcp/.config/counterpartyd/counterpartyd.conf

Then
$ chmod 700 counterpartyd-start.sh

Now you can run it with:
$ ./counterpartyd-start.sh

Try to change that first and then report any other errors that you may have.

I assume your bitcoin is running fine. You can tail the bitcoin debug log or execute this to check:

$ bitcoind getinfo

@something

Hi, thanks always. I am still in trouble... Just I want to connect to port 4000 but it does not work.

My problem:

RPC Port (4000) does not open. Backend RPC Port (8332) is open normally. 

What I did:

1. /home/xcp/counterpartyd_build/env/bin/python /home/xcp/counterpartyd_build/dist/counterpartyd/counterpartyd.py server

WARNING:root:Config file: /home/zono/.config/counterpartyd/counterpartyd.conf; Exists: Yes
INFO:root:Status: Running v9.48.0 of counterpartyd.
Status: Running v9.48.0 of counterpartyd.
INFO:root:Status: Checking version.
Status: Checking version.
Traceback (most recent call last):
  File "/home/xcp/counterpartyd_build/dist/counterpartyd/counterpartyd.py", line 663, in
    util.version_check(bitcoin.get_block_count())
  File "/home/xcp/counterpartyd_build/dist/counterpartyd/lib/util.py", line 440, in version_check
    raise VersionUpdateRequiredError(explanation)
lib.util.VersionUpdateRequiredError: Your version of counterpartyd is v9.48.0, but, as of block 334000, the minimum version is v9.49.0. Reason: ‘hotfix: numeric asset names’. Please upgrade to the latest version and restart the server.

2. Kill counterpartyd process for restart.

I got these errors when I executed "kill -9 PROCESS".

root     32631     1  0 11:05 ?        00:00:00 runsvdir -P /etc/service log: yd_build/dist/counterpartyd/counterpartyd.py", line 628, in     force=args.force)   File "/home/xcp/counterpartyd_build/dist/counterpartyd/counterpartyd.py", line 249, in set_options     raise exceptions.ConfigurationError('backend RPC password not set. (Use configuration file or --backend-rpc-password=PASSWORD)') AttributeError: 'module' object has no attribute 'ConfigurationError' 
root      1113     1  0 11:08 ?        00:00:00 runsvdir -P /etc/service log: /lock: temporary failure runsv counterblockd: fatal: unable to lock supervise/lock: temporary failure runsv nginx: fatal: unable to lock supervise/lock: temporary failure runsv counterpartyd: fatal: unable to lock supervise/lock: temporary failure runsv mongod: fatal: unable to lock supervise/lock: temporary failure runsv armory_utxsvr: fatal: unable to lock supervise/lock: temporary failure 

How can I restart counterpartyd.

FYI

1. Bitcoind works properly.

$bitcoind getinfo
{
    "version" : 90200,
    "protocolversion" : 70002,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 334409,
    "timeoffset" : 0,
    "connections" : 41,
    "proxy" : "",
    "difficulty" : 40007470271.27126312,
    "testnet" : false,
    "keypoololdest" : 1418315302,
    "keypoolsize" : 101,
    "paytxfee" : 0.00000000,
    "relayfee" : 0.00001000,
    "errors" : ""
}

2. When I executed this script, I got this error.. I do not why.  "counterpartyd: error: unrecognized arguments: --config-file /home/xcp/.config/counterpartyd/counterpartyd.conf"

#!/bin/bash
counterpartyd server --config-file /home/xcp/.config/counterpartyd/counterpartyd.conf

3. My config file.

/home/zono/.config/counterpartyd/counterpartyd.conf

[Default]
backend-rpc-connect=localhost
backend-rpc-port=8332
backend-rpc-user=rpc
backend-rpc-password=xxx
rpc-host=localhost
rpc-port=4000
rpc-user=rpc
rpc-password=xxx
blockchain-service-name=jmcorgan
I found this error below. What is this?

$ sudo tail -f ~xcp/.config/counterblockd/counterblockd.log
2014-12-15-T12:21:08+0000 Got call_jsonrpc_api request error: [Errno 111] Connection refused -- Waiting 3 seconds before trying again...
2014-12-15-T12:21:11+0000 Got call_jsonrpc_api request error: [Errno 111] Connection refused -- Waiting 3 seconds before trying again...
2014-12-15-T12:21:14+0000 Got call_jsonrpc_api request error: [Errno 111] Connection refused -- Waiting 3 seconds before trying again...

Hi Zono

  1. Your version of counterpartyd is v9.48.0, but, as of block 334000, the minimum version is v9.49.0. Reason: ‘hotfix: numeric asset names’. Please upgrade to the latest version and restart the server.

This is telling you you need to update to v9.49, so just run the setup part again (remove counterparty_build directory and check out from Github and run setup.py again - you do not have to change any config files after that, just run “counterpartyd server”)

  1. You installed in a non-default directory so just change “/home/xcp/” to “/home/zono” in your config file path (after you update).

  2. Connection refused simply means the port is not open (and it’s not open because counterparty is not running)

I found this error below. What is this?

> $ sudo tail -f ~xcp/.config/counterblockd/counterblockd.log
2014-12-15-T12:21:08+0000 Got call_jsonrpc_api request error: [Errno 111] Connection refused – Waiting 3 seconds before trying again…

I think that means counterblockd is not able to connect (because counterpartyd is not running).
I’ve never tailed that log because I’ve never seen counterpartyd work while counterblockd doesn’t. Just make sure counterpartyd can work and it’ll be fine. You don’t need to monitor counterblockd on its own.

@something

Hi, I am stil struggling to set up counterpartyd. :slight_smile:

I have changed to step by step approach. But unfortunately, I encountered another issue… Could you take a look please…?

My problem:

I got “Integrity check failed.” error when I tried to start counterpartyd.

When I did:

  1. Clean install Ubuntu 14.04 amd64

  2. Install bitcoind and run.

cd ~
sudo apt-get install software-properties-common python-software-properties
sudo add-apt-repository ppa:bitcoin/bitcoin
sudo apt-get update
sudo apt-get install bitcoind
mkdir -p ~/.bitcoin/
echo -e “rpcuser=rpc
rpcpassword=1234
server=1
daemon=1
txindex=1” > ~/.bitcoin/bitcoin.conf

bitcoind

  1. Install Counterpartyd and run.

cd ~
sudo apt-get -y update
sudo apt-get -y install git-core python3
git clone https://github.com/CounterpartyXCP/counterpartyd_build ~/counterpartyd_build
cd ~/counterpartyd_build
sudo python3 setup.py --with-bootstrap-db

counterpartyd server

  1. I got this error below.

$ counterpartyd server
Status: Running v9.49.1 of counterpartyd.
Status: Checking version.
Status: Acquiring lock.
Status: Connecting to database.
Traceback (most recent call last):
File “/home/xcp/counterpartyd_build/dist/counterpartyd/lib/util.py”, line 376, in connect_to_db
raise exceptions.DatabaseError(‘Integrity check failed.’)
lib.exceptions.DatabaseError: Integrity check failed.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/xcp/counterpartyd_build/dist/counterpartyd/counterpartyd.py”, line 660, in
db = util.connect_to_db()
File “/home/xcp/counterpartyd_build/dist/counterpartyd/lib/util.py”, line 379, in connect_to_db
except exceptions.DatabaseIntegrityError:
AttributeError: ‘module’ object has no attribute ‘DatabaseIntegrityError’

  1. Added a debug message

    368 # Integrity check
    369 integral = False
    370 for i in range(10): # DUPE
    371 try:
    372 logging.debug(‘Status: Checking database integrity.’)
    373 cursor.execute(’’‘PRAGMA integrity_check’’’)
    374 rows = cursor.fetchall()
    375
    376 logging.warning(rows[0][0]) # ADDED THIS DEBUG
    377
    378 if not (len(rows) == 1 and rows[0][0] == ‘ok’):
    379 raise exceptions.DatabaseError(‘Integrity check failed.’)

I put “logging.warning(rows[0][0])” and run again. Then I got this message below.

2014-12-17-T18:27:30+0900 Status: Running v9.49.1 of counterpartyd.
2014-12-17-T18:27:30+0900 Status: Checking version.
2014-12-17-T18:27:30+0900 Status: Acquiring lock.
2014-12-17-T18:27:30+0900 Status: Connecting to database.
2014-12-17-T18:37:04+0900 *** in database main ***
On page 3270 at right child: 2nd reference to page 415253
Page 415262 is never used

FYI

1. Blockchain syncing is not finished but I guess that it is not relevant to sqlite integrity_check error.

$ bitcoind getinfo
{
    "version" : 90300,
    "protocolversion" : 70002,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 285259,
    "timeoffset" : -1,
    "connections" : 39,
    "proxy" : "",
    "difficulty" : 2621404453.06461525,
    "testnet" : false,
    "keypoololdest" : 1418654127,
    "keypoolsize" : 101,
    "paytxfee" : 0.00000000,
    "relayfee" : 0.00001000,
    "errors" : ""
}

2. I may be able to find ways to fix the sqlite db. But I wanted ask you if you experienced the same problem or not.

I am sorry for asking questions many times.

Thanks,

Hi


Fixed the db error by like this.

$ sqlite3 mydata.db “.dump” | sqlite3 new.db

And then, port 4000 is open now eventually. 

Thanks a lot!!

Great to hear that, @zono


Let us know if you encounter any other issue!

Hello @something

I could use all counterpartyd Read API. See my blog if you can read Japanese :) http://www.yzono.com/

By the way, I thought that the next step was the Action/Write API but I realized it was wrong. Because I don't have private key of my bitcoin address generated by https://counterwallet.io.

My questions:

1. Can I get the secret key from the mnemonic phrase I made when I registered on https://counterwallet.io?

2. If I can get the private key by the question1's way, Can I use the key on my server running counterpartyd?

FYI:

I tried to enter the mnemonic phrase on Blockchain.info to get private key but didn't accept it.

I think that next step is starting counterblockd and then installing counterparty wallet. Counterparty wallet needs counterblockd, doesn't it? It is a little bit long way.. I will complete it by Christmas :)

Thanks,

@zono, sumimasen, kantan no mono dake! I will check your blog!

  1. I wrote a how-to here. You can use this approach to pre-generate addresses and private keys as well.
    Is it possible to create list of addresses and private keys from Counterwallet pass phrase?
  2. I am not quite sure that blockchain.info wallet uses the same deterministic approach and the same word list, if it doesn’t then it wouldn’t be possible to use the Counterwallet pass phrase to access that wallet.

When you start Bitcoin and then “counterpartyd server” no other services should require to be started manually, so I think counterblockd is already running (since the API works).

“ps -ef | grep block” may give you the answer (I am on a tablet now so I cannot give you an idea how it looks on my PC).

@something, Hi, your Japanese is very well. I can understand it!
 
Anyway, thanks to your clear explanation, I got my private key by using CounterWalletHelper.py.
 
And then, I got another problem below. I guess I should prepare jmcorgan and Insight. I will install Insight from now. I'm not sure how to set up jmcorgan..
   
$ counterpartyd send --source "17sdLuNtD7ZpFCVZ3Doz58fwxFF6i6CKk2" --destination "1GfcF1LSQagv65VQ1n66UAn9NF1TKmepcM" --quantity 1 --asset "XZCOIN"
Status: Running v9.49.1 of counterpartyd.
Status: Connecting to database.
Source not in backend wallet.
Public key (hexadecimal) or Private key (Wallet Import Format): XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Traceback (most recent call last):
  File "/home/xcp/counterpartyd_build/dist/counterpartyd/counterpartyd.py", line 675, in
    args.unsigned)
  File "/home/xcp/counterpartyd_build/dist/counterpartyd/counterpartyd.py", line 112, in cli
    unsigned_tx_hex = util.api(method, params)
  File "/home/xcp/counterpartyd_build/dist/counterpartyd/lib/util.py", line 66, in api
    raise RPCError('{}'.format(response_json['error']))
lib.util.RPCError: {'code': -32000, 'data': {'type': 'BitcoindRPCError', 'args': ['Unknown RPC command: `searchrawtransactions`. Either, switch to jmcorgan (recommended), use Insight, or use sochain or blockr.'], 'message': 'Unknown RPC command: `searchrawtransactions`. Either, switch to jmcorgan (recommended), use Insight, or use sochain or blockr.'}, 'message': 'Server error'}
 
FYI:

I said "I could use all counterpartyd Read API".. this is just counterpartyd Read API. not counterblockd.

I set up counterpartyd again because I didn't include counterblockd before.

(before)
sudo python3 setup.py --with-bootstrap-db

(now)
sudo python3 setup.py --with-bootstrap-db --with-counterblockd

And then, I did "sudo sv start counterpartyd" however port 4001 was not open. (port 4000 is open). Is there a launching script for counterblockd.. ? (but counterblockd is not needed for just sending asset to someone, right?)

ps -ef | grep block
root        27     2  0 11:57 ?        00:00:00 [kblockd]
root       776   770  0 11:57 ?        00:00:00 runsv counterblockd
xcp       1164  1008  0 13:57 pts/1    00:00:00 grep --color=auto block

I will inform to you my progress later.
 
Thanks,