Bitcoin Forum
April 16, 2024, 03:35:45 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: block.io - create new address for existing label  (Read 119 times)
Slater8021 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 1


View Profile
December 03, 2022, 04:02:34 PM
Last edit: December 03, 2022, 04:13:40 PM by Slater8021
Merited by ABCbits (1)
 #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!
1713238545
Hero Member
*
Offline Offline

Posts: 1713238545

View Profile Personal Message (Offline)

Ignore
1713238545
Reply with quote  #2

1713238545
Report to moderator
1713238545
Hero Member
*
Offline Offline

Posts: 1713238545

View Profile Personal Message (Offline)

Ignore
1713238545
Reply with quote  #2

1713238545
Report to moderator
If you see garbage posts (off-topic, trolling, spam, no point, etc.), use the "report to moderator" links. All reports are investigated, though you will rarely be contacted about your reports.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5814


not your keys, not your coins!


View Profile WWW
December 03, 2022, 05:11:45 PM
Merited by ABCbits (2)
 #2

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.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Slater8021 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 1


View Profile
December 03, 2022, 06:23:11 PM
 #3

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.
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5814


not your keys, not your coins!


View Profile WWW
December 04, 2022, 01:42:50 AM
Merited by ABCbits (1)
 #4

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:
<?php
$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?

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Slater8021 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 1


View Profile
December 04, 2022, 11:02:43 AM
 #5

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.
Slater8021 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 1


View Profile
December 05, 2022, 09:20:38 AM
 #6

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:
<?php
$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.
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5814


not your keys, not your coins!


View Profile WWW
December 05, 2022, 01:35:24 PM
 #7

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.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Slater8021 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 1


View Profile
December 05, 2022, 08:11:58 PM
 #8

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?
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5814


not your keys, not your coins!


View Profile WWW
December 05, 2022, 08: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.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!