1

I've been wondering how to connect browser with a smart contract using web3. I know that I need to instantiate provider as follow,

  web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

And via provider I'm 'talking' with contract, right?

When comes to deployment phase, do you setup node as a provider or you run some RPC on the server on localhost?

Cheers!

2

web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

To use this you need to have a node running locally with the rpc enabled at the port:8545, you can do it by running the command:

geth --rpc --rpcaddr <ip> --rpcport <portnumber>

with the <ip> being localhost and <portnumber> being 8545.

And via provider I'm 'talking' with contract, right? When comes to deployment phase, do you setup node as a provider or you run some RPC on the server on localhost?

via the provider you connect to the local node through RPC and use the web3 API to interact with the ethereum blockchain, where the contract is deployed.

NOTE: If you do not want to run a local node, you may use a injected web3 with services like metamask.

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.