How to interact with ethereum contract (ex. greeter) from html

EriqaEriqa Member Posts: 13
Can someone outline the steps involved in interacting with a simple Ethereum contract (ie. greeter) from html?

I have created a test net, mined ethers and also created the "greeter" contract. When I run admin.nodeInfo, the TCPPort is 30303

I know I need web3 + JSON ABI of my contract + address.

1) I don't know how to incorporate web3. The examples I have seen shows the "require" in the html page. Is this running on node.js?

2) I don't know what port# to put in place of 8545 in web3.setProvider(new web3.providers.HttpProviders("http://localhost:8545")

Any help would be appreciated.

Comments

  • EriqaEriqa Member Posts: 13
    tjade273 - thanks for responding. Just wanted to add - I am running Ubuntu 14.04 on wmvware.

    1) Nginx

    I started geth with --rpc flag pointing to a port.

    I am using nginx web server. I've changed the port using --rpcport to point to the port I am using. (The web page domain is local so I didn't bother with rpccorsdomain.)

    I included ethereum.min.js in the html

    I opened up browser and pointed to the page. The page comes up but when I try to execute the script, I get "web3 is not defined" when the code calls web3.eth.contract(....)

    Is there anything else I need to do to enable web3 on nginx server?

    2) Meteor

    So I then decided to install meteor and the added ethereum:web3 and now it is working.

    Is there an ethereum web3 module for nginx?






  • srivatsavsrivatsav Member Posts: 1
    when i follow below steps - i get below error - can anyone please share your thoughts ?

    [Env ubunt 14.04, on AWS box ]

    sudo apt-get update
    sudo apt-get install nodejs
    sudo apt-get install npm
    sudo apt-get install nodejs-legacy

    sudo npm install web3

    Error
    npm ERR! Error: No compatible version found: [email protected]'debris/bignumber.js#master'
    npm ERR! Valid install targets:
    npm ERR! ["1.0.0","1.0.1","1.1.0","1.1.1","1.2.0","1.2.1","1.3.0","1.4.0","1.4.1","1.5.0","2.0.0","2.0.1","2.0.2","2.0.3","2.0.5","2.0.6","2.0.7","2.0.8"]
    npm ERR! at installTargetsError (/usr/share/npm/lib/cache.js:719:10)
    npm ERR! at /usr/share/npm/lib/cache.js:638:10
    npm ERR! at saved (/usr/share/npm/node_modules/npm-registry-client/lib/get.js:142:7)
    npm ERR! at /usr/lib/nodejs/graceful-fs/polyfills.js:133:7
    npm ERR! at Object.oncomplete (fs.js:107:15)
    npm ERR! If you need help, you may report this log at:
    npm ERR!
    npm ERR! or email it to:
    npm ERR!

    npm ERR! System Linux 3.13.0-48-generic
    npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "web3"
    npm ERR! cwd /home/ubuntu
    npm ERR! node -v v0.10.25
    npm ERR! npm -v 1.3.10
    npm ERR!
    npm ERR! Additional logging details can be found in:
    npm ERR! /home/ubuntu/npm-debug.log
    npm ERR! not ok code 0

  • wimpiwimpi Member Posts: 3
    srivatsav said:

    when i follow below steps - i get below error - can anyone please share your thoughts ?

    [Env ubunt 14.04, on AWS box ]

    sudo apt-get update
    sudo apt-get install nodejs
    sudo apt-get install npm
    sudo apt-get install nodejs-legacy

    It seems ubuntu 14.04 comes with an old version of npm, you can check this with

    npm -v # returns 1.3.10 for me.

    The solution is to upgrade npm

    sudo npm install -g npm
    source ~/.bashrc
    npm -v # check the version, it should be >=3.5.2 (currently version)

    now you can proceed with

    sudo npm install web3
Sign In or Register to comment.