Bitcoin Forum

Alternate cryptocurrencies => Altcoin Discussion => Topic started by: simon66 on January 16, 2012, 10:29:34 PM



Title: [API] Difficulty needed.
Post by: simon66 on January 16, 2012, 10:29:34 PM
I'm currently working of a project and I need to know where can I find a reliable difficulty API?

Like I found this one for BTC

http://blockexplorer.com/q/getdifficulty

but I need to get one for NMV and DVC.

Thanks.

PS. I'll keep searching.


Title: Re: [API] Difficulty needed.
Post by: Remember remember the 5th of November on January 16, 2012, 10:57:40 PM
Every ?coind has an RPC command called getdifficulty to fetch current difficulty.


Title: Re: [API] Difficulty needed.
Post by: simon66 on January 16, 2012, 11:19:29 PM
Every ?coind has an RPC command called getdifficulty to fetch current difficulty.

ummm. what? Lol


Title: Re: [API] Difficulty needed.
Post by: notme on January 16, 2012, 11:21:24 PM
Every ?coind has an RPC command called getdifficulty to fetch current difficulty.

This.

bitcoind getdifficulty
namecoind getdifficulty
dvcoind getdifficulty (guessing on this one)


Title: Re: [API] Difficulty needed.
Post by: scintill on January 16, 2012, 11:22:25 PM
Every ?coind has an RPC command called getdifficulty to fetch current difficulty.

ummm. what? Lol

If you run bitcoind, namecoind, devcoind and keep them synced with the network, it's as easy as

Code:
$ bitcoind getdifficulty
1250757.73927466

at the shell, or via HTTP RPC requests if you set that up.


Title: Re: [API] Difficulty needed.
Post by: simon66 on January 17, 2012, 12:52:38 AM
Every ?coind has an RPC command called getdifficulty to fetch current difficulty.

ummm. what? Lol

If you run bitcoind, namecoind, devcoind and keep them synced with the network, it's as easy as

Code:
$ bitcoind getdifficulty
1250757.73927466

at the shell, or via HTTP RPC requests if you set that up.

I'm not so sure if the person I'm helping have that installed, how can I tell and how can I call it via php. Sorry if I'm asking too much.


Title: Re: [API] Difficulty needed.
Post by: payb.tc on January 17, 2012, 12:56:27 AM
for nmc, you could try scraping this page:

http://dot-bit.org/tools/nextDifficulty.php

Code:
<h2>Namecoin difficulty</h2>
<table cellpadding="0" cellspacing="0" class="liste">
<tr>
<th></th>
<th>Block</th>
<th>Time</th>
<th>Difficulty</th>
<th>Ratio</th>
</tr>
<tr>
<td style="text-align: left;"><abbr title="Last difficulty change">Last change</abbr></td>
<td>38304</td>
<td>16/01/2012 07:06</td>
<td><abbr title="3'523.80GH/s">516'181.44</abbr></td>
<td><abbr title="Based on elapsed blocks since last difficulty change">x1.04</abbr></td>
</tr>


Title: Re: [API] Difficulty needed.
Post by: simon66 on January 17, 2012, 01:02:48 AM
for nmc, you could try scraping this page:

http://dot-bit.org/tools/nextDifficulty.php

Code:
<h2>Namecoin difficulty</h2>
<table cellpadding="0" cellspacing="0" class="liste">
<tr>
<th></th>
<th>Block</th>
<th>Time</th>
<th>Difficulty</th>
<th>Ratio</th>
</tr>
<tr>
<td style="text-align: left;"><abbr title="Last difficulty change">Last change</abbr></td>
<td>38304</td>
<td>16/01/2012 07:06</td>
<td><abbr title="3'523.80GH/s">516'181.44</abbr></td>
<td><abbr title="Based on elapsed blocks since last difficulty change">x1.04</abbr></td>
</tr>

I was gonna do that, but there has to be an easier method. I'll wait on the "bitcoind getdifficulty" thingy


Title: Re: [API] Difficulty needed.
Post by: payb.tc on January 17, 2012, 01:16:55 AM
for nmc, you could try scraping this page:

http://dot-bit.org/tools/nextDifficulty.php

Code:
<h2>Namecoin difficulty</h2>
<table cellpadding="0" cellspacing="0" class="liste">
<tr>
<th></th>
<th>Block</th>
<th>Time</th>
<th>Difficulty</th>
<th>Ratio</th>
</tr>
<tr>
<td style="text-align: left;"><abbr title="Last difficulty change">Last change</abbr></td>
<td>38304</td>
<td>16/01/2012 07:06</td>
<td><abbr title="3'523.80GH/s">516'181.44</abbr></td>
<td><abbr title="Based on elapsed blocks since last difficulty change">x1.04</abbr></td>
</tr>

I was gonna do that, but there has to be an easier method. I'll wait on the "bitcoind getdifficulty" thingy

