Skip to content
This repository was archived by the owner on Sep 4, 2021. It is now read-only.

Commit 54fb3d3

Browse files
Update README.md
Added a few examples how to generate a new Payment and generate a new address
1 parent f57b8ab commit 54fb3d3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,38 @@ try {
6060
$response->getVersion();
6161
```
6262

63+
## Get new address
64+
```php
65+
$client = new \Electrum\Client('http://127.0.0.1', 7777, 0, 'user', 'password');
66+
$wallet = new \Electrum\Request\Method\Payment\AddRequest($client);
67+
$tx = $wallet->execute();
68+
echo $tx->getAddress();
69+
```
70+
71+
## Make a new Payment
72+
```php
73+
$client = new \Electrum\Client('http://127.0.0.1', 7777, 0, 'user', 'password');
74+
$method = new \Electrum\Request\Method\Payment\PayTo($client);
75+
$method->setDestination('BTC4ddress1234'); //Destination parameter is the address where we'll send the btc
76+
$method->setAmount(1); //send 1 BTC = 10k usd
77+
78+
$tx = $method->execute(); //$tx returns the transaction ID of the payment, this is still not sent to the blockchain
79+
/**
80+
* @param array ['password' => '<password>']
81+
* If the Electrum wallet is encrypted with a password use the following execute method instead
82+
* The previous one will return an error of "Password required"
83+
*/
84+
//$tx = $method->execute(['password' => 'myPass123']); //
85+
86+
$broadcast = new Electrum\Request\Method\Payment\Broadcast($client);
87+
$broadcast->setTransaction($tx);
88+
$result = $broadcast->execute(); //broadcasts payment to the blockchain
89+
echo $result;
90+
91+
A payment has been made
92+
93+
```
94+
6395
## Custom Client Configuration
6496
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.
6597
```php

0 commit comments

Comments
 (0)