I have installed my Monero CLI wallet on my Amazon server with this help.
I want to communicate with this wallet using php. I tried with this library but it is not connecting properly.
Can anyone please help me make it work or find another library?
I have installed my Monero CLI wallet on my Amazon server with this help.
I want to communicate with this wallet using php. I tried with this library but it is not connecting properly.
Can anyone please help me make it work or find another library?
In order to communicate via php with a Monero wallet you have to run Monero Wallet RPC.
monero-wallet-rpc --rpc-bind-port 18082 --disable-rpc-login --wallet-file /path/walletfile
If you are using a remote node, simply add to command the --daemon-host node.moneroworld.com:18089 flag.
That command will build a JSON API avaiable on the 18082 port. You can check if that works by typing http://127.0.0.1:18082/json_rpc in your browser.
Let's use the Monero PHP library in order to call some functions in your wallet.
<?php
// Example of Monero RPC Connection
require_once('src/jsonRPCClient.php');
require_once('src/Monero_Payments.php');
// Edit it with your ip and your port of Monero RPC
$monero_rpc = new Monero_Payments('127.0.0.1','18082');
In this way, you created the instance of Monero PHP library. All the calls are in details on this page.
For each call of Monero Wallet RPC, there is one function in the Monero PHP library.
Example:
Calling getaddress function
// Get address from Monero RPC
$address = $monero_rpc->getaddress();
// Print the RPC Response
$monero_rpc->print($address);
The RPC response will be printed as JSON. For getaddress call, it's
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"address": "42uMGYwvLuUGJzqdWZvr47CGCBz1qNNExZeegcjLPMbaFkBb3XGg6Y1bUwaMbovzGWDXtaASxSBYtaiBB4wuDmrAMCygexH",
"addresses": [
{
"address": "42uMGYwvLuUGJzqdWZvr47CGCBz1qNNExZeegcjLPMbaFkBb3XGg6Y1bUwaMbovzGWDXtaASxSBYtaiBB4wuDmrAMCygexH",
"address_index": 0,
"label": "Primary account",
"used": false
},
{
"address": "82qL8g5h9jvQGroSuDxZASAERKZPf7DQC8784YGmUPrdRp4TTo4KdruDfWUZkmWwWtCzP6buA9yYaWRmXXH7JkAPFXDtwuQ",
"address_index": 1,
"label": "",
"used": false
}
]
}
}
If you don't understand PHP library, you can try to call getaddress by curl.
$ curl -X POST http://127.0.0.1:18082/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"getaddress"}' -H 'Content-Type: application/json'