1

Apologies in advance for the long post. I'm new to Ethereum and don't know which details are significant and which are not.

I'm trying to learn about dapps by following an example in this book. My system is Windows 10-based. The book tells me first to sync an Ethereum node, which I do using

geth --datadir d:\Ethereum\geth

This is not my %APPDATA directory (that drive is too small to host the node).

So that was successful. Next step is to create and configure a private development chain, which I do using this:

geth --dev --datadir D:\SampleDapp\privatenet --ipcpath D:\Ethereum\geth.ipc --networkid 45 --rpc --rpcapi web3,net,eth,personal --rpccorsdomain "*" --mine console

The book tells me that for Mist to interact with the IPC file it must be located with the main node, therefore I set it up that way.

So far, so good. Next I create a simple contract in Solidity, which successfully compiles. Now we come to the deployment, which the book says is done with this Node.js script:

var Web3 = require('web3');
var fs = require('fs');
var exec = require('child_process').execSync;

var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
var walletAddress = web3.eth.accounts[0];
console.log(walletAddress);
web3.personal.unlockAccount(walletAddress, process.argv[2]);

var abi = fs.readFileSync('bin/peerbet.sol:Bet.abi');
var PeerBet = web3.eth.Contract(abi);

var compiled = '0x' + fs.readFileSync('bin/Bet.bin');
var peerbet = PeerBet.new({
    from: walletAddress,
    data: compiled,
    gas: 40e5,
    gasPrice: 20e9
}, function (e, contract) {
    if (e) console.log(e);

    if (typeof contract.address !== 'undefined') {
        console.log('Contract mined! address: ' + contract.address +
            ' transaction hash: ' + contract.transactionHash);
        fs.writeFileSync('contract_address', contract.address);
    }
});

This is where the problem is. The wallet address found at web3.eth.accounts[0] is one I've never seen before. I have two wallets on my system (one set up by Mist, and one by MetaMask), but neither of those addresses correspond to the address I'm getting in this script. Since I don't know where the wallet address came from, I don't know its private key, password, passphrase, or whatever. So, two questions: where did this wallet address come from, and what do I need to provide as an argument to get web3.personal.unlockAccount() to work? Thanks.

  • What is the content of your D:\SampleDapp\privatenet\keystore directory? Can you find there the address of web3.eth.accounts[0]? – ivicaa Oct 9 '18 at 20:26
  • @ivicaa Thanks! OK, in that directory is a JSON file with the address, so now I know where we're getting the address. Now how would I find the password (passphrase? private key?) needed for the call to web3.personal.unlockAccount()? – John Riehl Oct 9 '18 at 20:31
1

These two accounts must come from your dev node -> D:\SampleDapp\privatenet\keystore

Most probably you created them at some point and now you can not remember anymore.

Anyway, you can simply recreate the datadir. Simply delete D:\SampleDapp\privatenet and call the geth --dev ... command again. On the console create as many accounts as you need with personal.newAccount(). Then rerun your nodejs test-script.

  • 1
    It actually appears that when I first started the dev node it created the account automatically (I didn't create it, just the two accounts that are on the main node). I used personal.newAccount() on the console and created a new account, which now shows up as web3.eth.accounts[1]. Thanks for the help! – John Riehl Oct 9 '18 at 20:58
  • PS--I just figured out that the account that gets created when the chain is initialized has a balance of ETH and no passphrase. I deleted the privatenet directory, then ran the command again. In the console I typed eth.getBalance(eth.accounts[0]) and got that the account has 1.16e+77 ETH. Calling personal.unlockAccount(address, "") succeeds and allows use of the account. – John Riehl Oct 9 '18 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.