Author

Topic: Need help in configuring JSON RPC for Bitcoin Core - Please help (Read 1093 times)

sr. member
Activity: 555
Merit: 251
Hi,

I am developing a code in which i have the below lines to send the withdrawal.

$amount1=(double)$_POST['amount_w1'];
$wind = $bitcoin->sendtoaddress($address,$amount1);


But i want to know how to write the code to send multiple amounts to multiple addresses at a time..

Example - Address one - 0.1 BTC, Address 2 - 0.14 btc, Address 3 - 0.005 btc

I want to send all together as a single transaction. How do i do it?

What command should i write?

When i send multiple transactions in a single transaction, i have to pay the fees only once or multiple times?  Can i save the fees if i send multiple withdrawals in a single transaction?

Please help me
sr. member
Activity: 555
Merit: 251
at a complete guess (based on your code and the API)... it would be something like:

Code:
$transaction = $bitcoin->gettransaction($wind);
$amt = $transaction['amount'];
$fee = $transaction['fee'];

$amt will show the actual amount sent to the users address
$fee will show the fee that was used in the BTC transaction

Note: you may or may not want to use "abs($transaction['fee'])" as the fee is returned from gettransaction as a negative number...


Thanks a lot brother. It works like a charm
HCP
legendary
Activity: 2086
Merit: 4361
at a complete guess (based on your code and the API)... it would be something like:

Code:
$transaction = $bitcoin->gettransaction($wind);
$amt = $transaction['amount'];
$fee = $transaction['fee'];

$amt will show the actual amount sent to the users address
$fee will show the fee that was used in the BTC transaction

Note: you may or may not want to use "abs($transaction['fee'])" as the fee is returned from gettransaction as a negative number...
sr. member
Activity: 555
Merit: 251
"sendtoaddress" returns the transactionID that it has created. Use that TransactionID with "gettransaction": https://chainquery.com/bitcoin-api/gettransaction

The output from "gettransaction" includes the "fee".

Quote
 "fee": x.xxx,            (numeric) The amount of the fee in BTC. This is negative and only available for the
                              'send' category of transactions.

Thank you. But can you please tell me the exact php code to get the above value..

My current code is:

$amount1=(double)$_POST['amount_w1'];
$wind = $bitcoin->sendtoaddress($address,$amount1,"","",true);
$info = 'Paid to '.$address.'
Txid: '.$wind.'
';

What code should i use to get the value of the fee?

Should i write the code below to get the fee?

$fee = "fee"

Amount Sent = $amount1-$fee

Please tell me the code to get the above value?

HCP
legendary
Activity: 2086
Merit: 4361
"sendtoaddress" returns the transactionID that it has created. Use that TransactionID with "gettransaction": https://chainquery.com/bitcoin-api/gettransaction

The output from "gettransaction" includes the "fee".

Quote
  "fee": x.xxx,            (numeric) The amount of the fee in BTC. This is negative and only available for the
                              'send' category of transactions.
sr. member
Activity: 555
Merit: 251
Perhaps what you're really wanting is the RPC "sendtoaddress" function: https://chainquery.com/bitcoin-api/sendtoaddress

You simply state the address, the amount (optionally add some labels/comments if you want or just use "" empty strings) and then add a 'true' to the end to get it to subtract the fee from the amount:

Code:
bitcoin-cli sendtoaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1 "" "" true

I got this work already few hours back. anyway thanks for your reply.

now i want a code to know how much the fee was paid after that transaction. Please give me the php code to determine the fee that was paid for that transaction...
HCP
legendary
Activity: 2086
Merit: 4361
Perhaps what you're really wanting is the RPC "sendtoaddress" function: https://chainquery.com/bitcoin-api/sendtoaddress

You simply state the address, the amount (optionally add some labels/comments if you want or just use "" empty strings) and then add a 'true' to the end to get it to subtract the fee from the amount:

Code:
bitcoin-cli sendtoaddress "1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd" 0.1 "" "" true
sr. member
Activity: 555
Merit: 251

Example - If a client requests for a withdrawal of 0.1 btc, i want to deduct the fee and send the balance as withdrawal.  How do i put it in php code?  Please help me.  I dont want to charge a fixed fee from the clients.  I want to just deduct the fees that will incur for that withdrawal..

Check out RPC .estimateFee function: https://chainquery.com/bitcoin-api/estimatefee

Create a tx hash and pass it as a parameter to estimateFee call.

Thank you. I finally got it working by trying different combinations.

I still have one more question. Now after the withdrawal is processed, how do i get the exact fees charged for that transaction. Because i want to display the amount charged for withdrawal to the user. So that he will have clarity. Where do i get this information?

Please tell me the php code to write this function?
member
Activity: 258
Merit: 10
The next step in Financial Markets evolution

Example - If a client requests for a withdrawal of 0.1 btc, i want to deduct the fee and send the balance as withdrawal.  How do i put it in php code?  Please help me.  I dont want to charge a fixed fee from the clients.  I want to just deduct the fees that will incur for that withdrawal..

Check out RPC .estimateFee function: https://chainquery.com/bitcoin-api/estimatefee

Create a tx hash and pass it as a parameter to estimateFee call.
sr. member
Activity: 555
Merit: 251
The fee amount is simply the difference between Total Inputs and Total Outputs... so when you are creating the transaction, you just factor that in. If you're wanting to use the "Dynamic Fee" system, you'd call the "estimatefee" function (with appropriate parameter(s)) and that would give you the fee (in btc/KB) to use... then you select inputs where total inputAmount >= (requestedAmount + estimated fee)...

