Bitcoin Forum
April 25, 2024, 09:05:32 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: via PHP-script/jsonRPC bitcoin versenden  (Read 2425 times)
Artlu (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
December 20, 2011, 04:51:13 PM
 #1

Hallo,

Ich möchte mit folgendem Code Bitcoin über ein php Script versenden:
Code:
require_once '../jsonRPCClient.php';
$bitcoin = new jsonRPCClient('http://*user*:*pass*@127.0.0.1:8332/');
...
...
var_dump($bitcoin->walletlock());
var_dump($bitcoin->walletpassphrase($password,10));
var_dump($bitcoin->sendtoaddress($to,$amount));
var_dump($bitcoin->walletlock());
Die Variablen $password, $to, $amount sind alle korrekt mit Werten zugewiesen. Die Ausgabe die ich bekomme ist folgende:
Code:
NULL
NULL

Warning: fopen(http://...@127.0.0.1:8332/): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
 in ***/jsonRPCClient.php on line 132

Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to http://*user*:*pass*@127.0.0.1:8332/' in ***/jsonRPCClient.php:140
Stack trace:
#0 [internal function]: jsonRPCClient->__call('sendtoaddress', Array)
#1 ***/content/bitcoin.php(79): jsonRPCClient->sendtoaddress('1Ln1a2exAmTumnF...', '1')
#2 ***/index.php(470): require('***...')
#3 {main}
  thrown in ***/jsonRPCClient.php on line 140
Über die Commandline kann ich mit walletpassphrase und sendtoaddress versenden, nur übers php script nicht.

Gibt es außerdem eine Übersicht welche Return-Values der einzelnen Funktionen welchem Ergebnis zugeordnet sind? Kein Rückgabewert ist nämlich nicht sehr aussagekräftig.

Wär schön wenn mir jemand hiermit helfen könnte und mich auf meinen (Denk)Fehler hinweisen könnte.
Die bitcoind version ist übrigens 0.5.1-beta

Vielen Dank!
"The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714079132
Hero Member
*
Offline Offline

Posts: 1714079132

View Profile Personal Message (Offline)

Ignore
1714079132
Reply with quote  #2

1714079132
Report to moderator
1714079132
Hero Member
*
Offline Offline

Posts: 1714079132

View Profile Personal Message (Offline)

Ignore
1714079132
Reply with quote  #2

1714079132
Report to moderator
Retard
Prime Minister
VIP
Sr. Member
*
Offline Offline

Activity: 448
Merit: 252


View Profile
December 20, 2011, 05:29:30 PM
 #2

leg in den ordner wo das script liegt eine php.ini mit url fopen allowed

sollte darauf hin funzen ausser bei den meisten free hostern
terrytibbs
Hero Member
*****
Offline Offline

Activity: 560
Merit: 501



View Profile
December 20, 2011, 05:33:55 PM
 #3

I understand nothing except for the error message and the fact that you're running 0.51, but try actually enabling the RPC server.

Windows: %AppData%/Bitcoin/bitcoin.conf:
Linux: ~/.bitcoin/bitcoin.conf:
Code:
server=1
rpcuser=USERNAME
password=PASSWORD

Remember to change the username and password and enter it when making the RPC connection in your PHP code.
Artlu (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
December 20, 2011, 06:10:10 PM
 #4

Danke für die Antworten.

url fopen ist bereits aktiviert, Aktionen wie getnewaddress, getreceivedbyaddress, listtransactions, ... funktionieren soweit auch. Ob walletpassphrase funktioniert oder nicht kann ich nicht sagen, aber sendtoaddress geht auf jeden Fall nicht. Ich habe die Vermutung dass das wallet nicht entsperrt wird und somit der Befehl sendtoaddress auch nicht funktioniert. Allerdings wird das Passwort zuvor korrekt übergeben und funktioniert auch über die commandline.

I already enabled the RPC server and set a username and password. Commands like getnewaddress, getreceivedbyaddress and so on are already working. Just sendtoaddress doesn't work. Thank you anyway for your help!
winnetou
Sr. Member
****
Offline Offline

Activity: 361
Merit: 250


View Profile
December 20, 2011, 06:22:45 PM
 #5

an was bastelst du denn feines? Smiley
Artlu (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
December 20, 2011, 06:45:45 PM
 #6

Wie bereits in diesem Thread beschrieben, habe ich Bitcoin als zusätzliches Zahlungsmittel aufgenommen. Da das wallet in das eingezahlt wird auf dem Server liegt, möchte ich die empfangenen Bitcoins natürlich auch in mein eigenes wallet transferieren. Dazu möchte ich nicht ständig über die commandline die Befehle eintippen. Über ein Interface ist das dann doch einfacher und schöner Wink
Auch Rückzahlungen o.ä. lassen sich so besser erledigen.
winnetou
Sr. Member
****
Offline Offline

Activity: 361
Merit: 250


View Profile
December 20, 2011, 07:02:36 PM
 #7

ahja stimmt, ganz vergessen, sorry für die doppelte nachfrage ^^
Retard
Prime Minister
VIP
Sr. Member
*
Offline Offline

Activity: 448
Merit: 252


View Profile
December 20, 2011, 07:10:22 PM
 #8

und wann stellst du uns deije seite vor ?
Artlu (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
December 21, 2011, 05:38:49 PM
 #9

Dafür werde ich mal noch einen aussagekräftigen Text formulieren und in den entsprechenden Bereich schreiben Wink
Allerdings besteht das Problem leider immernoch, und bisher konnte mir keiner bei meinem Problem weiterhelfen ...
Deswegen gibts 0.3 BTC für denjenigen der mich auf die Lösung bringt Smiley
winnetou
Sr. Member
****
Offline Offline

Activity: 361
Merit: 250


View Profile
December 21, 2011, 09:08:06 PM
Last edit: December 21, 2011, 09:22:45 PM by winnetou
 #10

Hast du in der Bitcoin Konfigurationsdatei den Zugang auf eine bestimmte IP begrenzt? (allowip)
Falls ja,
- wenn es nicht localhost ist versichere dich ob die ausgehende IP deines Webservers auch die IP in der Datei ist. (bei shared-hosting ist die ausgehende ip oft eine andere; kannst du zb schnell rausfinden indem du wieistmeineip.de per php ausliest) oder um den Fehler einzugrenzen mal alle IPs erlauben

Bitcoin client auch mit -server gestartet?^^

Ansonsten versuchs mal mit folgender json Klasse

Quote
<?php
class jsonRPCClient {
   
   /**
    * Debug state
    *
    * @var boolean
    */
   private $debug;
   
   /**
    * The server URL
    *
    * @var string
    */
   private $url;
   /**
    * The request id
    *
    * @var integer
    */
   private $id;
   /**
    * If true, notifications are performed instead of requests
    *
    * @var boolean
    */
   private $notification = false;
   
   /**
    * Takes the connection parameters
    *
    * @param string $url
    * @param boolean $debug
    */
   public function __construct($url,$debug = false) {
      // server URL
      $this->url = $url;
      // proxy
      empty($proxy) ? $this->proxy = '' : $this->proxy = $proxy;
      // debug state
      empty($debug) ? $this->debug = false : $this->debug = true;
      // message id
      $this->id = 1;
   }
   
   /**
    * Sets the notification state of the object. In this state, notifications are performed, instead of requests.
    *
    * @param boolean $notification
    */
   public function setRPCNotification($notification) {
      empty($notification) ?
                     $this->notification = false
                     :
                     $this->notification = true;
   }
   
   /**
    * Performs a jsonRCP request and gets the results as an array
    *
    * @param string $method
    * @param array $params
    * @return array
    */
   public function __call($method,$params) {
      
      // check
      if (!is_scalar($method)) {
         throw new Exception('Method name has no scalar value');
      }
      
      // check
      if (is_array($params)) {
         // no keys
         $params = array_values($params);
      } else {
         throw new Exception('Params must be given as array');
      }
      
      // sets notification or request task
      if ($this->notification) {
         $currentId = NULL;
      } else {
         $currentId = $this->id;
      }
      
      // prepares the request
      $request = array(
                  'method' => $method,
                  'params' => $params,
                  'id' => $currentId
                  );
      $request = json_encode($request);
      $this->debug && $this->debug.='***** Request *****'."\n".$request."\n".'***** End Of request *****'."\n\n";
      
      // performs the HTTP POST
        $ch = curl_init();
        curl_setopt_array($ch, array(
            CURLOPT_URL => $this->url,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $request,
            CURLOPT_HTTPHEADER => array('Content-type: application/json'),
            CURLOPT_RETURNTRANSFER => true,
        ));
        
        $response = curl_exec($ch);
        if($response === false)
        {
         throw new Exception('Unable to connect to '.$this->url);
         throw new Exception('Keine Verbindung zum Bitcoin Server moeglich. Bitte kontaktiere uns. ');
      }
        
        $this->debug && $this->debug.='***** Server response *****'."\n".$response.'***** End of server response *****'."\n";
        $response = json_decode($response,true);
      
      // debug output
      if ($this->debug) {
         echo nl2br($debug);
      }
      
      // final checks and return
      if (!$this->notification) {
         // check
         if ($response['id'] != $currentId) {
         throw new Exception('Incorrect response id (request id: '.$currentId.', response id: '.$response['id'].')');
         }
         if (!is_null($response['error'])) {
         throw new Exception('Request error: '.$response['error']['message']);
         }
         
         return $response['result'];
         
      } else {
         return true;
      }
   }
}
?>
LightningFury
Hero Member
*****
Offline Offline

Activity: 687
Merit: 509



View Profile
December 22, 2011, 11:52:08 AM
 #11

Code:
floatval($amount);

▄▄█████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄████████████████████
███▄
▄█████████████████████████▄
██████████████▄████████████
███████████████████████████
███████████████████████████
█████████████████████████▀
▀███████████████████████▀
▀█████████████████████▀
▀█████████████████▀
▀▀█████████▀▀
.dune network...
           ██
         ██▀▀██
         ██▄▄██
       ██▀▀██▀▀██
       ██▄▄██▄▄█████▀▀███
       ██▀▀██▀▀█████▄▄███
       ██▄▄██▄▄█████▀▀███
  ███████████▀▀█████▄▄███
  ██▌▐██▌▐███▄▄█████▀▀███
  ██▌▐██▌▐██████████▄▄███
  ██▌▐██▌▐██████████▀▀███
  ██▌▐██▌▐██████████▄▄███
█████████████
██████████████
►  Metal
     ►  Wallets
          ►  dApps
►  Blog
     ►  Resources
          ►  Community
.

██████████

██████
██████████████████████████████
.
.
██████████

████████████████████
██████████
Artlu (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
December 22, 2011, 04:18:56 PM
 #12

Code:
floatval($amount);
Danke, ich wusste es ist nur irgend ne Kleinigkeit die ich übersehen habe ... Jetzt hat $amount den richtigen Datentyp und schon funktioniert alles.
Wie versprochen habe ich dir 0.3 BTC auf die in deiner Signatur angegebene Adresse überwiesen. Ich hoffe das ist auch deine Wink
LightningFury
Hero Member
*****
Offline Offline

Activity: 687
Merit: 509



View Profile
December 23, 2011, 11:55:16 AM
 #13

np  Wink
Bitcoins sind angekommen thx  Cheesy

▄▄█████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄████████████████████
███▄
▄█████████████████████████▄
██████████████▄████████████
███████████████████████████
███████████████████████████
█████████████████████████▀
▀███████████████████████▀
▀█████████████████████▀
▀█████████████████▀
▀▀█████████▀▀
.dune network...
           ██
         ██▀▀██
         ██▄▄██
       ██▀▀██▀▀██
       ██▄▄██▄▄█████▀▀███
       ██▀▀██▀▀█████▄▄███
       ██▄▄██▄▄█████▀▀███
  ███████████▀▀█████▄▄███
  ██▌▐██▌▐███▄▄█████▀▀███
  ██▌▐██▌▐██████████▄▄███
  ██▌▐██▌▐██████████▀▀███
  ██▌▐██▌▐██████████▄▄███
█████████████
██████████████
►  Metal
     ►  Wallets
          ►  dApps
►  Blog
     ►  Resources
          ►  Community
.

██████████

██████
██████████████████████████████
.
.
██████████

████████████████████
██████████
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!