Bitcoin Forum
April 25, 2024, 10:46:58 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Need coinhive code examples (php)  (Read 348 times)
philwire (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
November 05, 2017, 01:26:40 PM
 #1

Hi everyone,
I just discovered coinhive and wanted to fiddle with it with a personal lamp server in a virtual machine for testing purposes. Coinhive's documentation is pretty limited and real life makes it that I often have to interrupt my coding & testing sessions. However I've been lurking and reading in the cryptocurrency for about 2 years and I would like to have a small and unique faucet project.

Up to now, my web skills are pretty limited to installing WordPress scripts and moving mysql data around with php. I want to get to the next level of web integration, and with good examples I can learn quickly. Basically I'm trying to tell my php machine to fetch the json data and display it to the screen. Then, later on I would like to store the json data in a mysql database so I could show some stats. But up to now, all I get is either blank pages or http 500 errors. Even just making a simple console to graph the data is overwhelming. btw, do I need to have a https certificate to fetch https urls? That shows how much behind I feel like Tongue

While searching, I landed on beniamino38's hivefaucet wich was exactly the general idea I had in mind, except with a few variances like rewarding with more coins than btc or monero. I also thought of some forum "like" or "up" button that would hash a little before accepting, therefore showing a true value of encouragement to the poster (since the liker spent some cpu cycles for him/her), then sharing something like 1/3 to the poster, the liker and the hoster.

But again, usable examples are lacking, so useable examples would help me a lot. I'll make sure to share my creation asap Smiley
1714042018
Hero Member
*
Offline Offline

Posts: 1714042018

View Profile Personal Message (Offline)

Ignore
1714042018
Reply with quote  #2

1714042018
Report to moderator
1714042018
Hero Member
*
Offline Offline

Posts: 1714042018

View Profile Personal Message (Offline)

Ignore
1714042018
Reply with quote  #2

1714042018
Report to moderator
1714042018
Hero Member
*
Offline Offline

Posts: 1714042018

View Profile Personal Message (Offline)

Ignore
1714042018
Reply with quote  #2

1714042018
Report to moderator
Every time a block is mined, a certain amount of BTC (called the subsidy) is created out of thin air and given to the miner. The subsidy halves every four years and will reach 0 in about 130 years.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714042018
Hero Member
*
Offline Offline

Posts: 1714042018

View Profile Personal Message (Offline)

Ignore
1714042018
Reply with quote  #2

1714042018
Report to moderator
1714042018
Hero Member
*
Offline Offline

Posts: 1714042018

View Profile Personal Message (Offline)

Ignore
1714042018
Reply with quote  #2

1714042018
Report to moderator
BitBustah
Hero Member
*****
Offline Offline

Activity: 1218
Merit: 534



View Profile
November 05, 2017, 01:50:09 PM
 #2

Share your code and I'll take a look at it.
philwire (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
November 06, 2017, 12:07:02 AM
 #3

Hi, thanks for your reply. Here's my starting code, just to be able to handle a json string from php:

Code:
<?php 
$url
=sprintf('php://api.coinhive.com/user/balance?secret=MySecretKey&name=SomeName');
$data=file_get_contents($url);
$json=json_decode($data);
foreach (
$json as $character) {
echo $character->name '<br>';
}
 
?>


This shoots out a http error 500 on my box.
Any help appreciated.
MrFatoni
Full Member
***
Offline Offline

Activity: 169
Merit: 100

SORRY


View Profile
November 06, 2017, 03:17:35 AM
 #4

Hi, thanks for your reply. Here's my starting code, just to be able to handle a json string from php:

Code:
<?php 
$url
=sprintf('php://api.coinhive.com/user/balance?secret=MySecretKey&name=SomeName');
$data=file_get_contents($url);
$json=json_decode($data);
foreach (
$json as $character) {
echo $character->name '<br>';
}
 
?>


This shoots out a http error 500 on my box.
Any help appreciated.


try change php://api.coinhive.com to https://api.coinhive.com

I'm sorry for everything
philwire (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
November 06, 2017, 03:29:48 AM
 #5

Alright, now it gives a blank page. However if I check the source it printed a few <br>'s so this might mean progress
philwire (OP)
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
November 06, 2017, 03:58:01 AM
 #6

Alright i finally got it by fiddling with some php answers over the net. For future reference, here's how to show a name and balance of a user:

Code:
<?php
$url 
"https://api.coinhive.com/user/balance?secret=SecretAPIkey&name=UserToLookup";
$json file_get_contents($url);
$json_data json_decode($jsontrue);
echo 
"My name: "$json_data["name"];
echo 
"<br>My balance: "$json_data["balance"];
?>


Cheers! Smiley
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!