Bitcoin Forum
May 11, 2024, 09:29:45 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Need help to write the code for Bitcoin RPC withdrawal  (Read 394 times)
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 17, 2017, 02:14:57 AM
 #1

Hi,

I am writing a php code to process bitcoin withdrawal.  I want the recipient to bear the transaction fees of all the withdrawals.  I came to know that i have to use the command "subtractfeefromamount". 

I saw that i have to run the following command:

sendtoaddress "bitcoinaddress" amount ( "comment" "comment-to" subtractfeefromamount )

Please tell me how do write the above code in php to process the transaction..

I currently have the below code to process transaction:

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

Please tell me how do i include subtractfeefromamount in the above code?
1715462985
Hero Member
*
Offline Offline

Posts: 1715462985

View Profile Personal Message (Offline)

Ignore
1715462985
Reply with quote  #2

1715462985
Report to moderator
Bitcoin addresses contain a checksum, so it is very unlikely that mistyping an address will cause you to lose money.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715462985
Hero Member
*
Offline Offline

Posts: 1715462985

View Profile Personal Message (Offline)

Ignore
1715462985
Reply with quote  #2

1715462985
Report to moderator
1715462985
Hero Member
*
Offline Offline

Posts: 1715462985

View Profile Personal Message (Offline)

Ignore
1715462985
Reply with quote  #2

1715462985
Report to moderator
1715462985
Hero Member
*
Offline Offline

Posts: 1715462985

View Profile Personal Message (Offline)

Ignore
1715462985
Reply with quote  #2

1715462985
Report to moderator
achow101
Staff
Legendary
*
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
August 17, 2017, 06:15:45 AM
 #2

Note: I am not a PHP programmer

Your probably want to do something like this:

Code:
$wind = $bitcoin->sendtoaddress($address,$amount1,"","",true);

efeaydin
Full Member
***
Offline Offline

Activity: 181
Merit: 102


View Profile
August 17, 2017, 06:37:49 AM
 #3

Hi,

I am writing a php code to process bitcoin withdrawal.  I want the recipient to bear the transaction fees of all the withdrawals.  I came to know that i have to use the command "subtractfeefromamount". 

I saw that i have to run the following command:

sendtoaddress "bitcoinaddress" amount ( "comment" "comment-to" subtractfeefromamount )

Please tell me how do write the above code in php to process the transaction..

I currently have the below code to process transaction:

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

Please tell me how do i include subtractfeefromamount in the above code?

if (isset($_POST["addr"]) && isset($_POST["amount"]) && isset($_POST["fee"]))
{
 $wind = $bitcoin->sendtoaddress($_POST["addr"], (double)$_POST["amount"], (double)$_POST["fee"])
}

Maybe something like this? I can't tell it without seeing the class.
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 17, 2017, 01:12:01 PM
 #4

Hi,

I am writing a php code to process bitcoin withdrawal.  I want the recipient to bear the transaction fees of all the withdrawals.  I came to know that i have to use the command "subtractfeefromamount". 

I saw that i have to run the following command:

sendtoaddress "bitcoinaddress" amount ( "comment" "comment-to" subtractfeefromamount )

Please tell me how do write the above code in php to process the transaction..

I currently have the below code to process transaction:

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

Please tell me how do i include subtractfeefromamount in the above code?

if (isset($_POST["addr"]) && isset($_POST["amount"]) && isset($_POST["fee"]))
{
 $wind = $bitcoin->sendtoaddress($_POST["addr"], (double)$_POST["amount"], (double)$_POST["fee"])
}

Maybe something like this? I can't tell it without seeing the class.

I just sent you a pm with code.. Please reply
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 17, 2017, 01:12:19 PM
 #5

Note: I am not a PHP programmer

Your probably want to do something like this:

Code:
$wind = $bitcoin->sendtoaddress($address,$amount1,"","",true);

I tried this and it doesn't work..
cloverme
Legendary
*
Offline Offline

Activity: 1512
Merit: 1057


SpacePirate.io


View Profile WWW
August 17, 2017, 01:27:30 PM
 #6

Note: I am not a PHP programmer

Your probably want to do something like this:

Code:
$wind = $bitcoin->sendtoaddress($address,$amount1,"","",true);

I tried this and it doesn't work..

This might help you: https://chainquery.com/bitcoin-api/sendtoaddress

My guess is that your function call doesn't accept 5 parameters. Check your code where it encodes to json. I'm assuming you're also casting correctly to initialize a new "$bitcoin" object as well.
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 17, 2017, 02:29:39 PM
 #7

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

Activity: 1512
Merit: 1057


SpacePirate.io


View Profile WWW
August 18, 2017, 12:40:34 PM
 #8

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?

Sadly, it's a very complex process to calculate the exact transaction fee as you have to build the entire transaction yourself. There's no RPC command that returns the exact fee for you. The easiest thing for you do to is probably estimate it... You can use the rpc command "estimatefee" and pass a variable "6" to it which will gives you the approximate fee per kilobyte needed for a transaction for x blocks (the '6' is for is 6 blocks). Your average transaction size is between 225-300 bytes for a bitcoin transaction with a low number of inputs. Over the years, most sites have set a high level watermark as a standard withdrawal fee for all withdrawals.

See this great answer from Chris M. (dooglas) on stackexchange:
https://bitcoin.stackexchange.com/questions/1195/how-to-calculate-transaction-size-before-sending
IGCGamers (OP)
Sr. Member
****
Offline Offline

Activity: 555
Merit: 251


View Profile
August 18, 2017, 01:52:04 PM
 #9

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?

Sadly, it's a very complex process to calculate the exact transaction fee as you have to build the entire transaction yourself. There's no RPC command that returns the exact fee for you. The easiest thing for you do to is probably estimate it... You can use the rpc command "estimatefee" and pass a variable "6" to it which will gives you the approximate fee per kilobyte needed for a transaction for x blocks (the '6' is for is 6 blocks). Your average transaction size is between 225-300 bytes for a bitcoin transaction with a low number of inputs. Over the years, most sites have set a high level watermark as a standard withdrawal fee for all withdrawals.

See this great answer from Chris M. (dooglas) on stackexchange:
https://bitcoin.stackexchange.com/questions/1195/how-to-calculate-transaction-size-before-sending

Thankyou for your kind help. But i found a different working option. Another member from this forum helped 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!