Connecting to Ethereum node in web browser - ethereum

I'm getting this error:
CONNECTION ERROR: Couldn't connect to node http://localhost:8545, is it running?
I'm currently trying to use a Meteor app with a node on a private test network. I've also tried running it on a real node on the real network as well. I am able to access the web3.eth objects, but I can't seem to connect to my node! It's so frustrating!
My app runs on http://localhost:3000
I've tried the following in launching my nodes, neither of them work (they launch okay, but I cannot connect to them through my browser):
geth --networkid 8545 --genesis ~/genesis_block.json --datadir ~/.ethereum_experiment console
geth --rpccorsdomain "*" --rpc --networkid 8545 --minerthreads "1" --datadir ~/.ethereum_experiment --mine
This is what I use to set the provider in the browser console:
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));

I think I was getting the same error, when was trying to run geth in a VM. And in that case the issue was with RPC listening to localhost only. Binding it to all addresses with --rpcaddr "0.0.0.0" solved the problem:
geth --rpc --rpcaddr "0.0.0.0" --rpcport 8545 --nodiscover --networkid "$NETWORKID" --datadir ~/.ethereum_experiment --genesis ~/genesis_block.json
Important thing to note here is that with a such configuration the port will be open to connections from the outside world, if it's not on a private network or not protected with a firewall.
You can also check if the RPC port is open by trying to connect to it with telnet:
telnet localhost 8545

A simple solution is to use a node provider like Alchemy or Infura!
https://docs.alchemy.com/alchemy/introduction/getting-started
Make an Alchemy key by signing up for an account and creating an app
Replace your web3 setup with something like this:
const { createAlchemyWeb3 } = require("#alch/alchemy-web3"); // Using HTTPS const web3 = createAlchemyWeb3("https://eth-mainnet.alchemyapi.io/<api-key>");
You can use free nodes from one of these node providers and avoid the hassle of maintaining your nodes yourself.

Related

Cannot connect to a geth private network node with configured --ipcpath using Web3.IPCProvider

My OS is Windows. I have several running geth instances in my machine and, because of this, I must manually configure their ipcpath so that they would not have a conflict. I create a geth instance using the following command:
geth --datadir data --networkid 123 --ipcpath node5.ipc
I can attach to the instance via geth attach ipc:\\.\pipe\node5.ipc. But I cannot do the same using web3.py:
>>> from web3 import Web3
>>> w3 = Web3(Web3.IPCProvider('\\.\pipe\node5.ipc'))
>>> w3.isConnected()
False
What seems to be the problem here?

GoError: Error: the method personal_newAccount does not exist/is not available at web3.js

I just installed geth and
I start an instance of geth with this command: geth --rinkeby --syncmode=light --http
then I attach to that instance with this command: geth attach http://127.0.0.1:8545
and it seems to work well...
personal command return me that:
but on command personal.newAccount() I get this error:
From what I found in a old post: https://ethereum.stackexchange.com/questions/51772/account-created-using-web3-is-not-showing-in-geth-console I should allow personal api on starting command, but right now --rpcapi personal option is not available.
Do you have any idea what I did wrong?

How to connect to Livepeer to Rinkeby network?

I want to run livepeer and for that I need it to get connected to an Ethereum network. There are two options as mentioned here:
Hosted API services
Self hosted Ethereum node
If I want to opt for the latter, how would I mention rinkeby?
Because I only want to use for the test purposes.
The tutorial uses geth as example of the self-hosted Ethereum node.
In the geth manual, you can find the --rinkeby option to connect your node to the Rinkeby network.
Example:
geth --rinkeby --rpc --rpcapi "eth,net,web3"
It seems that the Livepeer doc only shows 1 hyphen (-) for the geth options, but it really should be 2 (--).
Don't forget to change the network option to -network rinkeby on Livepeer start as well.
Example:
livepeer -network rinkeby -ethUrl "http://localhost:8545"

How do i connect to an Ethereum node?

I setup an Ethereum light node on a VPS using Geth, and i'm running it using:
nohup geth --syncmode "light" --rpc --rpcapi "eth,net,web3" --ws --rpccorsdomain '*' --rpcaddr 0.0.0.0 --rpcport 8080 &
Now from my local laptop i would like to use this node to perform web3 queries to the Etherum blockchain. I'm using python but i tried to do the same using Web3js too and the output is the same:
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('http://MY-VPS-IP:8080'))
print(w3.isConnected())
Which gives me the following output:
False
Which means, i'm assuming, that the node is not accessible from outside the vps where i hosted it. How can i access it from outside? In theory the command i used should work, and i also made sure to have port 80 open. Any advice is appreciated
The command you write is old and not fully correct use this:
geth --syncmode "light" --ws --ws.addr "specific IP" --http --http.addr "specific IP"

Can I configure my truffle project to use an .ipc endpoint file instead of an ethereum RPC listener?

I'm working on a project that uses truffle framework and want to test my code on a private ethereum network. When I run truffle console, it connects to the network specified in truffle.js, like this:
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
}
}
};
Is there a syntax that I can use to point truffle to a geth.ipc file somewhere on the system, or is truffle limited to network endpoints?
By definition, the endpoint is a RPC listener, not a file.
You can use geth to create a testnet.
To use it, you need to use it as an endpoint.
See the configuration options of geth to specify the port if it's not connecting right away.
testrpc is also allowing you to create a testnetwork (8535 is the default port).