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
    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

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

Failed to connect to nodeos at; 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 \

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

# wait for nodeos
until curl
  sleep 1s

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, privacy policy and cookie policy

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