3

I have deployed a cryptocurrent on Private testNet from here. I have deployed two contracts, lets call them contract1 and contract2. Contract1 has less features than contract2 (like transferFrom() functionality was removed).
Now I am using

geth --identity "XXXX" --fast --cache=1024 --jitvm --rpc --rpcport "yyyy" --rpccorsdomain "*" --datadir "chaindata" --port "xxxx"  --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --rpcapi "db,eth,net,web3,admin,debug,miner,personal,web3" --autodag --networkid xxxx --nat "any" -ipcpath "/home/pr.singh/.ethereum/geth.ipc"  console 

to connect to geth console. Now I want to execute transfer() function of contract2. I know how to do it from geth console (using abi defination fo contract). But how to do it using web browser. What request do I need to send and HOW?
When I hit url http://localhost:yyyy/ (where yyyy is my rpcport) , I get {"jsonrpc":"2.0","error":{"code":-32600,"message":"EOF"}} as output, so I know my port is working fine.
But in what format do I need to send data to this port. Like how will it know which method of which contract needs to be executed. Any tutorial avilable on that. TIA.

  • As you have labeled it correctly: use web3js in your webpage's javascript. As long as you are doing it locally it will be fine, for production use metamask or infura – Roland Kofler Sep 6 '16 at 5:42
1

You need to author a HTML interface which uses the web3js library. For my own testing purposes, I simply drop the web3.js library into the DAPP directory and import it in the HTML file.

<script type="text/javascript" src="web3.js"></script>
<script type='text/javascript'>
var Web3 = require('web3');
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
...

Contracts can be connected to by creating contract objects and assigning the object an address.

var contract = web3.eth.contract([{"constant":false,...}]);
var forInstance = contract.at("0xabcd...");

Then you can call or send to the contract and web3 functions as per normal...

var d = forInstance.getData();
forInstance.setData('foo', {from:eth.accounts[0]});
  • So, do you mean I need to write HTML code for that? I am not a UI developer and have no idea how to write HTML code to access on my contract. Does Ethereum not provide any way to access your accounts and contracts from a web browser. Once I deployed a contract using MIST, I want to access all its functions using web, but How to do that? I am really puzzled. – Prashant Prabhakar Singh Sep 8 '16 at 7:07
  • Accessing anything from a web browser implies that 'someone' has to write an HTML interface. Mist itself allows for direct interaction with your contract more through 'watch contract'. There are also plugins like MetaMask that allow Web3 enable pages to connect to a node, but still that requires some HTML authoring. Keep in mind through that the Ethereum design philosophy has purposely been avoiding 'just another web page' mentality and that DAPP's a at their best when integrated with Mist itself. – o0ragman0o Sep 8 '16 at 23:06
  • Thanks buddy. Wrote HTML code for that, the same that wrote on geth console and now I am able to know balance and carry out transactions using web. – Prashant Prabhakar Singh Sep 11 '16 at 14:27
  • I was trying to access the functions written on inside my code on http:localhost:yyyy where yyyy is the rpcport. But I get error:32601 and a message that function doesn't exist, but when I use commands listed here , I get expected output.Like when I use curl -X POST --data '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":65}' http://localhost:8012/ I get list of accounts. I want to access my functions that I wrote using web3.js in similar manner, how can I do that? TIA – Prashant Prabhakar Singh Sep 14 '16 at 9:52
  • You might want to open a new question for that – o0ragman0o Sep 14 '16 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.