1. Go to this page and download the library: Download refring/monero-rpc-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
refring / monero-rpc-php example snippets
$walletClient = (new \RefRing\MoneroRpcPhp\ClientBuilder('http://127.0.0.1:18081/json_rpc'))
->buildWalletClient();
echo $walletClient->getVersion()->version;
$daemonClient = (new \RefRing\MoneroRpcPhp\ClientBuilder('http://127.0.0.1:18081/json_rpc'))
->buildDaemonClient();
echo $daemonClient->getVersion()->version;
$daemonClient = (new \RefRing\MoneroRpcPhp\ClientBuilder('http://127.0.0.1:18081/json_rpc'))
->withAuthentication('foo', 'bar')
->buildDaemonClient();
echo $daemonClient->getVersion()->version;
$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();
$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();
// 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);
bash
composer
bash
composer php-http/curl-client
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.