I have studied the documents for creating a new account using Nethereum..
var ecKey = Nethereum.Signer.EthECKey.GenerateKey();
var privateKey = ecKey.GetPrivateKeyAsBytes().ToHex();
var account = new Nethereum.Web3.Accounts.Account(privateKey);
I want to create the account on Geth to start with for testing and then will migrate this to Ethereum live. For this I am initalising Web3 with a constructor:
public Web3 _web3;
public BaseEthererumService()
{
_web3 = new Web3(Config.EndPointURL); // Prod "https://mainnet.infura.io";
// Geth "localhost:8545";
}
What I want is to write a new address to Geth (or Ethereum in prod) and to receive a new contract address back..
I have also tried:
public async Task<string> CreateAccount()
{
var account = await _web3.Personal.NewAccount.SendRequestAsync("123");
return account;
}
But this bombs out without returning any form of address. And when I run at a CLI geth account list I don't get anything back…
I simply need to register a new account on the blockchain programmatically using Nethereum.Web3
Any help would be appreciated.
Best Answer
if you're running Geth, you'll need to point to the
geth.ipc
file instead of the endpoint url pointing to Infura.io for key generation because they won't store your private key for you.Basically, run Geth locally and add the
geth.ipc
file path toConfig.EndPointURL
, and you should be able to generate a key with it.