How do i connect to an Ethereum node? - ethereum

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"

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?

Ethereum geth reset the block to 0 again after i restarted my pc

Everything run well when i restarted running command "geth" for my local private network. but when i restarted my pc and run the geth command again, the block reset to 0 again.
Here is my code to init the geth from configuration in my genesis.json:
geth --datadir "/PATH_TO_NODE/" init /PATH_TO/genesis.json
And then i run my geth node with command:
geth --identity "node01" --http --http.port "8000" --http.corsdomain "*" --datadir "/PATH_TO_NODE/" --nodiscover --http.api "eth,net,web3,personal,miner,admin" --networkid 1900 --allow-insecure-unlock
when i rerun the command above there is no problem, it will continuing the block that already there. But it will be resetting to the 0 again when i restart my PC. Is it intended or not?
I believe this is because you've ran your geth node with a different network ID (--networkid 1900) rather than the default which is hardcoded as 1 and will have been used when you ran your first command (without the flag above). Every time you do this it resets the chain data. Also afaik, putting network ID in the genesis doesn't actually change anything. The only ways to change it are to a) hardcode it in the codebase or use the flag.

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"

Connecting to Ethereum node in web browser

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.