Bitcoin Forum
April 26, 2024, 08:22:03 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [API] Difficulty needed.  (Read 1314 times)
simon66 (OP)
Sr. Member
****
Offline Offline

Activity: 423
Merit: 250


View Profile
January 16, 2012, 10:29:34 PM
 #1

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.
1714162923
Hero Member
*
Offline Offline

Posts: 1714162923

View Profile Personal Message (Offline)

Ignore
1714162923
Reply with quote  #2

1714162923
Report to moderator
The forum strives to allow free discussion of any ideas. All policies are built around this principle. This doesn't mean you can post garbage, though: posts should actually contain ideas, and these ideas should be argued reasonably.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714162923
Hero Member
*
Offline Offline

Posts: 1714162923

View Profile Personal Message (Offline)

Ignore
1714162923
Reply with quote  #2

1714162923
Report to moderator
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
January 16, 2012, 10:57:40 PM
 #2

Every ?coind has an RPC command called getdifficulty to fetch current difficulty.

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
simon66 (OP)
Sr. Member
****
Offline Offline

Activity: 423
Merit: 250


View Profile
January 16, 2012, 11:19:29 PM
 #3

Every ?coind has an RPC command called getdifficulty to fetch current difficulty.

ummm. what? Lol
notme
Legendary
*
Offline Offline

Activity: 1904
Merit: 1002


View Profile
January 16, 2012, 11:21:24 PM
 #4

Every ?coind has an RPC command called getdifficulty to fetch current difficulty.

This.

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

https://www.bitcoin.org/bitcoin.pdf
While no idea is perfect, some ideas are useful.
scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 252


View Profile WWW
January 16, 2012, 11:22:25 PM
 #5

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.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
simon66 (OP)
Sr. Member
****
Offline Offline

Activity: 423
Merit: 250


View Profile
January 17, 2012, 12:52:38 AM
 #6

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.
payb.tc
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000



View Profile
January 17, 2012, 12:56:27 AM
 #7

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>
simon66 (OP)
Sr. Member
****
Offline Offline

Activity: 423
Merit: 250


View Profile
January 17, 2012, 01:02:48 AM
 #8

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
payb.tc
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000



View Profile
January 17, 2012, 01:16:55 AM
 #9

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);
?>

scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 252


View Profile WWW
January 17, 2012, 04:26:03 AM
 #10

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() 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 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.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
payb.tc
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000



View Profile
January 17, 2012, 04:31:23 AM
 #11

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() 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?
scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 252


View Profile WWW
January 17, 2012, 04:37:36 AM
 #12

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.

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
simon66 (OP)
Sr. Member
****
Offline Offline

Activity: 423
Merit: 250


View Profile
January 17, 2012, 05:09:10 AM
 #13

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"
payb.tc
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000



View Profile
January 17, 2012, 05:12:48 AM
 #14

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
scintill
Sr. Member
****
Offline Offline

Activity: 448
Merit: 252


View Profile WWW
January 17, 2012, 05:31:26 AM
 #15

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.)

1SCiN5kqkAbxxwesKMsH9GvyWnWP5YK2W | donations
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!