I have an ETH testnet set up using this docker-compose.yml file.
When I try to send 1 wei from the "buffer" account 0x411167FeFecAD12Da17F9063143706C39528aa28
to the test account 0x6d179e1d7715b6b2eedf82b16b90db3fd4cd64a3
using the following commands, I get the error ùnknown account`:
Buffer account
The buffer account is the account in which all mined ETH ends up. It is specified in the genesis.json file:
The buffer account exists on the testnet and when I run
curl -X POST http://localhost:8178 \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0", "method":"eth_getBalance", "params":["0x411167FeFecAD12Da17F9063143706C39528aa28","latest"], "id":1}'
I get the expected result: The buffer account has 0x200000000000000000000000000000000000000000000000000000000000000
ETH:
{"jsonrpc":"2.0","id":1,"result":"0x200000000000000000000000000000000000000000000000000000000000000"}
Test account
I created the test account myself using
geth account new --password address1pw.txt
It appears in the output of
geth account list
Question
What do I need to do in order to transfer 1 wei from the buffer account to the test account?
Update 1
Changing the request to
> eth.sendTransaction({from: '0c56352F05De44C9b5BA8bcF9BDEc7e654993339', to: '0x6D179e1d7715b6b2eeDF82b16B90db3fd4cd64A3', value: 1});
results in
Error: gas required exceeds allowance (8000000) or always failing transaction
at web3.js:6347:37(47)
at web3.js:5081:62(37)
at <eval>:1:20(10)
0c56352F05De44C9b5BA8bcF9BDEc7e654993339
is ETH_ADDRESS
specified in the docker-compose.yml
file.
Update 2
Changing the request to
eth.sendTransaction({from: '0c56352F05De44C9b5BA8bcF9BDEc7e654993339', to: '0x6D179e1d7715b6b2eeDF82b16B90db3fd4cd64A3', gas:8000000 , value: 1});
results in
Error: insufficient funds for gas * price + value
at web3.js:6347:37(47)
at web3.js:5081:62(37)
at <eval>:1:20(12)
Update 3
In the genesis.json file the account from which I try to send ETH appears in the alloc
section:
"alloc": {
"411167FeFecAD12Da17F9063143706C39528aa28": {
"balance": "0x200000000000000000000000000000000000000000000000000000000000000"
}
},
Update 4:
Here is how the ETH is being initialized: The file entrypoint.sh is run where I find this:
echo $ETH_PASSWORD > /tmp/eth_pass
echo $ETH_PRIVATE_KEY > /tmp/eth_private_key
geth --datadir /data init ./.genesis.json
geth --datadir /data account import --password /tmp/eth_pass /tmp/eth_private_key || true
ETH_PASSWORD
and ETH_PRIVATE_KEY
come from the vriables in docker-compose.yml file:
geth:
image: ulamlabs/geth-poa-testnet:latest
environment:
- ETH_PASSWORD=QfdxTYxkwASj
- ETH_PRIVATE_KEY=0d0b4c455973c883bb0fa584f0078178aa90c571a8f1d40f28d2339f4e757dde
- ETH_ADDRESS=0c56352F05De44C9b5BA8bcF9BDEc7e654993339
ports:
- 8178:8178
- 8546:8546
volumes:
- ./genesis.json:/app/genesis.json
It seems that the buffer account (411167FeFecAD12Da17F9063143706C39528aa28
) is not created when the container is created.
Update 5:
I ran following commands in the geth shell:
echo carsdrivefasterbecausetheyhavebrakes > buffer-pw.txt
echo 766df34218d5a715018d54789d6383798a1885088d525670802ed8cf152db5b4 > buffer-private-key.txt
geth account import --datadir /data --password buffer-pw.txt buffer-private-key.txt
echo a-turkey-is-a-chicken-designed-by-a-committee > exchange-pw.txt
echo b07aedf303f832664eb7a5295be737776cb1ad17a277ec287b3b3c7bac154e5e > exchange-private-key.txt
geth account import --datadir /data --password exchange-pw.txt exchange-private-key.txt
When I check the balance of the buffer account using
geth attach http://localhost:8178
eth.getBalance("0x411167FeFecAD12Da17F9063143706C39528aa28");
I get this output:
9.04625697166532776746648320380374280103671755200316906558262375061821325312e+74
Then I tried to send 1 wei from the buffer account to the exchange account again:
eth.sendTransaction({from: '0x411167FeFecAD12Da17F9063143706C39528aa28', to: '0x190FD61ED8fE0067f0f09EA992C1BF96209bab66', value: 1});
I get the error
Error: authentication needed: password or unlock
at web3.js:6347:37(47)
at web3.js:5081:62(37)
at <eval>:1:20(10)
I tried to unlock the account using the following commands, without success:
eth.unlockAccount('0x411167FeFecAD12Da17F9063143706C39528aa28', 'carsdrivefasterbecausetheyhavebrakes', 600).then(console.log('Account unlocked!'));
web3.personal.unlockAccount('0x411167FeFecAD12Da17F9063143706C39528aa28', 'carsdrivefasterbecausetheyhavebrakes', 600).then(console.log('Account unlocked!'));
Update 6:
Modified the entrypoint.sh of the Docker image with geth
so that test accounts are included and the personal API is enabled.
Then, modified docker-compose.yml file to use that changed geth image.
Now unlocking the buffer account and sending money from it seems to work.
Best Answer
The error was caused by accounts missing in the geth testnet. If an account appears in
genesis.json
it does not mean that the respective account will automatically be created.Therefore the first step to fixing the problem is to modify the existing entrypoin.sh so that the accounts are actually created:
Also, in order for the
eth.unlockAccount
call to work, we need to enable the personal API when startinggeth
by adding--rpcapi="db,eth,net,web3,personal"
to the original call.Before
After
The resulting entrypoint.sh looks like this:
Finally, we need to replace the old docker image in
docker-compose.yml
with the new one, i. e. change the line fromto
Final version of
docker-compose.yml
looks like this:It refers to genesis.json with the following content:
Then, it is possible to start BTC and ETH testnets by running
docker-compose up -d
in the same directory as thedocker-compose.yml
file above.