Giter Club home page Giter Club logo

monero-rpc-php's Introduction

Monero Daemon & Wallet RPC client

Latest Stable Version Tests PHPStan codecov PHP Version Require

Monero daemon and wallet RPC client library written in modern PHP.

Features

  • Implements Monero wallet and daemon rpc methods
  • Support authentication for the wallet and daemon rpc servers
  • Fully strongly typed and strict_types enabled
  • Minimal dependencies
  • PSR-18 compatible, so different http client libraries can be used

Installation

You can install the package with Composer, at this this time minimum-stability has to be set to dev:

composer require refring/monero-rpc-php

When your project does not have a http client available yet, you should require one as well.

Different http clients can be used:

guzzle

composer require guzzlehttp/guzzle
Other http clients

symfony http client

composer require symfony/http-client psr/http-client nyholm/psr7

buzz

composer require kriswallsmith/buzz nyholm/psr7

php-http/curl-client

composer php-http/curl-client

Setup

Creating a client

For the wallet rpc client:

$walletClient = (new \RefRing\MoneroRpcPhp\ClientBuilder('http://127.0.0.1:18081/json_rpc'))
    ->buildWalletClient();

echo $walletClient->getVersion()->version;

Daemon rpc client:

$daemonClient = (new \RefRing\MoneroRpcPhp\ClientBuilder('http://127.0.0.1:18081/json_rpc'))
    ->buildDaemonClient();

echo $daemonClient->getVersion()->version;

Using authentication

$daemonClient = (new \RefRing\MoneroRpcPhp\ClientBuilder('http://127.0.0.1:18081/json_rpc'))
    ->withAuthentication('foo', 'bar')
    ->buildDaemonClient();

echo $daemonClient->getVersion()->version;

Connecting through a proxy

Configuring a proxy is specific to the http client library.

Below is a Symfony Http Client example for a socks5 proxy:

$httpClient = new Psr18Client(new CurlHttpClient([
    'http_version' => '2.0',
    'proxy' => 'socks5://username:[email protected]:9999',
]));

$daemonClient = (new \RefRing\MoneroRpcPhp\ClientBuilder('http://examplenode/json_rpc'))
    ->withHttpClient($httpClient)
    ->buildDaemonClient();

Injecting a logger

The client builder also supports injecting a logger and/or a http client:

$httpClient = new \Symfony\Component\HttpClient\Psr18Client();
$logger = new \Psr\Log\NullLogger();

$daemonClient = (new \RefRing\MoneroRpcPhp\ClientBuilder('http://127.0.0.1:18081/json_rpc'))    
    ->withHttpClient($httpClient)
    ->withLogger($logger)
    ->buildDaemonClient();

Usage

Creating a wallet and account

// Try to create a wallet, or open it when it already exists
try{
    $walletClient->createWallet('testwallet', 'English', 'password');
} catch (WalletExistsException $e) {
    $walletClient->openWallet('testwallet', 'password');
} catch(MoneroRpcException $e) {
    echo 'An error occured: '.$e->getMessage();
}

$baseAddressData = $walletClient->getAddress();
$subAddressData = $walletClient->createAddress();

printf("BaseAddress: %s\nSubAddress: %s\n", $baseAddressData->address, $subAddressData->address);

// Create another account
$newAccountData = $walletClient->createAccount('another account');
$newAccountSubAddress = $walletClient->createAddress($newAccountData->accountIndex);

printf("Account %d\nBaseAddress: %s\nSubAddress: %s", $newAccountData->accountIndex, $newAccountData->address, $newAccountSubAddress->address);

Testing

The project has unit tests and integration tests, the unit tests can be run using composer test:unit

To run the integration tests, you'll need docker and docker compose or you could run monerod and monero-wallet-rpc on your own.

If you have the docker stack installed, go to the tests folder and run docker compose up. Note that the daemon will run on port 18081 and monero-wallet-rpc will run on port 18083.

After that, run composer test:integration to run the integration tests.

Roadmap

  • More integration tests
  • Improve documentation and add examples

Contributing

See CONTRIBUTING.md

Changelog

See CHANGELOG.md

License

The MIT License (MIT). Please see License File for more information.

Acknowledgments

  • monero-rpc-rs - Parts of this project served as inspiration.
  • monero-php - Thanks for providing the php ecosystem with a Monero library during all these years!
  • Monero - Thanks to everybody involved!

monero-rpc-php's People

Contributors

dependabot[bot] avatar refring avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

recanman

monero-rpc-php's Issues

Call to undefined function RefRing\MoneroRpcPhp\Model\bcdiv()

#0 [my project]/vendor/refring/monero-rpc-php/src/Model/Amount.php(24): RefRing\MoneroRpcPhp\Model\Amount->toDenomination()
#1[my project]/MoneroPaymentService.php(184):` RefRing\MoneroRpcPhp\Model\Amount->toXmr()

private function toDenomination(int $denomination): string
{
    return bcdiv($this->amount, (string) $denomination, 12);
}

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.