js4eos is a javascript Command Line Application for EOS. All commands are same as cleos. You don't need to build eos or setup a eos docker.
js4eos is also a Testing Framework for EOS Smart Contract just like truffle on ethereum
中文请点击这里
npm install js4eos -g
update node if there is a error when install js4eos
npm install -g npm
npm install -g node
you may add sudo in linux-based operation
create default wallet
js4eos wallet create
create another wallet
js4eos wallet create -n name
unlock wallet before any operation.
You don't need to unlock again in 30 minutes.
js4eos wallet unlock
js4eos config set --network jungle
js4eos faucet accountxxx
accountxxx is the new account name,length 12, and must be 'a-z,1-5'
you can switch to other network to create your first account
js4eos config set --network mainnet/kylin/fibos
js4eos faucet accountxxx
you must import the private key of a account before using this account. private key only exists in local ram, and only encrypted key saves to file.
js4eos wallet unlock (then please input password of wallet)
js4eos wallet import keyxxx
keyxxx is the private key of account you want to operate.
this will run offline if there is a local compiler, or will run online.
cd xxx
js4eos compile -o xxx.wasm xxx.cpp
use compile2 if your code follows eosio.cdt rule.
js4eos compile2 -o xxx.wasm xxx.cpp
js4eos compile -g xxx.abi xxx.cpp
code with cdt rule
js4eos compile2 -g xxx.abi xxx.cpp --contract contractclass
you will find three files xxx.cpp, xxx.abi, xxx.wasm in folder 'xxx'
hello contract needs almost 52k ram
you can get free eos for your account in jungle network.
http://jungle.cryptolions.io/#faucet
then buyram for your account to deploy a contract
js4eos system buyram acountxxx acountxxx "10.0000 EOS"
must keep four decimal places. '.0000'
js4eos set contract accountxxx xxx
ensure xxx.wasm and xxx.abi have already exist in folder 'xxx'
all commands are same with that of cleos
js4eos config
for example, switch between mainnet/kylin/jungle/enu/fibos networks
js4eos config set --network mainnet/kylin/jungle/enu/fibos
change chainid, httpendpoint of current network
js4eos config set --chainid=aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906 --url=http://bp.cryptolions.io:8888
change network, and then change chainid, httpEndpoint of this network
js4eos config set --network mainnet --chainid=aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906 --url=http://bp.cryptolions.io:8888
We maintain well-work httpEndpoints, so you can sync the newest configuration file with below command.
js4eos config sync
you may come across some issues, and then you can try reset configuration to fix it.
js4eos config reset
js4eos doc network
update js4eos firstly with below command if you run into a problem.
npm install -g js4eos
Try below solutions if the issue is still not fixed.
unlock wallet if encounter below problem.
missing key, check your keyprovider
you can reset wallet if the issue is still going.
js4eos wallet stop
js4eos wallet delete
js4eos wallet create
js4eos wallet import xxx
check network or httpEndpoint if it is 'fetch error'
{ FetchError: request to
change httpEndpoint
js4eos config choose url
compile needs network if no local compiler
firstly, reset config and sync config
#(ubuntu等需要sudo)
npm install -g js4eos@latest
js4eos config reset
js4eos config sync
secondly, reset all if above solution not work
npm install -g js4eos@latest
js4eos reset
finally, restart you machine.Report a issue in github or contact wechat:itleaks
Not recommended to use js4eos in mingwin or cygwin.Pleas use powershell or normal terminal of windows. You may need to escape quote of a command.For example
js4eos push action eosio.token transfer '["youraccount", "account2", "1.0000 EOS", "test"]' -p youraccount
you need replace '"' to '""' in normal terminal
js4eos push action eosio.token transfer "[""youraccount"", ""account2"", ""1.0000 EOS"", ""test""]" -p youraccount
you need add '' in PowerShell
js4eos push action eosio.token transfer '[\"youraccount\", \"account2\", \"1.0000 EOS\", \"test\"]' -p youraccount
js4eos create key
js4eos wallet import xxxxx
js4eos system newaccount --stake-net "0.0000 EOS" --stake-cpu "0.0000 EOS" --buy-ram-kbytes 3 createraccount somenewaccount EOSxxxxx... EOSxxxxx... -p createraccount
js4eos push action eosio.token transfer '["itleakstoken", "itleakstokem", "10.0000 EOS", "test"]' -p itleakstoken
js4eos get account youraccount
js4eos system buyram payer receiver "0.0001 EOS"
js4eos system sellram payer bytes
js4eos system delegatebw payer receiver "0.0000 EOS" "0.1000 EOS"
the first "0.0000 EOS" is network, and the second "0.1000 EOS" is cpu
js4eos system undelegatebw payer receiver "0.0000 EOS" "0.1000 EOS"
js4eos set contract xxx/xxx/contract_name
contract_name.abi and contract_name.wasm must exist
httpendpoint may halt, and you can change to another endpoint.
$ js4eos config choose url
Choose one httpEndpoint for mainnet:
*[0] http://bp.cryptolions.io:8888
[1] https://mainnet.genereos.io
[2] https://mainnet.meet.one
[3] http://mainnet.eoscalgary.io
please input[0~3]>
$ js4eos config choose network
Choose one network:
*[0] mainnet
[1] localnet
[2] eosforce
[3] jungle
[4] kylin
[5] enu
[6] fibos
please input[0~6]>
js4eos is also a testing framework
mkdir js4eos-dapp
cd js4eos-dapp
js4eos dapp init
or
// a version support IDE 'vscode'
js4eos dapp init -v vscode
js4eos dapp create anewcontract
js4eos dapp compile hello
js4eos dapp deploy hello
Only test hello test units with option '-g' '-g hi' means grep pattern 'hi' and then test
js4eos dapp test -g hi
test all test
js4eos dapp test
Configuration of dapp is in file "js4eos_config.js"
please modify this configuration to change deploy config such as deploy account.