1

I need a way to restart my development environment fresh so I have a little script like this:

    quit 'keosd'
    quit 'nodeos'
    rm -rf eosio
    rm -rf ~/eosio-wallet
    nohup keosd > keosd.log 2>&1 &
    nohup node > nodeos.log 2>&1 &
    cleos wallet create --file .Wallet
    cleos create key --file .Key
    PK=5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
    cleos wallet import --private-key=$PK
    PK=$(head -1 .Key |sed 's/Private key: //')
    cleos wallet import --private-key=$PK
    PK=$(tail -1 .Key |sed 's/Public key: //')
    cmd="cleos create account eosio t $PK $PK"
    echo $cmd
    $cmd

but when the script gets to the last line I get the dreaded error:

Failed to connect to nodeos at http://127.0.0.1:8888/; is nodeos running?

though if I run cleos get info I can see nodeos is running and curiously, if I run the command by hand (shown below as printed by the script), it works. but the call from the script fails

cleos create account eosio t EOS7Yo3xXD35Ct3Bu9BnwGDR5cUZDscwUtu9Kxc9ywJyJSuUFn2fL EOS7Yo3xXD35Ct3Bu9BnwGDR5cUZDscwUtu9Kxc9ywJyJSuUFn2fL

for completeness:

quit() {
    s=$(echo $1 |sed 's/./[&]/') # this trick prevents grep from finding itself
    id=$(ps aux |grep $s |awk '{print $2}')
    [ ! -z $id ] && kill $id
}
node() {
    nodeos -e -p eosio \
        --plugin eosio::producer_plugin \
        --plugin eosio::chain_api_plugin \
        --plugin eosio::http_plugin \
        --plugin eosio::history_plugin \
        --plugin eosio::history_api_plugin \
        --data-dir /Users/ekkis/dev/eos/eosio/data \
        --config-dir /Users/ekkis/dev/eos/eosio/config \
        --access-control-allow-origin='*' \
        --contracts-console \
        --http-validate-host=false \
        --verbose-http-errors \
        --delete-all-blocks \
        --filter-on='*'
}

and I'm running on OSX 10.14 (Mojave) with CDT v1.4.1

2 Answers 2

2
# wait for nodeos
until curl http://127.0.0.1:8888/v1/chain/get_info
do
  sleep 1s
done
0

ok... the problem seems to be that when the account creation command runs, the node hasn't yet come up. the reason the wallet imports run is that those commands go to keosd instead, which comes up much more quickly

so the answer is to sleep 1 or some suitable period before trying to talk to the daemon

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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