3

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?

7

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'
  • Thank you so much serhack, maxithi for your reply. But i have some more doubt that which path i have to given in the place of "/path/walletfile" in the first command " monero-wallet-rpc --rpc-bind-port 18082 --disable-rpc-login --wallet-file /path/walletfile ". I execute it and gave the wallet password then it shows $ monero-wallet-rpc --rpc-bind-port 18082 --disable-rpc-login --wallet-file /path/walletfile – Albert Feb 1 '18 at 10:28
  • output: ERROR wallet.wallet2 src/wallet/wallet2.cpp:2499 e || !exists. THROW EXCEPTION: error::file_not_found WARN net.http src/wallet/wallet_errors.h:707 /DISTRIBUTION-BUILD/src/wallet/wallet2.cpp:2499:N5tools5error15file_error_baseILi1EEE: file not found "/path/walletfile.keys" ERROR wallet.rpc src/wallet/wallet_rpc_server.cpp:1887 Wallet initialization failed: file not found "/path/walletfile.keys" and i just tried again with the path where my wallet installed in the server, it again shows the same error. – Albert Feb 1 '18 at 10:28
  • kindly expect your reply... – Albert Feb 1 '18 at 10:32
  • Dear Albert, thank you so much for appreciating my work. You have to put the flag "--walletfile nameofyourwallet", where nameofyourwallet is the path to your wallet. If the wallet is in the same path of monero rpc, you have to put only the name of wallet. – SerHack Feb 1 '18 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.