How to setup a simple web interface using ethereum/web3.js
Information
You need to have a running ethereum node, for example testrpc and a running webserver.
Operating system used
macOS 10.12 Sierra
Software prerequisites
Node.js
Procedure
- Make sure you have access to a running ethereum node, for example testrpc
In this example i assume JSON-RPC api calls can be made to http://localhost:8545.
- There are several methods to apply JSON-RPC api calls to http://localhost:8545. Using:
- Web interface using ethereum/web3.js
- Node.js script using ethereum/web3.js
Use a Node.js script to communicate with an Ethereum node
- Install web3 module, type: npm install -g web3
Version 0.19.0 is now installed.
Note:
To check which version you have installed, type: npm list -g --depth=0
- Download the demonstration Node.js script:
ethereum_example1.js.txt
Modify it according to your situation.
- Run this Node.js script:
node ethereum_example1.js
Use a web application to communicate with an Ethereum node
- Go to the web3.js github page: https://github.com/ethereum/web3.js/releases,
select a release and download the source code.
Download the same source code version as the installed web3 node module (to make it consistent).
- In the dist folder you will find the files: web3-light.min.js and web3.min.js.
The file web3.min.js contains the Bignumber module (https://github.com/MikeMcl/bignumber.js) and web3-light.min.js does not.
If you are not sure which one to use, just use web3.min.js.
- Download the demonstration web application:
ethereum_example1.html
Modify it according to your situation.
- Copy this html file to your webserver <docroot> and access this file in your browser:
http://localhost:8545/ethereum_example1.html
|