Instructions how to use this (an) Ethereum node via RPC

For the Ethereum main network use as RPC url :  “http://85.214.51.53:8545

For the Ropsten test network use as RPC url :  “http://85.214.51.53:8546

———————————————————————————-

Access the node via “geth” on your local system:

  1. Be sure that your local IP is registered in your user profile. Only access from this IP is not blocked when you use the RPC service
  2. Install your “geth” binary (30 MB) on your local system (geth binaries)
  3. Look for the directory “geth” is placed
  4. Use the command  ‘./geth attach rpc:http://85.214.51.53:8545’ to connect and start the JavaScript environment (documentation)
  5. The console is starting and you see ‘>’ for inputs
  6. write ‘eth.getBlock(10000)’ and get the block information as result (documentation)

Your system is running in minutes without installing the 500 GB Ethereum blockchain!

Troubleshooting:

  • Install the right geth binary.
  • Verify that geth is available on your local system
  • Check the IP in your user profile
  • Verify that no personal firewall is blocking your outgoing request

Try also the Ropsten test network:

  • http://85.214.51.53:8545 is for the main network
  • http://85.214.51.53:8546 is for the Ropsten test network

———————————————————————————-

Access the node via “node.js” on own local system or server

  1. This will return a webserver response and output a html file.
  2. Install web3 through NPM or others within your node.js system.
  3. Point the server file to app.js

This will bring you an output with a balance of the account(Wallet).

File: app.js

const http = require('http');
const walletAddress = '0xDED5f23C157aCef931946D9A695cAc3eF1AaaA8D';


var Web3 = require('web3');
var web3 = new Web3();

web3.setProvider(new web3.providers.HttpProvider('http://85.214.51.53:8545'));

var balance = web3.eth.getBalance('0xDED5f23C157aCef931946D9A695cAc3eF1AaaA8D');


http.createServer(function(request, response) {
    response.writeHead(200, {'Content-Type': 'text/html'});
    response.end("<!DOCTYPE html>\n" +
        "<html lang=\"en\">\n" +
        "<head>\n" +
        "    <meta charset=\"UTF-8\">\n" +
        "    <title>ethernode.biz</title>\n" +
        "</head>\n" +
        "<body>\n" +
        "<p>ethernode.biz</p>" +
        "<center>\n" +
        "</center>\n " +
        "<p> Ethereum balance : " + balance +"</p>\n" +
        "</body>\n" +
        "</html>\n");
}).listen(process.env.PORT);
----------------------------------------------------------------------------------

Access the node via “PHP” on an Unix system

  1. Be sure that your geth is working properly via RPC (Use instruction above “Access the node via “geth” on your local system:”)
  2. Save the following shell script on your Unix system under ‘geth_rpc_getblock.js’. Be sure you have the right permissions to execute it
  3. Adjust the path to the geth command in the script
  4. Check if the command ‘./geth_rpc_getblock.js’ will bring some nice output. It should return something like “Data::QBIT=27867000000;WETH=0;ETH=0.002650772”
  5. Save the following PHP script under ‘geth_access.php’ in the same directory
  6. Adjust the path in $shellstring to your script file location
  7. The php script should echo the output from the script. “Data::QBIT=27867000000;WETH=0;ETH=0.002650772”

You got it! Remember that accessing geth with a php shell_exec command is not very save in the long run.

 

File: geth_rpc_getblock.js

#!/bin/sh
# ------------------------------------------------------------------------------
# Qubitica.net
# ------------------------------------------------------------------------------

# Don't define PARAM to use the standard IPC comms
# Use below to connect to RPC port

PARAM="rpc:http://85.214.51.53:8545"

/var/www/vhosts/ethernode.info/php/geth attach $PARAM << EOF | grep "Data:" | sed "s/Data: //"

var erc20ABI = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"burn","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_value","type":"uint256"}],"name":"burnFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"},{"name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Burn","type":"event"}];

//var QBITWalletAddress = "$1"; You may pass a parameter from the php call into this $1.

var QBITContractAddress1 = "0xCb5ea3c190d8f82DEADF7ce5Af855dDbf33e3962";
var QBITContractAddress2 = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";

var QBITWalletAddress = "0x842286ea00502f8e5b1ea40d17ebc4b70becda08";

var QBITContract1= web3.eth.contract(erc20ABI).at(QBITContractAddress1);
var QBITContract2= web3.eth.contract(erc20ABI).at(QBITContractAddress2);

var acctBal = web3.fromWei(eth.getBalance(QBITWalletAddress), "ether");
totalBal += parseFloat(acctBal);

var QBITbalanceOf = QBITContract1.balanceOf(QBITWalletAddress);
var WETHbalanceOf = QBITContract2.balanceOf(QBITWalletAddress);

console.log("Data:"+":QBIT="+  QBITbalanceOf +";WETH="+  WETHbalanceOf +";ETH="+  acctBal);

exit;
<<<<< New File

PHP Script: geth_access.php

<?php
$shellstring= "./geth_rpc_getblock.js";
$output=shell_exec($shellstring);
echo "$output";
?>

 

Troubleshooting:

  • shell scripts are sensitive regarding Windows linefeeds or returns \n\lf
  • check permissions