Skip to content
This repository was archived by the owner on Sep 4, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/src/.idea
/Vagrantfile
/.vagrant

# Composer
/vendor/
composer.lock

# IDE
/.idea

# For testing purposes
example.php
test.php

# Thanks macOS
.DS_Store
66 changes: 59 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# php-electrum-api - Electrum library with no dependencies
# php-electrum-api - Electrum library
```
Licence: GPL-3.0
Author: Pascal Krason <p.krason@padr.io>
Language: PHP 5.6
Language: PHP 5.6-7.1
```
Please note, this library is by far not completed and production ready, there are still a lot methods which aren't neither tested or even implemented.
Please note, this library is by far not completed and but can be used in production. Until now i only implemented the most commonly used API-Calls. If you think im missing something, just create an issue or fork the project.

# Setting up Electrum
First you need to setup a new Electrum wallet. Follow the instructions according to your OS at the [Electrum Download Page](https://electrum.org/#download). After the successfull installation you need to set a rpcport by typing:
Expand All @@ -19,9 +19,13 @@ Now we can go ahead and start Electrum in daemon mode:
```
electrum daemon start
```
Since some new version electrum wants you to load your wallet by hand on startup:
```
electrum daemon load_wallet
```

# Requirements
On the PHP side there are not much requirements, you only need atleast PHP 5.6 and the curl-Extension installed. Optional you need [Composer](http://getcomposer.org) to install this library.
On the PHP side there are not much requirements, you only need at least PHP 5.6 and the curl-Extension installed. Then you can go ahead ans it through [Composer](http://getcomposer.org) which will do everything else for you.

# Install
First you need to install [Composer](https://getcomposer.org/doc/00-intro.md), after you accomplished this you can go ahead:
Expand All @@ -32,8 +36,56 @@ Then you can simply include the autoloader and begin using the library:
```php
// Include composer autoloader
require_once 'vendor/autoloader.php';
```

# Examples

## Basic example
A very basic useage example. Every API-Call has it's own request-object. You simply create one and execute it.
```php

$method = new \Electrum\Request\Method\Version();

try {
$response = $method->execute();
} catch(\Exception $exception) {
die($exception->getMessage());
}

// Create new instance
$electrum = new \Electrum\Client('http://127.0.0.1/', 7777);
$electrum->getVersion();
$response->getVersion();
```

## Custom Client Configuration
Every Request/Method takes a `Electrum\Client`-instance as parameter which replaces the default one. A custom instance can be usefull if you want to set custom config params like another Hostname or Port.
```php
$client = new \Electrum\Client('http://127.0.0.1', 7777);
$method = new \Electrum\Request\Method\Version($client);

try {
$response = $method->execute();
} catch (\Exception $exception) {
die($exception->getMessage());
}

$response->getVersion();
```

## Advanced exception handling
Dealing with exceptions is easy. You can catch two types of exceptions which indicates whether it's an Request or Response fault.
```php
$method = new \Electrum\Request\Method\Version();

try {
$response = $method->execute();
} catch (\Electrum\Request\Exception\BadRequestException $exception) {
die(sprintf(
'Failed to send request: %s',
$exception->getMessage()
));
} catch(\Electrum\Response\Exception\ElectrumResponseException $exception) {
die(sprintf(
'Electrum-Client failed to respond correctly: %s',
$exception->getMessage()
));
}
```
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"email": "p.krason@padr.io"
}
],
"require": {},
"require": {
"zendframework/zend-hydrator": "^2.2"
},
"autoload": {
"psr-4": {
"Electrum\\": "src"
Expand Down
Loading