Bitcoin Forum

Bitcoin => Project Development => Topic started by: IGCGamers on August 17, 2017, 02:14:57 AM



Title: Need help to write the code for Bitcoin RPC withdrawal
Post by: IGCGamers on August 17, 2017, 02:14:57 AM
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?


Title: Re: Need help to write the code for Bitcoin RPC withdrawal
Post by: achow101 on August 17, 2017, 06:15:45 AM
Note: I am not a PHP programmer

Your probably want to do something like this:

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


Title: Re: Need help to write the code for Bitcoin RPC withdrawal
Post by: efeaydin on August 17, 2017, 06:37:49 AM
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.


Title: Re: Need help to write the code for Bitcoin RPC withdrawal
Post by: IGCGamers on August 17, 2017, 01:12:01 PM
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


Title: Re: Need help to write the code for Bitcoin RPC withdrawal
Post by: IGCGamers on August 17, 2017, 01:12:19 PM
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..


Title: Re: Need help to write the code for Bitcoin RPC withdrawal
Post by: cloverme on August 17, 2017, 01:27:30 PM
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.


Title: Re: Need help to write the code for Bitcoin RPC withdrawal
Post by: IGCGamers on August 17, 2017, 02:29:39 PM
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?


Title: Re: Need help to write the code for Bitcoin RPC withdrawal
Post by: cloverme on August 18, 2017, 12:40:34 PM
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


Title: Re: Need help to write the code for Bitcoin RPC withdrawal
Post by: IGCGamers on August 18, 2017, 01:52:04 PM
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.