Code:
<php
function calculateVariables($var) {
if($var == "winning_chance") {
global $payout;
return sprintf("%.2f",(9500/$payout) / 10000 * 100);
} elseif($var == "profit") {
global $payout;
global $bet_amt;
$pr_cal = $payout * 100;
$pr_cal = $pr_cal / 100 * $bet_amt;
$pr_cal = intval(($pr_cal*100000000))/100000000;
return number_format($pr_cal - $bet_amt,8,".","");
} elseif($var == "payout") {
global $winning_chance;
return sprintf("%.2f",95 / $winning_chance);
} else {
return "wrong_method";
}
}
// Remember that you need at-least 2 variables to calculate the rest.
// Set bet_amount:
$bet_amt = 1.00;
// Set payout (multiplier) to 101%:
$payout = 1.01;
// Calculate winning chance:
$winning_chance = calculateVariables("winning_chance");
// Calculate profit:
$profit = calculateVariables("profit");
// Calculate payout (multiplier) programmatically - should get the same previously set variable (note that, payour should only be calculated when winning_chance is known):
$payout = calculateVariables("payout");
?>
Code:
<php
define("API_ENDPOINT","http://vikfaucet.com/API");
define("API_KEY","YOUR_API_KEY");
define("API_SECRET","YOUR_API_SECRET");
// Generate seeds. If you wish to obtain the server seed hash (for this ***), please go to http://vikfaucet.com/dice and click Provably Fair.
$client_seed = uniqid() . uniqid() . uniqid();
$nonce = mt_rand(1,99);
// Choose High or Low.
$selection = 1; // High
# $selection = 2; // Low
// Allocate the previously generated variables and your local client seeds.
$fields = array(
'api_key' => urlencode(API_KEY),
'api_secret' => urlencode(API_SECRET),
'client_seed' => urlencode($client_seed),
'nonce' => urlencode($nonce),
'bet_amt' => urlencode($bet_amt),
'profit' => urlencode($profit),
'payout' => urlencode($payout),
'win_chance' => urlencode($win_chance),
'selection' => urlencode($selection)
);
$fields_string = "";
foreach($fields as $key=> $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, API_ENDPOINT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = json_decode(curl_exec($ch),TRUE);
curl_close($ch);
if($result['error_code'] == 200) {
$roll_number = $result['roll_number'];
$win = $result['win'];
$amount = $result['amount'];
if($win == 1) {
echo 'You have *** and earned a profit of ' . $amount . ' BTC. Your roll number was ' . $roll_number;
} else {
echo 'You have *** and lost an amount of ' . $amount . ' BTC.';
}
} else {
echo 'Server responsed with an error code of ' . $result['error_code'] . '. Message set by the server: ' . $result['error_message'];
}
?>
For the purpose of debugging, we've created several error codes and messages to help you find the problem.
Error Code #1001 — Failure — API has been disabled.
Error Code #1002 — Failure — Blank data has been sent.
Error Code #1003 — Failure — Wrong authentication details.
Error Code #1004 — Rate-Limited — Rate-limited.
Error Code #1005 — Error — Invalid NONCE parameter.
Error Code #1006 — Error — The parameters have to be numeric only.
Error Code #1007 — Error — The calculated parameters do not match.
Error Code #1008 — Error — The bet_amt is either lower than 0.00000001 or the balance is not sufficient to complete the ***.
Error Code #200 — Success — Everything is fine. Check out other JSON parameters to find more information.