Author

Topic: block.io - create new address for existing label (Read 144 times)

hero member
Activity: 882
Merit: 5834
not your keys, not your coins!
December 05, 2022, 03:40:15 PM
#9
Of course, this is just a proof of concept to show you how it's done. You'd want to keep track of each user's highest used address index e.g. in a database, fetch that number, increment by one, save it to DB again, construct the new address label and fetch a new address with that label from your wallet provider.
Accumulating balances would just require you to query all userA-* addresses and add the results. I don't see a problem with that.

The more you think about it, the clearer the picture becomes. The only question is whether it is the best practice solution?
Suppose a user would like to one day pay off his entire balance, which is shown to him from the database but is located at, say, 4 addresses. Doesn't he then pay transaction fees four times? Another question that comes to my mind now: How do I deal with the accumulated credit on different addresses of a user in advance?
You could do a variety of things. Centralized exchanges send all deposited funds to one or two 'internal' exchange wallets, and just keep track of user balances as a number in a database. When a user withdraws, they check what amount they own and pay out from the internal wallet. They also batch payments, i.e. using one input and multiple outputs, they pay out lots of users in a single transaction.

More about inputs / outputs here: link and link.

This means if you don't use the exchange model, you can also use multiple balances of a user (in your example 4) as inputs and send them to one output address. That saves fees compared to doing 4 individual transactions, but costs more than a 1-input transaction due to taking up more space on the blockchain.
newbie
Activity: 5
Merit: 1
Of course, this is just a proof of concept to show you how it's done. You'd want to keep track of each user's highest used address index e.g. in a database, fetch that number, increment by one, save it to DB again, construct the new address label and fetch a new address with that label from your wallet provider.
Accumulating balances would just require you to query all userA-* addresses and add the results. I don't see a problem with that.

The more you think about it, the clearer the picture becomes. The only question is whether it is the best practice solution?
Suppose a user would like to one day pay off his entire balance, which is shown to him from the database but is located at, say, 4 addresses. Doesn't he then pay transaction fees four times? Another question that comes to my mind now: How do I deal with the accumulated credit on different addresses of a user in advance?
hero member
Activity: 882
Merit: 5834
not your keys, not your coins!
Did you still have experiences with similar services? Read me something.
No; I don't use nor recommend any such service, because you are giving away your keys. Not your keys.. Remember?

Your approach is not really effective. You are assuming standard terms. In your approach, you randomly generate 10 addresses. It is more effective here to first find out which is the highest value after the user (user-?), for which addresses already exist. But even thinking further, it would most likely lead to problems, at the latest when it comes to allocating the accumulated credit of each address to the actual user. Programmatically, this would be a shambles. The approach of so-called forwarding addresses would be much more useful here. It's all about matching the amount deposited through different addresses for a specific user to a root wallet.
Of course, this is just a proof of concept to show you how it's done. You'd want to keep track of each user's highest used address index e.g. in a database, fetch that number, increment by one, save it to DB again, construct the new address label and fetch a new address with that label from your wallet provider.
Accumulating balances would just require you to query all userA-* addresses and add the results. I don't see a problem with that.
newbie
Activity: 5
Merit: 1
Quote
you would want to call get_new_address with label=userAx{address_number} as many times as you wish to create a new address for User A.
And that's exactly what I want to do in PHP.
Here ya go.

Code:
$addresses_for_userA = array();
for (
$x 0$x 10$x++) {
  
array_push($addresses_for_userA"userA-".$x);
}

// this is just to show you the addresses it generated
foreach ($addresses_for_userA as $address) {
  echo 
$address "\n";
}

Your approach is not really effective. You are assuming standard terms. In your approach, you randomly generate 10 addresses. It is more effective here to first find out which is the highest value after the user (user-?), for which addresses already exist. But even thinking further, it would most likely lead to problems, at the latest when it comes to allocating the accumulated credit of each address to the actual user. Programmatically, this would be a shambles. The approach of so-called forwarding addresses would be much more useful here. It's all about matching the amount deposited through different addresses for a specific user to a root wallet.
newbie
Activity: 5
Merit: 1
Thank you for inspiration. I will test your approach.

And no, don't worry. My somewhat stupid question does not reflect the quality of my approach. I have been handling Bitcoin for a few years, if not programmatically.

But briefly on the topic: I just hope that it also performs well with the server side with increasing number of addresses. Nevertheless, I found it better with forwarding addresses.
Did you still have experiences with similar services? Read me something.
hero member
Activity: 882
Merit: 5834
not your keys, not your coins!
Quote
you would want to call get_new_address with label=userAx{address_number} as many times as you wish to create a new address for User A.
And that's exactly what I want to do in PHP.
Here ya go.

Code:
$addresses_for_userA = array();
for (
$x 0$x 10$x++) {
  
array_push($addresses_for_userA"userA-".$x);
}

// this is just to show you the addresses it generated
foreach ($addresses_for_userA as $address) {
  echo 
$address "\n";
}

Basically, you pick a prefix that is unique per user (like userA-) and then append a number that keeps increasing.
That way you can tell which addresses belong to which user, and it's easy to keep track and add new addresses (look at last one, increment number by one).

And yes, you are welcome to ask. I'm building some kind of asset safe for friends with some features. The user should simply be able to generate a new receiving address, which can also be clearly assigned to his wallet.
Did you read those terms? You don't want to lose your friends money, do you?
newbie
Activity: 5
Merit: 1
Thanks for your answer. But why does the doc say the following?

"With Block.io, you can create wallet addresses for users inside your games, auction sites, stores, etc.

To create a user's wallet on your account, create addresses for them using get_new_address. You should specify a sequence of labels for that user. For instance, if you wish to create a number of addresses for User A, you would want to call get_new_address with label=userAx{address_number} as many times as you wish to create a new address for User A.

Once you have addresses for User A, you can perform relevant actions for their addresses."Huh



And that's exactly what I want to do in PHP. I remember that it could be realized via block.io with forwarding_addresses some time ago. But that is apparently no longer possible, for whatever reason.

And yes, you are welcome to ask. I'm building some kind of asset safe for friends with some features. The user should simply be able to generate a new receiving address, which can also be clearly assigned to his wallet.
hero member
Activity: 882
Merit: 5834
not your keys, not your coins!
Their docs say: 'Returns a newly generated address, and its unique(!) label generated by Block.io. You can optionally specify a custom label.' with exclamation mark.
I'm pretty sure there's no way to get 2 addresses with the same label; it's probably used internally to uniquely identify those addresses.

May I ask why you're even using a 'Wallet as a Service' in the first place, though? Undecided
They can run with your funds at any time (like any other such service):
We will not be responsible or liable to you for any loss and take no responsibility for damages or claims arising in whole or in part, directly or indirectly from: (a) user error such as forgotten passwords, incorrectly constructed transactions, or mistyped Virtual Currency addresses; (b) server failure or data loss; (c) corrupted or otherwise non-performing Wallets or Wallet files; (d) unauthorized access to applications; (e) any unauthorized activities, including without limitation the use of hacking, viruses, phishing, brute forcing or other means of attack against the Services.
newbie
Activity: 5
Merit: 1
Hi,

I use the block.io API and want to add another address to an existing label.

$user = 'anyone'

$getNewUserAddress = $block_io->get_new_address(array('label' => $user));

I am using PHP.

How do I do that?

Many thanks for your help!
Jump to: