Step by Step Learning for Blockchain using BlocApps

— ================================================
— URLs Followed:
— ================================================

— ================================================
— Prerequisites (Software to be installed)
— ================================================

— ================================================
— Steps to install bloc from NPM (Node.js Package Manager)
— Here, C:\> refers to Node.js Command Prompt
— ================================================
— Following commands needs to be executed if we have to by-pass Proxy Settings

C:\>npm config set strict-ssl false
C:\>npm config set registry ""
C:\>npm config set proxy http://<Username>:<UserPassword>@
C:\>npm config set http-proxy http://<Username>:<UserPassword>@
C:\>npm config set https-proxy https://<Username>:<UserPassword>@

--Commands used for the listing/deleting the Key/Value (if required)
-- npm config list
-- npm config delete proxy
-- npm config delete http-proxy
-- npm config delete https-proxy
-- npm config delete strict-ssl

C:\>npm install -g blockapps-bloc

C:\>bloc init
	? ==========================================================================
	? ==========================================================================
	We're constantly looking for ways to make blockapps-bloc better!
	May we anonymously report usage statistics to improve the tool over time?
	More info: &
	========================================================================== No
		____  __           __   ___
	   / __ )/ /___  _____/ /__/   |  ____  ____  _____
	  / __  / / __ \/ ___/ //_/ /| | / __ \/ __ \/ ___/
	 / /_/ / / /_/ / /__/ ,< / ___ |/ /_/ / /_/ (__  )
	/_____/_/\____/\___/_/|_/_/  |_/ .___/ .___/____/
								  /_/   /_/
	prompt: Enter the name of your app:  Programming_BlocApps
	prompt: Enter your name:  VinayChauhan
	prompt: Enter your email so BlockApps can reach you:
	prompt: apiURL:  (
	prompt: Enter the blockchain profile you wish to use.  Options: strato-dev, ethereum:  (strato-dev) strato-dev
	report obj: {"initName":"VinayChauhan","initEmail":"","initTimestamp":"1471955873"}
	Wrote: C:\Programming_BlocApps\.bowerrc
	Wrote: C:\Programming_BlocApps\app.js
	Wrote: C:\Programming_BlocApps\bower.json
	Wrote: C:\Programming_BlocApps\gulpfile.js
	Wrote: C:\Programming_BlocApps\marko-taglib.json
	Wrote: C:\Programming_BlocApps\package.json
	Wrote: C:\Programming_BlocApps\test\common.js
	Wrote: C:\Programming_BlocApps\test\top.js
	Wrote: C:\Programming_BlocApps\app\lib\abi.js
	Wrote: C:\Programming_BlocApps\app\lib\analytics.js
	Wrote: C:\Programming_BlocApps\app\lib\cmd.js
	Wrote: C:\Programming_BlocApps\app\lib\codegen.js
	Wrote: C:\Programming_BlocApps\app\lib\compile.js
	Wrote: C:\Programming_BlocApps\app\lib\contract-helpers.js
	Wrote: C:\Programming_BlocApps\app\lib\icon.js
	Wrote: C:\Programming_BlocApps\app\lib\keygen.js
	Wrote: C:\Programming_BlocApps\app\lib\prompt-schema.js
	Wrote: C:\Programming_BlocApps\app\lib\scaffold.js
	Wrote: C:\Programming_BlocApps\app\lib\upload.js
	Wrote: C:\Programming_BlocApps\app\lib\yaml-config.js
	Wrote: C:\Programming_BlocApps\app\routes\addresses.js
	Wrote: C:\Programming_BlocApps\app\routes\contract.js
	Wrote: C:\Programming_BlocApps\app\routes\examples.js
	Wrote: C:\Programming_BlocApps\app\routes\home.js
	Wrote: C:\Programming_BlocApps\app\routes\users.js
	Wrote: C:\Programming_BlocApps\test\config\config.test.js
	Wrote: C:\Programming_BlocApps\test\contract\contract.test.js
	Wrote: C:\Programming_BlocApps\test\keygen\keygen.test.js
	Wrote: C:\Programming_BlocApps\test\multi\multi.test.js
	Wrote: C:\Programming_BlocApps\app\contracts\Greeter.sol
	Wrote: C:\Programming_BlocApps\app\contracts\MultiContract.sol
	Wrote: C:\Programming_BlocApps\app\contracts\Payout.sol
	Wrote: C:\Programming_BlocApps\app\contracts\SimpleDataFeed.sol
	Wrote: C:\Programming_BlocApps\app\contracts\SimpleMultiSig.sol
	Wrote: C:\Programming_BlocApps\app\contracts\SimpleStorage.sol
	Wrote: C:\Programming_BlocApps\app\contracts\Stake.sol
	Wrote: C:\Programming_BlocApps\app\contracts\template.marko
	Wrote: C:\Programming_BlocApps\app\static\css\styles.css
	Wrote: C:\Programming_BlocApps\app\components\contractJS\template.marko
	Wrote: C:\Programming_BlocApps\app\components\contractFunctions\template.marko
	Wrote: C:\Programming_BlocApps\app\components\contracts\template.marko
	Wrote: C:\Programming_BlocApps\app\components\contractNameList\template.marko
	Wrote: C:\Programming_BlocApps\app\components\contractFunctionsCall\template.marko
	Wrote: C:\Programming_BlocApps\app\components\contractStatus\template.marko
	Wrote: C:\Programming_BlocApps\app\components\globalKeystore\template.marko
	Wrote: C:\Programming_BlocApps\app\components\header\template.marko
	Wrote: C:\Programming_BlocApps\app\components\home\home.marko
	Wrote: C:\Programming_BlocApps\app\components\keyModal\template.marko
	Wrote: C:\Programming_BlocApps\app\components\loginStatus\template.marko
	Wrote: C:\Programming_BlocApps\app\components\keyStatus\template.marko
	Wrote: C:\Programming_BlocApps\app\components\navTemplate\template.marko
	Wrote: C:\Programming_BlocApps\app\components\login\template.marko
	Wrote: C:\Programming_BlocApps\app\components\selectUser\template.marko
	project initiated!
	now type `cd Programming_BlocApps && npm install`
	thanks for registering with BlockApps!

C:\>cd Programming_BlocApps && npm install

C:\Programming_BlocApps>bloc genkey
	prompt: Enter a high entropy password. You will need this to sign transactions.: <<Test@1234>>

	wrote app\users\admin\e2807b606286be178347eac8609527fdb26dc703.json
		...waiting for transaction to be mined
	transaction successfully mined!

------ ================================================
------ URL For Testing/Verificatrion:
------ ================================================

—— ================================================
—— URL For Testing/Verificatrion:
—— ================================================

— ================================================
— Sample Program
— HelloWorld.sol is a contract which is already placed at location :- C:\Programming_BlocApps\app\contracts\HelloWorld.sol
— ================================================

C:\Programming_BlocApps>bloc compile HelloWorld.sol
	Compiling single contract: HelloWorld.sol
	Compile successful: contract HelloWorld {

		function getMessage1() public returns (string outMessage)  {
			return "Ananya Chauhan";

		function getMessage2(string inMessage) public returns (string outMessage)  {

			return inMessage;

	writing HelloWorld to app\meta\HelloWorld\HelloWorld.json
	wrote: app\meta\HelloWorld\HelloWorld.json

C:\Programming_BlocApps>bloc upload HelloWorld
	address: e2807b606286be178347eac8609527fdb26dc703
	prompt: Enter password to retrieve private key:
	upload contract: HelloWorld
		...waiting for transaction to be mined
	writing: app\meta\HelloWorld\102e4d7afa14a10cf0f0bb9dbd19d5c4555b2069.json
	writing: app\meta\HelloWorld\Latest.json
	creating metadata for HelloWorld

------ ================================================
------ URL For Testing/Verificatrion wherein balance could be checked:
------ ================================================	

C:\Programming_BlocApps>bloc start
	bloc is listening on
	api is pointed to with profile strato-dev

— ================================================
— How to execute contract in UI
— * Also, sample javascript code using blockapps.js is shared at location C:\Programming_BlocApps\app\indexBlockChain-HelloWorld.html
— * We can use this code from UI point of view and do the necessary integration
— ================================================

Once the server is started using command “bloc start” then run following URL http://localhost:8008/contracts in browser and click on “Generate HTML”

— ================================================
— Issues Faced/Resolved
— ================================================

(1) How to Check Versions of Node and NPM
C:\Programming_BlocApps>npm -v
C:\Programming_BlocApps>node -v

(2) Unable to start the server using command :- bloc start
[Comments also updated at URL:-]
Steps followed for Resolution:-

	(a) C:\Programming_BlocApps>node app.js start
		throw err;
		Error: Cannot find module './tatus/template'
			at Function.Module._resolveFilename (module.js:339:15)
			at Function.require.resolve (internal/module.js:23:19)
			at create (C:\Programming_BlocApps\app\components\contracts\template.marko.js:10:46)
			at Object.Template.c (C:\Programming_BlocApps\node_modules\marko\runtime\marko-runtime.js:103:18)
			at Object.<anonymous> (C:\Programming_BlocApps\app\components\contracts\template.marko.js:37:51)
	(b) Edit/Update a file :- C:\Programming_BlocApps\app\components\contracts\template.marko.js
		___contractFunctionsCall_template = __helpers.l(require.resolve("../contractFunctionsCall/template"));
        //___tatus_template = __helpers.l(require.resolve("../tatus/template"));
		//___tatus_template.render({"contractMeta": data.contractMeta, "apiURL": data.apiURL}, out);
	(c) C:\Programming_BlocApps>bloc start
		bloc is listening on
		api is pointed to with profile strato-dev

(3) How to see contract in UI?
Once the server is started using command “bloc start” then run following URL http://localhost:8008/contracts in browser

(4) How to change the port for server in node.js?
It could be done by modifying the port settings in file C:\Programming_BlocApps\app.js
At line no. 45, we do have the port number specifications i.e. given below
var port = process.env.PORT || 8000;

(5) Any online tool for compilation of Solidity code?
Code could be compiled at


Useful URL

How to access Tomcat Manager from Eclipse

It has been observed that Tomcat Manager is not accessible after starting the Tomcat Server from Eclipse. Even after doing changes in file – $TOMCAT_HOME/conf/tomcat-users.xml changes are not getting reflected back.

Therefore, we need to configure Eclipse to take control over from Tomcat, we need to do double-click the Tomcat Server entry in Servers tab and then we will get the server configuration. At the left column, under Server Locations, select Use Tomcat installations (If it is grayed-out then delete the Server and add it again). This way Eclipse will take full control over Tomcat and we will be able to access the default Tomcat homepage with the Tomcat Manager when running from inside Eclipse.

Configuration to access Tomcat Manager from Eclipse
Configuration to access Tomcat Manager from Eclipse

Note: Above stated configuration is validated on Apache-Tomcat-8.0.33

How to enable Tomcat Manager

To access the Tomcat Manager page, we need to define users in file – $TOMCAT_HOME/conf/tomcat-users.xml. By default, there is NO user which means that no one can access the Tomcat Manager page.

To access the above mentioned page, we need to add a user(s) as the role “manager-gui”

	<role rolename="manager-gui"/>
	<user username="admin" password="admin" roles="manager-gui"/>

Once done then save the file and restart the Tomcat Server and we should able to access the default manager page (http://localhost:8080/manager) with user = “admin” and password = “admin”

Note: Above stated configuration is validated on Apache-Tomcat-8.0.33

SQLException: Failed preTestConnection

Today while working on a project requirement, we got following SQL Exception:-

java.sql.SQLException: Failed preTestConnection.
Pool requests blocked for jdbc/XXYYSZDB until the test connection thread is successful.

Since, our application uses pooled JDBC database connections from the app server hence when the connection to our database fails, pooled connections that are no longer valid might exist in the free pool.

Therefore, connection pretesting is a way to test connections from the free pool before giving them to the client. We can enable the PreTest Connections feature in the WebSphere administrative console to prevent application from obtaining connections that are no longer valid.

The feature is particularly useful for routine database outages. Because these outages are usually scheduled for periods of low use, connections to the database are likely to be in the free pool rather than in active use. Active connections are not pretested; pretesting impedes performance during normal operation.

For doing configuration in WebSphere 6.0.x, following are the steps:-
(1) In the administrative console, click Resources > JDBC providers.
(2) Select a provider and click Data Sources under Additional properties.
(3) Select a data source and click WebSphere Application Server data source properties under Additional properties.
(4) Select the PreTest Connections check box.
(5) Type a value for the PreTest Connection Retry Interval, which is measured in seconds. This property determines the frequency with which a new connection request is made after a pretest operation fails.
(6) Type a valid SQL statement for the PreTest SQL String. Use a reliable SQL command, with minimal performance impact; this statement is processed each time a connection is obtained from the free pool. For example, “select 1 from dual” in oracle or “SQL select 1” in SQL Server.

Powermock : MockClassLoader Issue with Log4j

When running a PowerMock Test Log4j gives me the following (or something similar) error:-

log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.
log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by
log4j:ERROR [org.powermock.core.classloader.MockClassLoader@14a55f2] whereas object of type
log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [sun.misc.Launcher$AppClassLoader@92e78c].
log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator].


Caused by: org.apache.commons.logging.LogConfigurationException:Invalid class loader hierarchy.  
You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed.

There are a couple of different solutions to this:
# Upgrade to PowerMock 1.3+
# Make use of the @PowerMockIgnore annotation at the class-level of the test.
For example if using log4j, use `@PowerMockIgnore(“org.apache.log4j.*”)` if using commons logging, use `@PowerMockIgnore(“org.apache.commons.logging.*”)`.

Reference URL :-

How to handle special character (such as ‘&’) in Oracle?

Following are the few options that could be tried to handle special characters in Oracle:-

Case Study 1

SELECT a.employee_id,
replace(a.employee_display_name,'&amp;'||'reg;',NULL) updated_emp_display_name
FROM employee a
WHERE a.employee_id IN (26, 28, 48, 51, 61, 104, 39, 107);

Case Study 2

-- select ASCII('&amp;') from dual
-- select CHR(38) from dual;

SELECT a.employee_id,
replace(a.employee_display_name,chr(38)||'reg;',NULL) updated_emp_display_name
FROM employee a
WHERE a.employee_id IN (26, 28, 48, 51, 61, 104, 39, 107);

Case Study 3

Set scan off
-- Setting the scan off tells sqlplus that dont scan for variables in the statements.

SELECT a.employee_id,
replace(a.employee_display_name,'®',NULL) updated_emp_display_name
FROM employee a
WHERE a.employee_id IN (26, 28, 48, 51, 61, 104, 39, 107);

Case Study 4

set define off

SELECT a.employee_id,
replace(a.employee_display_name,'®',NULL) updated_emp_display_name
FROM employee a
WHERE a.employee_id IN (26, 28, 48, 51, 61, 104, 39, 107);

set define on