Reputation: 3
I want to implement a bitcoin payment gateway without the help of any third party. So the idea is that I give the public address to the users and check the balance of the address using any API.
But there is a problem, how can I know which user sent how much money to the address. For example, I give 2 users my public address. They both bought the same thing. One paid the money and the other did not. How can I detect which user paid the money?
I guess generating a new address for every order is not a good idea.
Upvotes: -1
Views: 191
Reputation: 71
In order to do that I will not rely solely on the bitcoin address. I would generate a transaction with one of my wallet address, the number of satoshis I'd like to recieve and a unique ID (customer ID) in the OP_RETURN of the transaction. pseudo code will look like this:
// server side
transaction = create_transaction()
transaction.add_output(destination_address, amount_in_satoshis)
transaction.add_output(OP_RETURN, "PAYMENT_ID")
// in client side
transaction.sign(private_key)
send_transaction(transaction)
Just make sure that OP_RETURN size is less than 80 bytes
Upvotes: 0
Reputation: 2242
I guess generating a new address for every order is not a good idea.
It is actually the best idea, and how it is implemented everywhere else. You should create a new address for every single transaction. BIP32 details a method used by most wallets to create many addresses from a single master key.
Upvotes: -1