Author

Topic: [API] Difficulty needed. (Read 1314 times)

sr. member
Activity: 448
Merit: 252
January 17, 2012, 01: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.)
hero member
Activity: 812
Merit: 1000
January 17, 2012, 01: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
sr. member
Activity: 423
Merit: 250
January 17, 2012, 01: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"
sr. member
Activity: 448
Merit: 252
January 17, 2012, 12:37:36 AM
#12
here you go... a bullet-proof php attempt:

Code:
$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.
hero member
Activity: 812
Merit: 1000
January 17, 2012, 12: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:
$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?
sr. member
Activity: 448
Merit: 252
January 17, 2012, 12: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:
$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.
hero member
Activity: 812
Merit: 1000
January 16, 2012, 09:16:55 PM
#9
for nmc, you could try scraping this page:

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

Code:

Namecoin difficulty


















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

sr. member
Activity: 423
Merit: 250
January 16, 2012, 09:02:48 PM
#8
for nmc, you could try scraping this page:

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

Code:

Namecoin difficulty


Block Time Difficulty Ratio
Last change 38304 16/01/2012 07:06 516'181.44 x1.04
















I was gonna do that, but there has to be an easier method. I'll wait on the "bitcoind getdifficulty" thingy
hero member
Activity: 812
Merit: 1000
January 16, 2012, 08:56:27 PM
#7
for nmc, you could try scraping this page:

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

Code:

Namecoin difficulty


Block Time Difficulty Ratio
Last change 38304 16/01/2012 07:06 516'181.44 x1.04















sr. member
Activity: 423
Merit: 250
January 16, 2012, 08:52:38 PM
#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.
sr. member
Activity: 448
Merit: 252
January 16, 2012, 07: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.
legendary
Activity: 1904
Merit: 1002
January 16, 2012, 07: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)
sr. member
Activity: 423
Merit: 250
January 16, 2012, 07:19:29 PM
#3
Every ?coind has an RPC command called getdifficulty to fetch current difficulty.

ummm. what? Lol
legendary
Activity: 1862
Merit: 1011
Reverse engineer from time to time
January 16, 2012, 06:57:40 PM
#2
Every ?coind has an RPC command called getdifficulty to fetch current difficulty.
sr. member
Activity: 423
Merit: 250
January 16, 2012, 06: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.
Jump to:
© 2020, Bitcointalksearch.org
Block Time Difficulty Ratio
Last change 38304 16/01/2012 07:06 516'181.44 x1.04