I have just started learning blockchain development
I have created an ethereum sidechain, which is running on docker containers in my local machine.
I have previously used solidity to write smart contracts and deploy them on the testnet using truffle, or by getting the provider from infura.
Note: wherein each container acts as a node.
But how do I do the same thing for my private chain?
You need to configure truffle to point to your testnet. The truffle config docs describe how to do this in detail. Essentially you want to put the following in your truffle.js file:
networks: {
test: {
host: "<ip address of one of your docker containers>",
port: <port number your container is listening on>,
network_id: "*" // match any network id
}
}
Related
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"
So I have followed multiple tutorials on getting started with smart contract development in Ethereum and have read many, many pages on security and development in OpenZeppelin. How exactly do I go about actually deploying my project to the Ethereum mainnet using Hardhat though? I can only find info on deploying to test networks!
Expand the networks section of the config file.
Example configuration:
mainnet: {
url: "https://mainnet.infura.io/v3/<your_infura_key>", // or any other JSON-RPC provider
accounts: [<your_private_key>]
}
Instead of specifying the private key directly, you can also specify the mnemonic phrase.
For more details, see the docs.
In the context of hardhat, mainnet, testnet or any other network work in the same way. These are just the tags. you can define multiple networks in hardhat config
module.exports = {
solidity: "0.8.9",
defaultNetwork: "hardhat",
networks: {
hardhat: {},
rinkeby: {
url: RAPI_URL,
accounts: [RINKEBY_WALLET_ADDRESS_PRIVATE_KEY]
},
mainnet: {
url: ETH_MAINNET_RPC_URL,
accounts: [MAINNET_WALLET_ADDRESS_PRIVATE_KEY]
},
},
}
then for deploy use the command like this
npx hardhat run scripts/deploy.js --network rinkeby
or
npx hardhat run scripts/deploy.js --network mainnet
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"
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).
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.