Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

OMC 

[Tutorial] Using the JSON RPC API (OmniCoind API)

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
Code
rpcuser=YOURUSERNAME
rpcpassword=MAKETHISLONGANDDIFFICULT
rpcallowip=*
rpcport=4355
server=1
daemon=1
(nodes go here)
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.

PHP Code

<?php
require("jsonRPCClient.php");
$omc = new jsonRPCClient("httpd://[username]:[password]@[ip-address]:4355/"); 
?>
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.
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."; ?>
Pretty good tutorial. You should have changed this to be config and rpc setup first then the actual client, and users shouldn't do * they should use their servers addresses.
(Apr 25, 2014 11:11 AM)Linux. Wrote:  Pretty good tutorial. You should have changed this to be config and rpc setup first then the actual client, and users shouldn't do * they should use their servers addresses.

I flipped it around, because that does make sense. Also, I mentioned that under the config.
<?php echo "I'm a professional web developer, if you need something ask me."; ?>
I can't seem to get it connected.

I have checked if my port is open and it is. Here are my settings....of course i changed the pass...

Code
rpcuser=chaddiablo
rpcpassword=ppasswordduh
rpcallowip=*
addnode=172.245.39.121
addnode=151.228.222.25
addnode=198.100.155.248
addnode=192.99.42.164
addnode=192.99.42.206
addnode=192.99.42.238
rpcport=43555
server=1
daemon=1

Code
$omc = new jsonRPCClient("http://chaddiablo:[email protected]:43555/");

Is there something wrong with this?

Edit:
Here is what shows up:
Code
Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to http://chaddiablo:[email protected]:4355' in /home3/dawk/public_html/classes/jsonRPCClient.class.php:140 Stack trace: #0 /home3/clfarmer/public_html/test.php(19): jsonRPCClient->__call('validateaddress', Array) #1 /home3/dawk/public_html/test.php(19): jsonRPCClient->validateaddress('oM8v179x5YrcGQu...') #2 {main} thrown in /home3/dawk/public_html/classes/jsonRPCClient.class.php on line 140

Chad
Your RPC port in the config is 43555, and in the error it says it's connecting to 4355.
<?php echo "I'm a professional web developer, if you need something ask me."; ?>
I'm really lost...
I don't understand what a "deamon" is... and what I need to do.

I found a tutorial on how to make a gamble website but I'm totally lost. please pm me.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by NoHacksJustGlobalMay 23, 2022 02:18 AM 4 285 May 23, 2022 02:18 AM
Last Post: NoHacksJustGlobal
by Real_ZeusJun 9, 2021 01:19 PM 6 220 Jun 9, 2021 01:19 PM
Last Post: Real_Zeus
[OMC] by SomeWhiteGuyJul 19, 2015 05:38 PM 6 148 Jul 19, 2015 05:38 PM
Last Post: SomeWhiteGuy