Apr 25, 2014 11:10 AM
(This post was last modified: Apr 25, 2014 11:19 AM by ScreamX.)
OmniCoind has remote procedure call function within it. This allows you to communicate with your OmniCoin daemon remotely. You can use this functionality to make things like wallets, block explorers, autobuy systems, etc. All you need is a little PHP knowledge.
To make life really easy, we're going to use a library called jsonRPCClient. You can download it here. I used the lite version, inside the includes folder, you only need the file jsonRPCClient.php.
Make sure your configuration of the server reflects that you want to allow RPC connection. Your config should be something like the one below. Your config file will be located at ~/.OmniCoin
For security reasons, you NEED to change rpcuser, rpcpassword, and rpcallowip. rpcallowip should be set to the ip address that your remotely connecting from. It's intensely unsecure to leave it set at * (which means anyone can connect to it.)
Create a new PHP file, in notepad or some other PHP text editor. Inside put the following.
This snippet will include the jsonRPCClient.php, which is the library you downloaded. Then, it initiates it's connection with your OmniCoin server. You need to set the fields that are in brackets username, password, ip-address. If your port is different than 4355, you'll need to update that as well.
After you have a successfuly connection, you can execute any command within the OmniCoin server simply by calling it directly.
Example: (This command will print out the same data as it would from the server's command line directly.
Another Example:
This snippet will pull the 10 most recent transactions, parse them and order them inside a table by the most recent transaction.
Thanks for reading, I hope it was useful.
To make life really easy, we're going to use a library called jsonRPCClient. You can download it here. I used the lite version, inside the includes folder, you only need the file jsonRPCClient.php.
Make sure your configuration of the server reflects that you want to allow RPC connection. Your config should be something like the one below. Your config file will be located at ~/.OmniCoin
Code
rpcuser=YOURUSERNAME
rpcpassword=MAKETHISLONGANDDIFFICULT
rpcallowip=*
rpcport=4355
server=1
daemon=1
(nodes go here)Create a new PHP file, in notepad or some other PHP text editor. Inside put the following.
PHP Code
<?php
require("jsonRPCClient.php");
$omc = new jsonRPCClient("httpd://[username]:[password]@[ip-address]:4355/");
?>After you have a successfuly connection, you can execute any command within the OmniCoin server simply by calling it directly.
Example: (This command will print out the same data as it would from the server's command line directly.
PHP Code
<?php
require("jsonRPCClient.php");
$omc = new jsonRPCClient("httpd://username:[email protected]:4355/");
print_r($omc->getinfo());
?>Another Example:
This snippet will pull the 10 most recent transactions, parse them and order them inside a table by the most recent transaction.
PHP Code
<?php
<table class="transaction">
<tr>
<th>Direction</th>
<th>From</th>
<th>Amount</th>
<th>Confirmations</th>
<th>Time</th>
</tr>
<?php
$data = $omc->listtransactions($username, 10);
$data = json_encode(array_reverse($data));
$data = json_decode($data);
foreach($data as $item) {
echo "<tr>";
echo "<td>" . $item->category . "</td>";
echo "<td>" . $item->address . "</td>";
echo "<td>" . $item->amount . "</td>";
echo "<td>" . $item->confirmations . "</td>";
echo "<td>" . floor((time() - $item->time) / 60) . " Minutes ago</td>";
}
?>
</table>
Thanks for reading, I hope it was useful.
<?php echo "I'm a professional web developer, if you need something ask me."; ?>


