I am trying to set up a private blockchain with geth, using truffle to deploy a smart contract to it. My goal is to get a private blockchain running with several accounts, deploy some contracts to it and connect some peers. It is supposed to be learning exercise.
I am running:
- geth 1.9.15
- truffle 5.1.30
- Ubuntu 18.04
Here are the steps I took to set up the private blockchain:
- Create 5 accounts:
geth account new --datadir private-chain --password pw.txt
- Initialize blockchain:
geth --datadir private-chain init private-chain/genesis-block.json
- Start the console:
geth --datadir private-chain --http --http.addr 127.0.0.1 --http.port 8545 --http.api eth,net,web3,personal --networkid 3456 console 2> private-chain/private-chain.log
My genesis-block.json file funded the new accounts with 120 ethers each.
When I try to deploy the contract with truffle, this is what I get:
Starting migrations...
======================
> Network name: 'geth'
> Network id: 3456
> Block gas limit: 2000000 (0x1e8480)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
Error: *** Deployment Failed ***
"Migrations" -- Returned error: authentication needed: password or unlock.
So I tried to unlock the account by changing 1_initial_migration.js to the following:
const web3_lib = require ("web3");
const Migrations = artifacts.require ("Migrations.sol");
module.exports = function (deployer, network, addresses)
{
const web3 = new web3_lib (new web3_lib.providers.HttpProvider ('http://127.0.0.1:8545'));
console.log ('>>>>> Attempting to unlock account');
console.log ('>>>>> Using password ' + process.env.GETH_PW);
web3.eth.personal.unlockAccount ('0x1234567890abcdef1234567890abcdef12345678', 'my-pw', 36000).then (console.log ('Account unlocked!'));
console.log ('>>>>> Deploying migration');
deployer.deploy (Migrations);
};
The "Account unlocked!" message was printed to the screen, but I got the same error as before.
Then I went to the geth console and tried to unlock the account from there and this was the result:
> web3.personal.unlockAccount ("0x1234567890abcdef1234567890abcdef12345678", "my-pw", 36000)
GoError: Error: account unlock with HTTP access is forbidden at web3.js:6347:37(47)
at native
at <eval>:1:91(6)
Is this even possible? Is there something I am forgetting, or not understanding about how this is supposed to work? What would be the correct way to do what I am trying to do?