Bitcoin Forum
May 10, 2024, 06:29:50 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [API] Primedice.NET - Utilize the functionality of Primedice.com in .NET 4.5  (Read 1138 times)
kripod (OP)
Newbie
*
Offline Offline

Activity: 11
Merit: 0


View Profile
November 30, 2015, 04:13:22 PM
Last edit: December 03, 2015, 06:52:33 PM by kripod
 #1

Primedice.NET
View on GitHub

Primedice.NET wraps the functionality of the Primedice API in C#.
The project is written in .NET 4.5 as a portable class library.



Getting started

The following examples assume that the project has been referenced with the using directive:
Code:
using KriPod.Primedice;

Please be advised that all the monetary amounts are in satoshi by default (1 satoshi = 0.00000001 bitcoin).

Registering a new user
Code:
var username = "<username>";

// Initialize a new unauthorized instance of PrimediceClient
var client = new PrimediceClient();

// Create a new user
var user = await client.Users.Create(username);

// The following is the most important property of the newly-created user
// Store the value of AuthToken in order to access the created account later
var authToken = user.AuthToken;

Making a bet with an existing user
Code:
var serverSeed = "<serverSeed>";
var authToken =  "<authToken>";
var amount = 1; // 0.00000001 BTC
var condition = BetCondition.LowerThan;
var target = 49.5;

// Initialize a new authorized instance of PrimediceClient
// (Bet simulation is available by using an unauthorized instance)
var client = new PrimediceClient(authToken);

// Place a new bet with the parameters specified above
var bet = await client.Bets.Create(amount, condition, target);

// Verify the fairness of the bet whether it was lost
if (!bet.IsWon && !bet.Verify(serverSeed)) {
    // The roll was not calculated fairly. (This should never happen.)
}

Withdrawing and depositing funds
Code:
var authToken =  "<authToken>";
var withdrawalAddress = "<bitcoinAddress>";
var amount = 100000; // 0.001 BTC

// Initialize a new authorized instance of PrimediceClient
var client = new PrimediceClient(authToken);

// Withdraw some amount of money to the withdrawal address specified above
var withdrawal = await client.Wallet.Withdraw(amount, withdrawalAddress);

// Query the deposit address of self
var depositAddress = await client.Wallet.GetDepositAddress();
1715365790
Hero Member
*
Offline Offline

Posts: 1715365790

View Profile Personal Message (Offline)

Ignore
1715365790
Reply with quote  #2

1715365790
Report to moderator
1715365790
Hero Member
*
Offline Offline

Posts: 1715365790

View Profile Personal Message (Offline)

Ignore
1715365790
Reply with quote  #2

1715365790
Report to moderator
1715365790
Hero Member
*
Offline Offline

Posts: 1715365790

View Profile Personal Message (Offline)

Ignore
1715365790
Reply with quote  #2

1715365790
Report to moderator
Even in the event that an attacker gains more than 50% of the network's computational power, only transactions sent by the attacker could be reversed or double-spent. The network would not be destroyed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715365790
Hero Member
*
Offline Offline

Posts: 1715365790

View Profile Personal Message (Offline)

Ignore
1715365790
Reply with quote  #2

1715365790
Report to moderator
1715365790
Hero Member
*
Offline Offline

Posts: 1715365790

View Profile Personal Message (Offline)

Ignore
1715365790
Reply with quote  #2

1715365790
Report to moderator
cloverme
Legendary
*
Offline Offline

Activity: 1512
Merit: 1057


SpacePirate.io


View Profile WWW
December 02, 2015, 02:29:55 PM
 #2

Nice code solution for their API, glad to see someone else coding in C# too Cheesy I'm still amazed that any gambling site allows access to an API. Especially PD since a user figured out how to access the current decrypted server seed 6 months ago. Granted they plugged the hole, but still.

You could also add a provably fair check for past bets/rolls in there, just for good measure.
kripod (OP)
Newbie
*
Offline Offline

Activity: 11
Merit: 0


View Profile
December 02, 2015, 05:17:39 PM
 #3

Nice code solution for their API, glad to see someone else coding in C# too Cheesy I'm still amazed that any gambling site allows access to an API. Especially PD since a user figured out how to access the current decrypted server seed 6 months ago. Granted they plugged the hole, but still.

You could also add a provably fair check for past bets/rolls in there, just for good measure.

A provably fair check is already implemented, just use Bet.Verify("serverSeed") Smiley
I think that PrimeDice doesn't currently allow getting previous seed pairs, but I have already suggested them adding the functionality to do so.
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!