here you go... a bullet-proof php attempt:

Code:
<?php
$moo 
file_get_contents('http://dot-bit.org/tools/nextDifficulty.php');
$moo substr($moostrpos($moo'H/s') + 5);
$moo substr($moo0strpos($moo'<'));
$diff str_replace('\'','',$moo);
?>



Title: Re: [API] Difficulty needed.
Post by: scintill on January 17, 2012, 04:26:03 AM
Every ?coind has an RPC command called getdifficulty to fetch current difficulty.

ummm. what? Lol

If you run bitcoind, namecoind, devcoind and keep them synced with the network, it's as easy as

Code:
$ bitcoind getdifficulty
1250757.73927466

at the shell, or via HTTP RPC requests if you set that up.

I'm not so sure if the person I'm helping have that installed, how can I tell and how can I call it via php. Sorry if I'm asking too much.

You can check by trying "bitcoind getdifficulty" at the command line and seeing if it works.  If it does, the PHP is simple:

Code:
<?php
$difficulty 
= (float)`bitcoind getdifficulty`;
echo 
"Difficulty is "$difficulty"\n";

The "`" symbols are the "backtick operator", but shell_exec() (http://www.php.net/manual/en/function.shell-exec.php) is equivalent.  Replacing bitcoind with namecoind, etc., would make it work for all chains, if all the servers are installed and running.

From the sounds of it installing and maintaining nodes for each chain is more complicated than you want.  The APIs at http://blockexplorer.sytes.net/q (http://blockexplorer.sytes.net/q) might meet your needs, but last I looked some of the chains were out of date, and it seems to be down right now.  I also couldn't figure out how to use the relevant API call -- it would be something like http://blockexplorer.sytes.net/chain/Bitcoin/q/nethash , but I couldn't figure out how to narrow it to just the current difficulty.


Title: Re: [API] Difficulty needed.
Post by: payb.tc on January 17, 2012, 04:31:23 AM
You can check by trying "bitcoind getdifficulty" at the command line and seeing if it works.  If it does, the PHP is simple:

Code:
<?php
$difficulty 
= (float)`bitcoind getdifficulty`;
echo 
"Difficulty is "$difficulty"\n";

The "`" symbols are the "backtick operator", but shell_exec() (http://www.php.net/manual/en/function.shell-exec.php) is equivalent.  Replacing bitcoind with namecoind, etc., would make it work for all chains, if all the servers are installed and running.

wouldn't that approach also require you to know the full path to bitcoind?


Title: Re: [API] Difficulty needed.
Post by: scintill on January 17, 2012, 04:37:36 AM
here you go... a bullet-proof php attempt:

Code:
<?php
$moo 
file_get_contents('http://dot-bit.org/tools/nextDifficulty.php');
$moo substr($moostrpos($moo'H/s') + 5);
$moo substr($moo0strpos($moo'<'));
$diff str_replace('\'','',$moo);
?>


simon66, this is probably your best bet, in combination with similar pages for the other chains you're interested in.

wouldn't that approach also require you to know the full path to bitcoind?

If it is not in the PATH environment variable, you would have to put the full path.  Mine is in the PATH, so it works.


Title: Re: [API] Difficulty needed.
Post by: simon66 on January 17, 2012, 05:09:10 AM
looking here he got bitcoind, namecoind, and devcoind.

It's installed on /var/www/files/daemons/

I tried

Code:
$difficulty = (float)shell_exec('/var/www/files/daemons/bitcoind getdifficulty');
echo "Difficulty is ", $difficulty, "\n";

and I got "Difficulty 0"


Title: Re: [API] Difficulty needed.
Post by: payb.tc on January 17, 2012, 05:12:48 AM
looking here he got bitcoind, namecoind, and devcoind.

It's installed on /var/www/files/daemons/

I tried

Code:
$difficulty = (float)shell_exec('/var/www/files/daemons/bitcoind getdifficulty');
echo "Difficulty is ", $difficulty, "\n";

and I got "Difficulty 0"


do you know if bitcoind was actually already up and running or did your command launch it?

> ps aux|grep bit


Title: Re: [API] Difficulty needed.
Post by: scintill on January 17, 2012, 05:31:26 AM
looking here he got bitcoind, namecoind, and devcoind.

It's installed on /var/www/files/daemons/

I tried

Code:
$difficulty = (float)shell_exec('/var/www/files/daemons/bitcoind getdifficulty');
echo "Difficulty is ", $difficulty, "\n";

and I got "Difficulty 0"


do you know if bitcoind was actually already up and running or did your command launch it?

> ps aux|grep bit


Yeah, check that, and if the chain is synced up.  There is a "getblockcount" command that should be close to http://blockexplorer.com/q/getblockcount .

(If the server isn't started "bitcoind -daemon" is how I start it, maybe there are better ways.)