Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: btc6000 on September 24, 2013, 07:31:23 AM



Title: bitcoind - create accounts via API
Post by: btc6000 on September 24, 2013, 07:31:23 AM
There are a number of bitcoind API commands referring to [account], but how do you create, update & delete named accounts using API?

Cheers


Title: Re: bitcoind - create accounts via API
Post by: tgerring on September 24, 2013, 12:43:27 PM
Code:
getnewaddress 	[account] 	Returns a new bitcoin address for receiving payments. If [account] is specified (recommended), it is added to the address book so payments received with the address will be credited to [account]. 
Code:
setaccount 	<bitcoinaddress> <account> 	Sets the account associated with the given address. Assigning address that is already assigned to the same account will create a new address associated with that account. 

And you don't "delete" addresses, they just sit unused

https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list


Title: Re: bitcoind - create accounts via API
Post by: CIYAM on September 24, 2013, 12:51:26 PM
You should read up about Bitcoin accounts before deciding whether you really want to use them.

Some things to know are that accounts != addresses (even though the API commands are likely to lead you to believe that they are), accounts can end up with negative balances, you can't send BTC "from" the address of an account and "moves" of BTC between accounts are internal wallet operations (i.e. nothing to do with the blockchain).

Also if you are using bitcoin-qt then you are going to end up with a lot of confusion between "accounts" and "labels".


Title: Re: bitcoind - create accounts via API
Post by: tgerring on September 24, 2013, 12:58:49 PM
Shameless self-promotion, but this explains some of the reasons why developing against bitcoind can be such a pain.  http://www.ideaexcursion.com/2013/09/18/developing-against-bitcoind/

A couple of tips:

* Use listunspent, not getbalance
* Use Gavin's contrib/spendfrom script, never the `sendfrom` command


Title: Re: bitcoind - create accounts via API
Post by: icedicedavid on September 25, 2013, 11:26:10 PM
I create a new account for each users I accept deposit from with getaccountaddress

then I have a daemon that checks listaccounts for any deposits.

If deposit is found, I use move to transfer the balance to the "bank" account and credit the user.

Then the next time listaccounts is called, they will show up as 0.

All outgoing withdraw is sent via move from "bank" account to withdraw address.

Let me know if this helps.


Title: Re: bitcoind - create accounts via API
Post by: knowitnothing on September 25, 2013, 11:53:17 PM
I create a new account for each users I accept deposit from with getaccountaddress

then I have a daemon that checks listaccounts for any deposits.

That is not going to work well with thousands of accounts. Instead, properly use listsinceblock.

The reasoning for this is that making new accounts is something that happens very often, and you won't be receiving deposits from all them, so it makes little sense to use listaccounts for this task.


Title: Re: bitcoind - create accounts via API
Post by: icedicedavid on September 26, 2013, 12:05:20 AM
I create a new account for each users I accept deposit from with getaccountaddress

then I have a daemon that checks listaccounts for any deposits.

That is not going to work well with thousands of accounts. Instead, properly use listsinceblock.

The reasoning for this is that making new accounts is something that happens very often, and you won't be receiving deposits from all them, so it makes little sense to use listaccounts for this task.

thats a good point actually, thanks!


Title: Re: bitcoind - create accounts via API
Post by: tgerring on September 26, 2013, 03:21:55 PM
If you're looking for accounts with deposits, `listunspent` works might fine too.