EOS.IO v4 development help script

in eos •  7 years ago 

For anyone starting out development with the latest v4 EOS.IO software, the following script may help to understand the CLI commands provided and initialize the environment (development use only please).

The nodeos and keod processes can be killed manually with kill <pid> to "reset" your local blockchain. Wallets can be deleted by remove .wallet files under ~/eosio-wallet/

#!/bin/bash

# set your base directory
SRC=~/eos4/eos/

echo "------------------------"
echo "PROCESS LIST"
ps -x | egrep "eos|keosd" | grep -v grep
echo "if you want to start over, kill nodeos and keosd processes above"
echo "------------------------"

# notes
# ~/.local/share/eosio/nodeos/config/config.ini  has some useful setup like:
# private-key = ....
# producer-name = eosio
# ~/eosio-wallet/  has all the wallets (but remember to shut off keosd)
# ~/eosio-wallet/config.ini  has config

# remove any current wallets (should kill keosd first)
rm -f ~/eosio-wallet/*.wallet # be careful this is safe for your system

# run nodeos in the background - it should continue running even when you disconnect ssh
nohup nodeos --resync-blockchain &

sleep 1

echo "------------------------"
echo "PROCESS LIST"
ps -aux | egrep "eos|keosd" | grep -v grep
echo "------------------------"

sleep 1

# create default wallet and another called w2
wpass1=$(cleos wallet create | tail -n 1 | sed 's/^.\(.*\).$/\1/')
wpass2=$(cleos wallet create -n w2 | tail -n 1 | sed 's/^.\(.*\).$/\1/')
# if you get " Wallet with name: 'default' already exists " then kill keosd, remove .wallet's under ~/eosio-wallet/

cleos wallet list

echo default wallet has pass $wpass1
echo w2 wallet has pass $wpass2

# now lock them...
cleos wallet lock
cleos wallet lock -n w2

# and unlock them...
cleos wallet unlock --password $wpass1
cleos wallet unlock -n w2 --password $wpass2


# Create (or update) a contract on an account
# This transactions will have 2 actions on it, with names of "setcode" and "setabi"
# The client signs the transaction with the account 'eosio' under permission of 'active'
# the signatures of the txn can be seen in "signatures"
cleos set contract eosio ${SRC}build/contracts/eosio.bios -p eosio@active    # An account and permission level to authorize, as in 'account@permission'
# the output of the command is:
# ${executor} <= ${contract}:${action} ${args...}
# where executor is the account authority

# if you've run the above before, you may get "contract is already running this version of code" error to say its already there

# create a new key, which will be our new OwnerKey
keydata=$(cleos create key | sed 's/^.*: \(.*\)$/\1/')
pkey1=$(sed 'q' <<< "$keydata")
key1=$(sed -n '2p' <<< "$keydata")

echo new OwnerKey is $key1 $pkey1

# create a second key which will be the normal active key
keydata=$(cleos create key | sed 's/^.*: \(.*\)$/\1/')
pkey2=$(sed 'q' <<< "$keydata")
key2=$(sed -n '2p' <<< "$keydata")

echo new key is $key2 $pkey2

# import keys into wallet w2 by private key
cleos wallet import -n w2 $pkey1
cleos wallet import -n w2 $pkey2

# use eosio account to create two accounts with an OwnerKey of key1, ActiveKey of key2
cleos create account eosio user1 $key1 $key2
cleos create account eosio user2 $key1 $key2

# get some info on those new accounts
echo "cleos get account user1"
cleos get account user1

echo "cleos get account user2"
cleos get account user2

Notes

  • nodeos is the blockchain process
  • keosd is the local wallet plugin
  • The above was tested on a Ubuntu 16.04 box - please make sure it is compatible with your system and set up.
  • SRC should be replaced with your EOS install directory
  • Most of the cleos commands can be run with -d -j for "don't publish" and "json" to show the real output that gets sent

More info

For installed EOS.IO try this guide: https://steemit.com/eos/@anantanand/eos-dawn-3-0-setup-instructions-for-developers-a-beginning-to-dawn-3-0

For more tutorial help see: https://github.com/EOSIO/eos/wiki/Tutorial-Getting-Started-With-Contracts

Q&A: https://eosio.stackexchange.com

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!