Author

Topic: Need help to write the code for Bitcoin RPC withdrawal (Read 402 times)

sr. member
Activity: 555
Merit: 251
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.
legendary
Activity: 1512
Merit: 1057
SpacePirate.io
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
sr. member
Activity: 555
Merit: 251
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?
legendary
Activity: 1512
Merit: 1057
SpacePirate.io
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.
sr. member
Activity: 555
Merit: 251
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..
sr. member
Activity: 555
Merit: 251
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
full member
Activity: 181
Merit: 102
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.
staff
Activity: 3458
Merit: 6793
Just writing some code
Note: I am not a PHP programmer

Your probably want to do something like this:

Code:
$wind = $bitcoin->sendtoaddress($address,$amount1,"","",true);
sr. member
Activity: 555
Merit: 251
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?
Jump to: