GithubHelp home page GithubHelp logo

aceat64 / easybitcoin-php Goto Github PK

View Code? Open in Web Editor NEW
283.0 35.0 244.0 11 KB

A simple class for making calls to Bitcoin's API using PHP. This is an old library, I suggest instead using https://github.com/denpamusic/php-bitcoinrpc

License: MIT License

PHP 100.00%

easybitcoin-php's Introduction

EasyBitcoin-PHP

A simple class for making calls to Bitcoin's API using PHP.

Getting Started

  1. Include easybitcoin.php into your PHP script:

    require_once('easybitcoin.php');
  2. Initialize Bitcoin connection/object:

    $bitcoin = new Bitcoin('username','password');

    Optionally, you can specify a host, port. Default is HTTP on localhost port 8332.

    $bitcoin = new Bitcoin('username','password','localhost','8332');

    If you wish to make an SSL connection you can set an optional CA certificate or leave blank

    $bitcoin->setSSL('/full/path/to/mycertificate.cert');
  3. Make calls to bitcoind as methods for your object. Examples:

    $bitcoin->getinfo();
    
    $bitcoin->getrawtransaction('0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098',1);
    
    $bitcoin->getblock('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');
    
    $bitcoin->bumpfee('f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', ["fee_rate" => 50]);

Additional Info

  • When a call fails for any reason, it will return false and put the error message in $bitcoin->error

  • The HTTP status code can be found in $bitcoin->status and will either be a valid HTTP status code or will be 0 if cURL was unable to connect.

  • The full response (not usually needed) is stored in $bitcoin->response while the raw JSON is stored in $bitcoin->raw_response

easybitcoin-php's People

Contributors

aceat64 avatar axelay avatar wqeqwew avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easybitcoin-php's Issues

Can not create a new Adress

Hello this is my code

require_once('templates/easybitcoin.php');
$bitcoin = new Bitcoin('user','pw','localhost','8332');

$adress = $bitcoin->getnewaddress("myname");

But the $adress is null.
It wont create the adress but why?
And how can i create a adress and store it into a string?

Empty reply from server

hello dear i m trying to use easybitcoin to connect my bitcoind daemon to get wallet info and etc etc.
i m using bitcoin.conf file

server=1
daemon=1
rpcallowip=connecting server ip/0
rpcuser=username of mine
rpcpassword=password
rpcport=8333
listen=1
keypool=10000
prune=600
maxuploadtarget=20
maxconnections=16
walletnotify=/var/www/html/cron/receive.sh %s

and in easy bitcoin i m connecting like this

"; $info = $bitcoin->getinfo(); print_r($info); echo "
"; print_r($bitcoin->getwalletinfo() ); echo"
"; echo $info ? $info : "Oops an error: ".$bitcoin->error; ?>

it give me output
Empty server reply

what is wrong in my code please any one help me????

How to make calls when script is run as daemon?

I realize this isn't an issue, but I thought I might be able to get the best advice here.

I've written a script that makes RPC calls using EasyBitcoin-PHP. When I run this script directly everything works fine.

However, I'd like to run this script as a daemon using systemd. When I start the daemon using systemctl start myscript, I see the following error:

error: Could not locate RPC credentials. No authentication cookie could be found, and no rpcpassword is set in the configuration file (/.bitc...

I think this may be because the script is being executed as root, and so it can't find the location of ~/bitcoin/bitcoin.conf correctly.

What would be the best way to get around this?

unsure how or why my lockunspent method is not working...

I have been trying for days, and I cannot seem to understand why the EasyBitcoin.php will not accept my parameters for locking unspent transactions using the rpc calls. Here is the code I am using;

$tx = $bitcoin->masternode('outputs');
$txid = array_keys($tx);
$tx_array = [];
	foreach($txid as $locktx) {
          $tx_array = [
                'txid'  => $locktx,
                'vout'  => (int)$tx[$locktx],
            ];
    $lock = "false";
		$lock_mn = $bitcoin->lockunspent($lock, $tx_array);
}

And no matter how I spin it, I keep getting errors like this:

Expected type bool, got string

Has anyone had any success with this rpc command?

500 error

On ubuntu server, I've tried a few different ways, and every time I get the following:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)

I can do a getinfo from command line successfully.

Any ideas?

error to start main.py

python main.py -c ../.bitcoin/
Traceback (most recent call last):
File "main.py", line 11, in
from gevent import monkey
ImportError: No module named gevent

bitcoind won't send bitcoins from wallet

I'm using library for PHP https://github.com/aceat64/EasyBitcoin-PHP

I'm trying to unlock wallet using

`<?php

require 'func/ezbtc.php';

$bitcoin = new Bitcoin('admin','admin', 'localhost', '7788');

$bitcoin->walletpassphrase('PASSWORD', '30');

?>`

Instead of PASSWORD there is real password for wallet.

But when I try to send some bitcoins to another wallet it just not working.
No errors, nothing.

What's wrong?

Windows

What do i need to install in my windows computer to use this script?
i want my website users to have their wallet on my website. So they can send and receive bitcoins into the wallet

Parse error 32700

To solve that error

{"result":null,"error":{"code":-32700,"message":"Parse error"},"id":1}

it's required to comment out line 120:

CURLOPT_FOLLOWLOCATION => true,

Username Password

Hi
To make this connection ====>
$bitcoin = new Bitcoin('username','password');
From where i get this username and password..Please guide me

Username / Password ?

Looking at the code here ...
What site are you calling the username/password for ? What is this connected too.

thanks, great work too!

Thank you so much for this Andrew!

I know this isn't an issue but I wanted to find a contact but couldn't find one so I left a message here. Thank you for creating this. I created a website that uses a different type of cryptocurrency but works just as well. This made things so much easier and https still works as of 2019! Thanks again and it's so simple and elegant!

Cheers~
patrikpatrik

How Can I pass params?

Hello,
your library is very useful for me. I need some suggestion:
How can I pass parameters ?
I'm using this:

$params = array("I" => "SI");
$bitcoin->method($params);

Is that correct?

Handle much address like 1 million address

Hi ..
i try want to build website with API service provider like
block.io

so i compile bitcoin-cli daemon in 1 vps. and created 1 vps more for backend using php
and i connected with your library

now i have a 25k address in my bitcoin wallet.dat .
and now i feel the proccess is slow .
what the best technical for this case ??
any help ?
sory for oot

Bitcoind returns error “JSON value is not an array as expected”, using easybitcoin.php to call sendmany()

[Posted the below in stackoverflow as well]
Link: Here

I am creating a php script to use the sendmany() call to bitcoind. After some database calisthenics involving hitting three tables for permissions, checking user privileges and ensuring the send amounts are correct and there are enough bitcoins on the server, I wind up with the following array to send bitcoins to:

Array
(
    [0] => Array
        (
            [coinadd] => mteCLqiEK7v5d3YbDQtxj8oKcdhtHRtXcw
            [amount] => 0.21445033
        )

    [1] => Array
        (
            [coinadd] => 2N5aa9FBxGf5xmeLiDz1yJVNYdsfK9GUWWe
            [amount] => 0.02588679
        )

    [2] => Array
        (
            [coinadd] => 2Muf4WEzFqNviURTdvkGSswHyrgMzR8optK
            [amount] => 0.02601681
        )

)

$max = count($paynow);
$b=1;
$amount = 0;
$emit = '{"';
foreach($paynow as $key => $val){
    foreach($val as $k => $v){
        $emit .= "$v";
        if($b <= $max){
            if($k == 'coinadd'){
                $emit .= '":';
            } elseif($k == 'amount') {
                $amnt = $amount += $v;
                if($b !== $max){
                    $emit .= ', "'; 
                }               
            }
        }
    }
    $b++;
}
$emit .= "}";

The above foreach takes the $paytoo array and generates the following json string:

{
"mteCLqiEK7v5d3YbDQtxj8oKcdhtHRtXcw":0.21445033, "2N5aa9FBxGf5xmeLiDz1yJVNYdsfK9GUWWe":0.02588679, "2Muf4WEzFqNviURTdvkGSswHyrgMzR8optK":0.02601681
}

This string passes the JSON lint test on jsonlint.com

I then decode the string to create an array.

$send = json_decode($emit,true);

Array
(
    [mteCLqiEK7v5d3YbDQtxj8oKcdhtHRtXcw] => 0.21445033
    [2N5aa9FBxGf5xmeLiDz1yJVNYdsfK9GUWWe] => 0.02588679
    [2Muf4WEzFqNviURTdvkGSswHyrgMzR8optK] => 0.02601681
)

So far so good.

Now on to the RPC call

$sent = $bitcoin->sendmany( "", $send, 1, "", "", 1, 1, "CONSERVATIVE" );
$err = $bitcoin->error;

Aaaand Kablooie! I get the following error from Bitcoind:

"JSON value is not an array as expected"

If I turn the JSON string into an object, then the error switches to

"JSON value is not an object as expected".

From a comment in Github Here
This snippet of code is from the library's __call method in easybitcoin.php

// If no parameters are passed, this will be an empty array
$params = array_values($params);

// Build the request, it's ok that params might have any empty array
$request = json_encode(array(
    'method' => $method,
    'params' => $params,
    'id'     => $this->id
));So depending on the parameters of the RPC command the general format will be the following.
$myVar->nameofRPCcommand(...);

For example a command that takes two strings will be
$myVar->nameofRPCcommand($myStr1, $myStr2);

Or with a string followed by an array
$myVar->nameofRPCcommand($myStr, $myArr);

Other than slitting my wrists and offering my blood to the programming gods, I've done everything I can think of. Can anyone spot what I am doing wrong here?

NULL value returned for call

i tried to run a command that has the following structure bitcode-cli getaddressdeltas '{"addresses": ["Bh22SsBJyeAJY3vmc8EEd12HWMtM85c7C0"]}' using the EasyBitcoin-PHP script but it returns NULL. How can i modify the code to accept the command?

Wrong status code

$bitcoin->status returns me everytime a empty string "", but all rpc call work perfect!

What is the problem? How can i detect when I can't connect to RPC?

Is there a way to specify the wallet file?

I'm running bitcoind with multiple wallets since they just added the support for it in their last release. However, I don't see any way to specify the .dat file for the wallet here. Is this possible? If so, how would I do this?

getblocktemplate no longer works

Hi there,

Since Bitcoin 0.13.1 (segwit), the getblocktemplate() method no longer returns anything.

I think this is due to the fact that you now need to specify a rule when calling getblocktemplate. For example, if you call:

bitcoin-cli getblocktemplate

You get this error:

error code: -8
error message:
Support for 'segwit' rule requires explicit client support

To get it working, you have to pass a rule like this as an extra argument, like so:

bitcoin-cli getblocktemplate '{"rules":["segwit"]}'

Is there any way to pass this argument to the $bitcoin->getblocktemplate() method to get it working again?

"JSON value is not an integer as expected"

trying to get block 502284

$bitcoin->getblockhash('502284')

getting

(
[result] =>
[error] => Array
(
[code] => -1
[message] => JSON value is not an integer as expected
)

[id] => 1

why incementing id?

  // The ID should be unique for each call
        $this->id++;

why do you need this?
if id is always 0, and not unique for each call, what will happen?
when I checked with some commands, it seemed fine.

sorry for my english.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.