Then, create outputs to be:
amountToCustAddr = withdrawAmount = (requestedAmount - fee)
amountToChangeAddress = (Total inputs - requestedAmount)


So:
estimatefee(6 blocks) =  0.00256843 btc/kB
requestedAmount = 0.01

AvailableInput1 = 3.4 BTC

Assuming tx size of 226 bytes (1 input + 1 custAddr Output + 1 changeAddr output), the fee = (0.00256843 BTC/kB / 1000) * 226 bytes = 0.00058047

withdrawAmount = (requestedAmount - fee) = 0.01 - 0.00058047 = 0.00941953 BTC
amountToChangeAddr = (TotalInputs - requestedAmount) = 3.4 - 0.01 = 3.39 BTC


Then just create a transaction with all the calculated values:

Inputs:
AvailableInput1 = 3.4 BTC

Outputs:
custAddr = withdrawAmount = 0.00941953 BTC
chgAddr = (TotalInputs - requesteedAmount) = 3.4 - 0.01 = 3.39 BTC

The fee is not explicitly specified when you create the transaction, as the protocol specifies that it is the difference between total Inputs (3.4) and total outputs (3.39 + 0.00941953) = 0.00058047 in this example


Just be aware that your customers are likely to moan and whine if they request 0.01 and only get 0.00941953 unless you make it VERY VERY VERY clear that the transaction fee will be deducted from the requested amount Tongue

Thanks but estimated fee is always not accurate. Many times the fees we get by running estimated fees differs from the actual fees. Is there any way to use the code "subtractfeefromamount". I saw this while searching on google. But how to use it exactly on php?
HCP
legendary
Activity: 2086
Merit: 4361
The fee amount is simply the difference between Total Inputs and Total Outputs... so when you are creating the transaction, you just factor that in. If you're wanting to use the "Dynamic Fee" system, you'd call the "estimatefee" function (with appropriate parameter(s)) and that would give you the fee (in btc/KB) to use... then you select inputs where total inputAmount >= (requestedAmount + estimated fee)...

Then, create outputs to be:
amountToCustAddr = withdrawAmount = (requestedAmount - fee)
amountToChangeAddress = (Total inputs - requestedAmount)


So:
estimatefee(6 blocks) =  0.00256843 btc/kB
requestedAmount = 0.01

AvailableInput1 = 3.4 BTC

Assuming tx size of 226 bytes (1 input + 1 custAddr Output + 1 changeAddr output), the fee = (0.00256843 BTC/kB / 1000) * 226 bytes = 0.00058047

withdrawAmount = (requestedAmount - fee) = 0.01 - 0.00058047 = 0.00941953 BTC
amountToChangeAddr = (TotalInputs - requestedAmount) = 3.4 - 0.01 = 3.39 BTC


Then just create a transaction with all the calculated values:

Inputs:
AvailableInput1 = 3.4 BTC

Outputs:
custAddr = withdrawAmount = 0.00941953 BTC
chgAddr = (TotalInputs - requesteedAmount) = 3.4 - 0.01 = 3.39 BTC

The fee is not explicitly specified when you create the transaction, as the protocol specifies that it is the difference between total Inputs (3.4) and total outputs (3.39 + 0.00941953) = 0.00058047 in this example


Just be aware that your customers are likely to moan and whine if they request 0.01 and only get 0.00941953 unless you make it VERY VERY VERY clear that the transaction fee will be deducted from the requested amount Tongue
sr. member
Activity: 555
Merit: 251
any one please reply
sr. member
Activity: 555
Merit: 251
Just modify whatever values you're setting as the output value to their withdraw address and output value to your change address.

Subtract the network free from customer output... And then add that amount to your change address output value. That will effectively "transfer" the network fee from you to them.

Ie current setup:
Input: 1 BTC
outputToCustomerAddr: 0.1
outputToChangeAddr: 0.8999
Fee = 0.0001

Change to:
Input: 1 BTC
outputToCustomerAddr: (0.1-0.0001) = 0.0999
outputToChangeAddr: (0.8999+0.0001) = 0.9000
Fee: 0.0001

Note: fee doesn't need to be fixed... It's just an example Wink

but how to get the value of the fees that is going to be charged. we do not know the fees amount right. in such case what value should we substract?
HCP
legendary
Activity: 2086
Merit: 4361
Just modify whatever values you're setting as the output value to their withdraw address and output value to your change address.

Subtract the network free from customer output... And then add that amount to your change address output value. That will effectively "transfer" the network fee from you to them.

Ie current setup:
Input: 1 BTC
outputToCustomerAddr: 0.1
outputToChangeAddr: 0.8999
Fee = 0.0001

Change to:
Input: 1 BTC
outputToCustomerAddr: (0.1-0.0001) = 0.0999
outputToChangeAddr: (0.8999+0.0001) = 0.9000
Fee: 0.0001

Note: fee doesn't need to be fixed... It's just an example Wink
sr. member
Activity: 555
Merit: 251
Hi,

I installed bitcoin core on ubuntu server and using JSON RPC on php. I am in the process of developing a gaming site.  When a client requests a withdrawal it automatically process the transaction and the transaction fee is charged from my main balance. Is there any way to make the the transaction fees deducted from the withdrawn money by the user.

Example - If a client requests for a withdrawal of 0.1 btc, i want to deduct the fee and send the balance as withdrawal.  How do i put it in php code?  Please help me.  I dont want to charge a fixed fee from the clients.  I want to just deduct the fees that will incur for that withdrawal..
Jump to: