Bitcoin Forum
March 30, 2024, 03:04:45 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Need help in configuring JSON RPC for Bitcoin Core - Please help  (Read 1072 times)
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 14, 2017, 08:53:01 PM
Merited by ABCbits (1)
 #1

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

Posts: 1711767885

View Profile Personal Message (Offline)

Ignore
1711767885
Reply with quote  #2

1711767885
Report to moderator
1711767885
Hero Member
*
Offline Offline

Posts: 1711767885

View Profile Personal Message (Offline)

Ignore
1711767885
Reply with quote  #2

1711767885
Report to moderator
There are several different types of Bitcoin clients. The most secure are full nodes like Bitcoin Core, but full nodes are more resource-heavy, and they must do a lengthy initial syncing process. As a result, lightweight clients with somewhat less security are commonly used.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1711767885
Hero Member
*
Offline Offline

Posts: 1711767885

View Profile Personal Message (Offline)

Ignore
1711767885
Reply with quote  #2

1711767885
Report to moderator
1711767885
Hero Member
*
Offline Offline

Posts: 1711767885

View Profile Personal Message (Offline)

Ignore
1711767885
Reply with quote  #2

1711767885
Report to moderator
1711767885
Hero Member
*
Offline Offline

Posts: 1711767885

View Profile Personal Message (Offline)

Ignore
1711767885
Reply with quote  #2

1711767885
Report to moderator
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4315

<insert witty quote here>


View Profile
August 16, 2017, 03:45:46 AM
Merited by ABCbits (1)
 #2

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

..JAMBLER.io..Create Your Bitcoin Mixing
Business Now for   F R E E 
▄█████████████████████████████
█████████████████████████
████▀████████████████████
███▀█████▄█▀███▀▀▀██████
██▀█████▄█▄██████████████
██▄▄████▀▄▄▄▀▀▀▀▀▄▄██████
█████▄▄▄██████████▀▄████
█████▀▄█▄██████▀█▄█████
███████▀▄█▀█▄██▀█▄███████
█████████▄█▀▄█▀▄█████████
█████████████████████████
█████████████████████████
▀█████████████████████████████
█████████████████████████████████████████████████
.
      OUR      
PARTNERS

.
█████████████████████████████████████████████████
████▄
██
██
██
██
██
██
██
██
██
██
██
████▀
▄█████████████████████████████
████████▀▀█████▀▀████████
█████▀█████████████▀█████
████████████████████████
███████████████▄█████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████▀█████████
████████████████████████
█████▄█████████████▄█████
████████▄▄█████▄▄████████
▀█████████████████████████████
█████████████████████████████████████████████████
.
   INVEST   
BITCOIN

.
█████████████████████████████████████████████████
████▄
██
██
██
██
██
██
██
██
██
██
██
████▀
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 16, 2017, 12:57:27 PM
 #3

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?
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 16, 2017, 11:53:10 PM
 #4

any one please reply
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4315

<insert witty quote here>


View Profile
August 17, 2017, 04:39:24 AM
Merited by ABCbits (3)
 #5

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

..JAMBLER.io..Create Your Bitcoin Mixing
Business Now for   F R E E 
▄█████████████████████████████
█████████████████████████
████▀████████████████████
███▀█████▄█▀███▀▀▀██████
██▀█████▄█▄██████████████
██▄▄████▀▄▄▄▀▀▀▀▀▄▄██████
█████▄▄▄██████████▀▄████
█████▀▄█▄██████▀█▄█████
███████▀▄█▀█▄██▀█▄███████
█████████▄█▀▄█▀▄█████████
█████████████████████████
█████████████████████████
▀█████████████████████████████
█████████████████████████████████████████████████
.
      OUR      
PARTNERS

.
█████████████████████████████████████████████████
████▄
██
██
██
██
██
██
██
██
██
██
██
████▀
▄█████████████████████████████
████████▀▀█████▀▀████████
█████▀█████████████▀█████
████████████████████████
███████████████▄█████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████▀█████████
████████████████████████
█████▄█████████████▄█████
████████▄▄█████▄▄████████
▀█████████████████████████████
█████████████████████████████████████████████████
.
   INVEST   
BITCOIN

.
█████████████████████████████████████████████████
████▄
██
██
██
██
██
██
██
██
██
██
██
████▀
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 17, 2017, 01:42:14 PM
 #6

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?
genesis.vision
Member
**
Offline Offline

Activity: 258
Merit: 10

The next step in Financial Markets evolution


View Profile WWW
August 17, 2017, 01:46:29 PM
 #7


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.

Genesis Vision — Decentralized Platform for Asset Management
 ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰ TRADE WITH GV ▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰  
●  Twitter Facebook •  The next step in financial markets evolution • Telegram Medium  ●
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 17, 2017, 02:30:01 PM
 #8


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?
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4315

<insert witty quote here>


View Profile
August 17, 2017, 11:10:26 PM
 #9

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

..JAMBLER.io..Create Your Bitcoin Mixing
Business Now for   F R E E 
▄█████████████████████████████
█████████████████████████
████▀████████████████████
███▀█████▄█▀███▀▀▀██████
██▀█████▄█▄██████████████
██▄▄████▀▄▄▄▀▀▀▀▀▄▄██████
█████▄▄▄██████████▀▄████
█████▀▄█▄██████▀█▄█████
███████▀▄█▀█▄██▀█▄███████
█████████▄█▀▄█▀▄█████████
█████████████████████████
█████████████████████████
▀█████████████████████████████
█████████████████████████████████████████████████
.
      OUR      
PARTNERS

.
█████████████████████████████████████████████████
████▄
██
██
██
██
██
██
██
██
██
██
██
████▀
▄█████████████████████████████
████████▀▀█████▀▀████████
█████▀█████████████▀█████
████████████████████████
███████████████▄█████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████▀█████████
████████████████████████
█████▄█████████████▄█████
████████▄▄█████▄▄████████
▀█████████████████████████████
█████████████████████████████████████████████████
.
   INVEST   
BITCOIN

.
█████████████████████████████████████████████████
████▄
██
██
██
██
██
██
██
██
██
██
██
████▀
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 18, 2017, 12:15:43 AM
 #10

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
*
Offline Offline

Activity: 2086
Merit: 4315

<insert witty quote here>


View Profile
August 18, 2017, 02:06:01 AM
 #11

"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.

..JAMBLER.io..Create Your Bitcoin Mixing
Business Now for   F R E E 
▄█████████████████████████████
█████████████████████████
████▀████████████████████
███▀█████▄█▀███▀▀▀██████
██▀█████▄█▄██████████████
██▄▄████▀▄▄▄▀▀▀▀▀▄▄██████
█████▄▄▄██████████▀▄████
█████▀▄█▄██████▀█▄█████
███████▀▄█▀█▄██▀█▄███████
█████████▄█▀▄█▀▄█████████
█████████████████████████
█████████████████████████
▀█████████████████████████████
█████████████████████████████████████████████████
.
      OUR      
PARTNERS

.
█████████████████████████████████████████████████
████▄
██
██
██
██
██
██
██
██
██
██
██
████▀
▄█████████████████████████████
████████▀▀█████▀▀████████
█████▀█████████████▀█████
████████████████████████
███████████████▄█████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████▀█████████
████████████████████████
█████▄█████████████▄█████
████████▄▄█████▄▄████████
▀█████████████████████████████
█████████████████████████████████████████████████
.
   INVEST   
BITCOIN

.
█████████████████████████████████████████████████
████▄
██
██
██
██
██
██
██
██
██
██
██
████▀
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 18, 2017, 02:38:23 AM
 #12

"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 = '<span  class="msgOk">Paid to <b>'.$address.'</b><br />Txid: <b>'.$wind.'</b><br></span>';

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
*
Offline Offline

Activity: 2086
Merit: 4315

<insert witty quote here>


View Profile
August 18, 2017, 03:35:26 AM
 #13

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...

..JAMBLER.io..Create Your Bitcoin Mixing
Business Now for   F R E E 
▄█████████████████████████████
█████████████████████████
████▀████████████████████
███▀█████▄█▀███▀▀▀██████
██▀█████▄█▄██████████████
██▄▄████▀▄▄▄▀▀▀▀▀▄▄██████
█████▄▄▄██████████▀▄████
█████▀▄█▄██████▀█▄█████
███████▀▄█▀█▄██▀█▄███████
█████████▄█▀▄█▀▄█████████
█████████████████████████
█████████████████████████
▀█████████████████████████████
█████████████████████████████████████████████████
.
      OUR      
PARTNERS

.
█████████████████████████████████████████████████
████▄
██
██
██
██
██
██
██
██
██
██
██
████▀
▄█████████████████████████████
████████▀▀█████▀▀████████
█████▀█████████████▀█████
████████████████████████
███████████████▄█████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████▀█████████
████████████████████████
█████▄█████████████▄█████
████████▄▄█████▄▄████████
▀█████████████████████████████
█████████████████████████████████████████████████
.
   INVEST   
BITCOIN

.
█████████████████████████████████████████████████
████▄
██
██
██
██
██
██
██
██
██
██
██
████▀
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 18, 2017, 01:45:47 PM
 #14

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
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 28, 2017, 02:44:35 PM
 #15

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
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!