Ethereum : Am I mining to my correct wallet address? - ethereum

I'm trying to start Ethereum, so I created my wallet first using metamask and I added to geth using private key with this command.
geth account import private_key.txt
After that I run the mining command using geth --mine, so my question is : am I really mining to my correct wallet ?

OPTION 1:
You can set the account your Ethereum miner mines to by running the following in the geth console:
miner.setEtherbase('yourethaddress')
You can also set a local address to mine to using:
miner.setEtherbase(eth.accounts[2])
Replace '2' with the number of your account.
OPTION 2: When starting your geth node you can use the --etherbase flag.
geth --rpc --etherbase 0xC95767AC46EA2A9162F0734651d6cF17e5BfcF10
Using your ETH public address.
More information here: https://geth.ethereum.org/docs/interface/mining

Related

Unable to list accounts using geth console even though accounts exist

When I run the geth command to list all accounts, it works fine:
geth account list
INFO [04-09|15:47:35.967] Maximum peer count ETH=50 LES=0 total=50
INFO [04-09|15:47:35.967] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [04-09|15:47:35.968] Set global gas cap cap=25000000
Account #0: {<my_public_address>} keystore: <path_to_keystore>
But when I start it's console, I get undefined and an empty array while requesting balances/accounts:
> eth.getAccounts()
undefined
> eth.accounts
[]
However, if I specify my address in order to check the balance, it works fine:
> eth.getBalance("<my account address>")
3000000000000000000
I am running a local self-hosted Ethereum node on rinkeby network:
geth --rinkeby --rpc --rpcapi "eth,net,web3" --cache 2048
Try manually using the --keystore option, and adding the path to the folder that has your keystore. (in this case it's probably ~/.ethereum/rinkeby/keystore )

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"

web3 json rpc error "" when attempting transactions

We're using web3 to connect to the rinkeby test ethereum network. When doing so through geth, via localhost, with the below web3 command:
var web3 = new Web3('http://localhost:8545');
We don't get any errors. We use this command to start geth:
geth --rinkeby --rpc --rpcapi="personal,eth,network,web3,net" --ipcpath "~/Library/Ethereum/geth.ipc"
However when we try using the rinkeby test network directly:
var web3 = new Web3('https://rinkeby.infura.io/');
We get this error:
Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (errors.js:42)
at XMLHttpRequest.request.onreadystatechange (index.js:73)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:546)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:387)
at XMLHttpRequest.js:493
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:353)
at MessageQueue.js:118
at MessageQueue.__guardSafe (MessageQueue.js:316)
Most of the operations work on both networks, but .send() calls fail when connecting to the rinkeby network directly.
We think it's an issue with authentication, since other commands succeed that don't perform transactions. However, we tried using the HDWalletProvider and none of our accounts created via geth have mnemonics.
Any advice or troubleshooting steps would be appreciated. Thanks
Transactions have to be signed. When you send a transaction via your local geth node, it knows the private key corresponding to the address you're sending from, so it can sign the transaction for you (once you unlock the account).
A public node like Infura (fortunately!) doesn't know your private key, so it can't sign transactions for you. You'll need to sign them locally and then send them using sendSignedTransaction.

Ethereum deployed contract not defined in Geth Javascript console

I cannot access a deployed and mined Ethereum contract on a private network from the Geth Javascript console. Not sure where the issue is, any help is appreciated.
Thank you in advance for your time.
Scenario
I launched my Geth as below
geth --datadir ~/.ethereum/myProject --networkid 1234 --rpc --rpcport 8546 --rpcapi "eth,net,web3" --unlock 0 console
I've deployed and mined an Ethereum contract (to simplify things, I've used the default MetaCoin contract provided by Truffle), and I got the trx and contract address back.
I can access it from the Truffle console but if I try from the Geth Javascript console I get an error.
Please refer to the pictures below:
Truffle console
Geth javascript console
Software used
Geth (v1.7.3-stable)
NodeJS (v6.12.3)
TestRPC (v6.0.3 (ganache-core:2.0.2))
Truffle (v4.0.5)
Geth does not know about MetaCoin. In Geth console, you need to do:
var MetaCoin = web3.eth.Contract(metaCoinJsonAbi, itsAddress);
// or web3.eth.contract depending on the version of Web3
Then you can use it. Refer to this.

Not able to create accounts for Private Ethereum Blockchain using Geth and Web3 API

I am unable to create accounts for Private Ethereum Blockchain using Geth and Web3 API.
personal.newAccount(passwd) is not working for me. Please explain how to create account using above command.
And also, I am unable to install "ethereumjs-accounts".
If you try to search the internet why the "geth json rpc personal api" is not working, you will find an excellent answer on Ethereum Stack Exchange which I'd like to quote in full:
First, a note on safety:
You should not make the personal API available over RPC
If you are on a local, trusted machine, you should use IPC instead of RPC. Otherwise, anyone who can connect to your node via RPC can try to brute-force your passwords and steal your Ether.
All administrative APIs are available by default over IPC, so no need to use any flags with geth
To connect via IPC:
Install my library:
npm install web3_extended
var web3_extended = require('web3_extended');
var options = {
host: '/home/user/.ethereum/geth.ipc',
ipc:true,
personal: true,
admin: false,
debug: false
};
var web3 = web3_extended.create(options);
web3.personal.newAccount("password",function(error,result){
if(!error){
console.log(result);
}
});
Replace the host variable with the proper path for your system.
Note: All requests via IPC must be asynchronous.
Some Alternatives:
I don't know why you want to create new accounts via web3, but it's likely not the best way to do what you're trying to achieve. It is much safer and more modular to use a hooked web3 provider with a client-side light wallet or to simply use the Mist browser which handles all accounts for you.
Now for the technique (don't do this)
You need to enable the personal API over RPC. Do this by starting geth with
geth --rpc --rpcapi "db,eth,net,web3,personal"
Then you can use the personal_newAccount method via RPC. It's not implemented in web3.js, so you need to manually issue the RPC request. For example with curl:
curl -X POST --data '{"jsonrpc":"2.0","method":"personal_newAccount","params":["password"],"id":1}' localhost:8545
creates a new account with password password and returns the address:
{"id":1,"jsonrpc":"2.0","result":"0x05ca0ddf7e7506672f745b2b567f1d33b7b55f4f"}
There is some basic documentation
Alternatively:
Use the unofficial extended web3.js
this allows you to use the personal, admin and miner APIs via a standard web3.js interface.
Published on Feb 16 at 8:34 and released under terms of CC BY-SA 3.0 by Tjaden Hess.
The command must be personal.newAccount()
Then the console asks for passphrase, give your required password then it again asks for confirmation.
An output in the form of Address("0x----------------------------") will appear.It is 1 account/address for your private network.