7

I have used web3 to interact with my private chain by using :

web3.setProvider(new web3.providers.HttpProvider("http://localhost:8012"));

But How can I connect to Public Network using web3?

I am trying to make a web interface for interaction with my contract( which deployes, where you can use all the functions provided by my contract using my web interface. I have done this on private network and everything worked seamlessly.
But now I have doubt that whether I can replicate same on public network.
For example let my contract address be x and contract ABI be y and I have a function named transfer to transfer coins. I have done this on private network:

web3.setProvider(new web3.providers.HttpProvider("http://localhost:8012"));
var contract1=web3.eth.contract(y).at(x);
contract1.transfer(to, amount, {from: frm});

Also can I unlock my account using RPC ? I mean if my users want to create an address, If I can ask for password from them and use web3.personal.newAccount(password);.

To summarise:

  1. Can I access my contract on Public network using web3? If yes, How?
  2. Is personal exposed over RPC? I mean if I have to generate addresses or unlock account using web3, how can I do that?
  3. There are api that provide Ethereum addresses, how do they work?
1

2 Answers 2

9

This is how you access ehtereum public network

new Web3.providers.HttpProvider('https://api.myetherapi.com/eth')
4
  1. Yes, you can access to your contract on the Ethereum mainnet or testnet (public chains) after publishing a contract, exactly like you do for the private chain. You have to connect your client code (Web3 JS) to a running Ethereum node through RPC. This running node can be:

    • A node running locally on the client machine (http://localhost:8545)
    • A remote node (provided by your organisation)
    • A 3rd party node
  2. Personal is not exposed. The accounts and transactions are handled most of the time by an Ethereum browser such as Mist or Google Chome (+plugin Metamask). The Ethereum browser allows to:

    • Connect to a node
    • Create an account
    • Fund an account
    • Send transaction

For example, every time your client will try to execute a sendTransaction or a contract written functions like you wrote

var contract1=web3.eth.contract(y).at(x);
contract1.transfer(to, amount, {from: frm});

it will open a popup asking the user to approve the transaction.

Examples of Metamask

enter image description here enter image description here

  1. If you want to manage yourself all this part, I haven't tried but I guess you can use a library like eth-lightwallet

Hope this helps you.

2
  • Thanks for the answer. So if I want to write an api to generate ethereum addresses or carry out transactions, the only way I have is to connect to ethereum node via IPC, right? I am not sure if web3_extended can help? Does web3_extended provides support of using perosnal? Dec 9, 2016 at 4:57
  • Also if I can't unlock account via RPC, how can I use web3 to connect to a ethereum node voia IPC. Please update the answer. Thanks Dec 9, 2016 at 5:06

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.