Author

Topic: Blocktrail/btc.com SDK Fees estimation (Read 174 times)

btj
member
Activity: 115
Merit: 16
July 29, 2018, 06:08:50 PM
#2
Here is how to do it:

Code:
use Blocktrail\SDK\BlocktrailSDK;
use 
Blocktrail\SDK\Wallet;

// BEGIN - CHANGE REQUIRED INFOS
require_once __DIR__ "BLOCKTRAIL_SDK";

define("blocktrail_api"""); 
define("blocktrail_secret""");
define("blocktrail_wallet""");
define("blocktrail_password""");

$address ""// your address
$satoshi 100000// your amount in satoshi

// END - CHANGE REQUIRED INFOS

$client = new BlocktrailSDK(blocktrail_apiblocktrail_secret"BTC"false);
$wallet $client->initWallet(blocktrail_walletblocktrail_password);

$feeStrategy = \Blocktrail\SDK\Wallet::FEE_STRATEGY_LOW_PRIORITY// your fee type

$coinselect $wallet->coinSelection(
\
Blocktrail\SDK\Wallet::normalizeOutputsStruct([$address => $satoshi]),
falsefalse,
$feeStrategy
);

$fees $coinselect["fee"];

// Logs
var_dump($coinselect);
echo 
"\n Fees for this transaction will be: ".$fees;
?>

Change some informations like: BLOCKTRAIL_SDK path, blocktrail api, address where you want to send the amount, and the amount it self in ($satoshi string).

I notice the bitcoin address you are trying to send BTC to:
Code:
66f4dec6ab29cd056ce1814c6fdfee05e1524b36
are not in correct format, a Bitcoin address start with number '1' or '3',  contains 26 to 33 characters (a-z, A-Z, 0-9), excluding 'O', 'I' and 'l', to prevent visual ambiguity. And your address do not follow all this conditions ... i think you put a random MD5 string.

If it's a testnet address, please switch to testnet on Blocktrail, but i don't know if Fees estimation is supported or not for testnet, change this line:
Code:
$client = new BlocktrailSDK(blocktrail_api, blocktrail_secret, "BTC", false);
to

Code:
$client = new BlocktrailSDK(blocktrail_api, blocktrail_secret, "BTC", true);

I suggest to process payments semi-automatically ... when user submit new withdraw request, from admin panel you can process it with one button click.

I used Blocktrail API in the past, but personnaly i didn't liked it ... support is late or never answer to customers tickets/emails, and the fees for transactions are very high (I don't know if this changed from that time - Around one year ago).
newbie
Activity: 3
Merit: 0
July 28, 2018, 08:13:05 AM
#1
First of all hi and thanks for your support and your time.

I want to calculate the fees of a blocktrail transaction with blocktrail SDK, before making the transaction, in order to let the recipient pay fees.

Here is what I tried:

Code:
$FEES = $wallet->coinSelection(\Blocktrail\SDK\Wallet::normalizeOutputsStruct(['66f4dec6ab29cd056ce1814c6fdfee05e1524b36' =>'100000']),false,false,\Blocktrail\SDK\Wallet::FEE_STRATEGY_LOW_PRIORITY['fee'];
echo "$FEES";

But this don't work, error says this:
Code:
Fatal error: Uncaught Blocktrail\SDK\Exceptions\BlocktrailSDKException: Address not recognized
how can I fix it?Any other ideas to make this "action"?

I have also another question, how should I process payments on my site and why? Is more correct to process a payment when user request it, so with only 1 input or to process all payments togheter with a cronjob?

Thanks for read, hope that you'll have a nice day Smiley
Jump to: