2

I started using Geth. and make a shell script which will end txn to another ETH address.

Step 1: Run command 'geth --fast --cache=1024' in one terminal and wait for full blockchain update. Step 2: Run below code as send.sh in another shell. Command: sh send.sh 'ETH address to send ETH' 'Amount'

Code for send.sh: #!/bin/sh

geth attach << EOF | grep "RESULT:" | sed "s/RESULT: //"
personal.unlockAccount("My ETH Address", "password")
var txnid = web3.eth.sendTransaction({from: "My ETH Address", to: "$1", value: web3.toWei($2, "ether")});
console.log("RESULT: " + txnid);

EOF

Output: Txn id [This works perfectly, no issues but want to send transaction from another server using javascript API by connecting this server geth]

All looks fine to me. But I want to use same functionality in https://github.com/ethereum/wiki/wiki/JavaScript-API

when I try to connect localhost:8545 not working and run Javascript API call. Not sure how to convert this code to Javascript. I am new hers any help will be great to my start up with Ethereum Javascript API.

1
  • 1
    Not working? It will be easy to answer what's not working? If you are getting any error, update the question with the error. May 20, 2017 at 6:49

2 Answers 2

2

8545 is an rpc endpoint
to access all the functions from a browser, you will have to serve the application to an http endpoint and have a .js and a .html file

  1. install web3
  2. https://www.npmjs.com/package/web3
  3. https://github.com/ethereum/wiki/wiki/JavaScript-API


use http framework like express https://expressjs.com/

then in your js write

http.listen(3000, function(){
     console.log('listening on *:3000');
   });<br>
var Web3 = require('web3');
var web3 = new Web3();


use your object to invoke the methods and ping to localhost:3000 in the browser

1

You can use web3 or web3_extended for connection to your geth from remote.

var web3_extended = require('web3_extended');

var options = {
  host: 'http://localhost:8545',
  personal: true,
  ipc : false,
  admin: true,
  debug: false
};
var web3 = web3_extended.create(options);

to connect to your geth via RPC. You can use web3 in the same way.

Note: You can even connect to geth instance with IPC using web3_extended with ipc= true parameter. IPC is more secure than RPC.

1
  • What might be command to run geth with web3 and ipc. May 20, 2017 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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