├── .gitignore ├── README.md ├── README_zh.md ├── bg_service ├── cmds ├── compile.js ├── compile2.js ├── config.js ├── config_cmds │ ├── choose.js │ ├── choose_cmds │ │ ├── network.js │ │ └── url.js │ ├── list.js │ ├── reset.js │ ├── set.js │ └── sync.js ├── create.js ├── create_cmds │ ├── account.js │ └── key.js ├── dapp.js ├── dapp_cmds │ ├── compile.js │ ├── create.js │ ├── deploy.js │ ├── init.js │ └── test.js ├── doc.js ├── doc_cmds │ ├── guild.js │ └── network.js ├── ext.js ├── ext_cmds │ └── claimeeth.js ├── faucet.js ├── get.js ├── get_cmds │ ├── abi.js │ ├── account.js │ ├── accounts.js │ ├── actions.js │ ├── block.js │ ├── currency.js │ ├── currency_cmds │ │ ├── balance.js │ │ └── stats.js │ ├── info.js │ ├── table.js │ └── transaction.js ├── localnet.js ├── localnet_cmds │ ├── reset.js │ ├── restart.js │ ├── start.js │ └── stop.js ├── push.js ├── push_cmds │ └── action.js ├── reset.js ├── set.js ├── set_cmds │ ├── abi.js │ ├── code.js │ ├── contract.js │ └── permission.js ├── system.js ├── system_cmds │ ├── buyram.js │ ├── delegatebw.js │ ├── exchange.js │ ├── newaccount.js │ ├── sellram.js │ └── undelegatebw.js ├── version.js ├── wallet.js └── wallet_cmds │ ├── create.js │ ├── createkey.js │ ├── delete.js │ ├── import.js │ ├── keys.js │ ├── list.js │ ├── lock.js │ ├── privatekey.js │ ├── stop.js │ └── unlock.js ├── docs ├── faucet.md └── networks.md ├── files ├── config.json └── weixin.png ├── index.js ├── js4eos ├── js4eos_bg ├── lib ├── api.js ├── compile.js ├── config.js ├── crypto.js ├── eoshelper.js ├── eosjs.js ├── index.js ├── patch_api.js ├── patches.js ├── request.js ├── utils.js ├── wallet.js └── wallet2.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | package-lock.json 8 | node_modules 9 | .vscode 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # js4eos 2 | 3 | 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.
4 | js4eos is also a Testing Framework for EOS Smart Contract just like truffle on ethereum
5 | 中文请点击这里 6 | # install js4eos 7 | ``` 8 | npm install js4eos -g 9 | ``` 10 | update node if there is a error when install js4eos 11 | ``` 12 | npm install -g npm 13 | npm install -g node 14 | ``` 15 | you may add sudo in linux-based operation 16 | 17 | # create wallet 18 | create default wallet 19 | ``` 20 | js4eos wallet create 21 | ``` 22 | create another wallet 23 | ``` 24 | js4eos wallet create -n name 25 | ``` 26 | # unlock wallet 27 | unlock wallet before any operation.
28 | You don't need to unlock again in 30 minutes. 29 | ``` 30 | js4eos wallet unlock 31 | ``` 32 | # create the first account 33 | ## jungle testnet 34 | ``` 35 | js4eos config set --network jungle 36 | js4eos faucet accountxxx 37 | ``` 38 | accountxxx is the new account name,length 12, and must be 'a-z,1-5'
39 | you can switch to other network to create your first account 40 | ``` 41 | js4eos config set --network mainnet/kylin/fibos 42 | js4eos faucet accountxxx 43 | ``` 44 | ## import private key of account 45 | you must import the private key of a account before using this account. 46 | private key only exists in local ram, and only encrypted key saves to file. 47 | ``` 48 | js4eos wallet unlock (then please input password of wallet) 49 | js4eos wallet import keyxxx 50 | ``` 51 | keyxxx is the private key of account you want to operate. 52 | # compile contract 53 | 54 | ## compile wasm 55 | this will run offline if there is a local compiler, or will run online. 56 | ``` 57 | cd xxx 58 | js4eos compile -o xxx.wasm xxx.cpp 59 | ``` 60 | use compile2 if your code follows eosio.cdt rule. 61 | ``` 62 | js4eos compile2 -o xxx.wasm xxx.cpp 63 | ``` 64 | ## generate abi 65 | ``` 66 | js4eos compile -g xxx.abi xxx.cpp 67 | ``` 68 | code with cdt rule 69 | ``` 70 | js4eos compile2 -g xxx.abi xxx.cpp --contract contractclass 71 | ``` 72 | you will find three files xxx.cpp, xxx.abi, xxx.wasm in folder 'xxx' 73 | # buyram 74 | hello contract needs almost 52k ram
75 | you can get free eos for your account in jungle network.
76 | http://jungle.cryptolions.io/#faucet
77 | then buyram for your account to deploy a contract 78 | ``` 79 | js4eos system buyram acountxxx acountxxx "10.0000 EOS" 80 | ``` 81 | must keep four decimal places. '.0000' 82 | # deploy contract 83 | ``` 84 | js4eos set contract accountxxx xxx 85 | ``` 86 | ensure xxx.wasm and xxx.abi have already exist in folder 'xxx' 87 | 88 | # other commands 89 | all commands are same with that of cleos 90 | 91 | # new apis 92 | js4eos config 93 | ## switch network 94 | for example, switch between mainnet/kylin/jungle/enu/fibos networks 95 | ``` 96 | js4eos config set --network mainnet/kylin/jungle/enu/fibos 97 | ``` 98 | 99 | ## change chainid, httpendpoint 100 | change chainid, httpendpoint of current network 101 | ``` 102 | js4eos config set --chainid=aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906 --url=http://bp.cryptolions.io:8888 103 | ``` 104 | ## change chainid, httpendpoint, network 105 | change network, and then change chainid, httpEndpoint of this network 106 | ``` 107 | js4eos config set --network mainnet --chainid=aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906 --url=http://bp.cryptolions.io:8888 108 | ``` 109 | ## sync configuration 110 | We maintain well-work httpEndpoints, so you can sync the newest configuration file with below command. 111 | ``` 112 | js4eos config sync 113 | ``` 114 | ## reset configuration 115 | you may come across some issues, and then you can try reset configuration to fix it. 116 | ``` 117 | js4eos config reset 118 | ``` 119 | # view documents 120 | 121 | ``` 122 | js4eos doc network 123 | ``` 124 | 125 | # issues 126 | update js4eos firstly with below command if you run into a problem. 127 | ``` 128 | npm install -g js4eos 129 | ``` 130 | Try below solutions if the issue is still not fixed. 131 | ## key problem 132 | unlock wallet if encounter below problem. 133 | ``` 134 | missing key, check your keyprovider 135 | ``` 136 | you can reset wallet if the issue is still going. 137 | ``` 138 | js4eos wallet stop 139 | js4eos wallet delete 140 | js4eos wallet create 141 | js4eos wallet import xxx 142 | ``` 143 | ## network problem 144 | check network or httpEndpoint if it is 'fetch error' 145 | ``` 146 | { FetchError: request to 147 | ``` 148 | change httpEndpoint 149 | ``` 150 | js4eos config choose url 151 | ``` 152 | ## compile issue 153 | compile needs network if no local compiler 154 | ## how to do when have no idea 155 | firstly, 156 | reset config and sync config 157 | ``` 158 | #(ubuntu等需要sudo) 159 | npm install -g js4eos@latest 160 | js4eos config reset 161 | js4eos config sync 162 | ``` 163 | secondly, 164 | reset all if above solution not work 165 | ``` 166 | npm install -g js4eos@latest 167 | js4eos reset 168 | ``` 169 | finally, restart you machine.Report a issue in github or contact wechat:itleaks 170 | ## windows compatible issue 171 | Not recommended to use js4eos in mingwin or cygwin.Pleas use powershell or normal terminal of windows. 172 | You may need to escape quote of a command.For example 173 | ``` 174 | js4eos push action eosio.token transfer '["youraccount", "account2", "1.0000 EOS", "test"]' -p youraccount 175 | ``` 176 | you need replace '"' to '""' in normal terminal 177 | ``` 178 | js4eos push action eosio.token transfer "[""youraccount"", ""account2"", ""1.0000 EOS"", ""test""]" -p youraccount 179 | ``` 180 | you need add '\' in PowerShell 181 | ``` 182 | js4eos push action eosio.token transfer '[\"youraccount\", \"account2\", \"1.0000 EOS\", \"test\"]' -p youraccount 183 | ``` 184 | 185 | vscode is recommendded 186 | 187 | # More commands 188 | ## create keys 189 | ``` 190 | js4eos create key 191 | ``` 192 | ## import key 193 | ``` 194 | js4eos wallet import xxxxx 195 | ``` 196 | ## create a new account 197 | ``` 198 | js4eos system newaccount --stake-net "0.0000 EOS" --stake-cpu "0.0000 EOS" --buy-ram-kbytes 3 createraccount somenewaccount EOSxxxxx... EOSxxxxx... -p createraccount 199 | ``` 200 | ## transfer 201 | ``` 202 | js4eos push action eosio.token transfer '["itleakstoken", "itleakstokem", "10.0000 EOS", "test"]' -p itleakstoken 203 | ``` 204 | ## get account info 205 | ``` 206 | js4eos get account youraccount 207 | ``` 208 | ## buy ram 209 | ``` 210 | js4eos system buyram payer receiver "0.0001 EOS" 211 | ``` 212 | ## sell RAM 213 | ``` 214 | js4eos system sellram payer bytes 215 | ``` 216 | ## delegate CPU,NET 217 | ``` 218 | js4eos system delegatebw payer receiver "0.0000 EOS" "0.1000 EOS" 219 | ``` 220 | the first "0.0000 EOS" is network, and the second "0.1000 EOS" is cpu 221 | ## undelegate 222 | ``` 223 | js4eos system undelegatebw payer receiver "0.0000 EOS" "0.1000 EOS" 224 | ``` 225 | 226 | ## deploy contract 227 | ``` 228 | js4eos set contract xxx/xxx/contract_name 229 | ``` 230 | contract_name.abi and contract_name.wasm must exist 231 | 232 | ## choose httpendpoint 233 | httpendpoint may halt, and you can change to another endpoint. 234 | ``` 235 | $ js4eos config choose url 236 | Choose one httpEndpoint for mainnet: 237 | *[0] http://bp.cryptolions.io:8888 238 | [1] https://mainnet.genereos.io 239 | [2] https://mainnet.meet.one 240 | [3] http://mainnet.eoscalgary.io 241 | please input[0~3]> 242 | ``` 243 | ## choose network 244 | ``` 245 | $ js4eos config choose network 246 | Choose one network: 247 | *[0] mainnet 248 | [1] localnet 249 | [2] eosforce 250 | [3] jungle 251 | [4] kylin 252 | [5] enu 253 | [6] fibos 254 | please input[0~6]> 255 | ``` 256 | # Eos Testing framework 257 | js4eos is also a testing framework 258 | ### initail a contract application 259 | ``` 260 | mkdir js4eos-dapp 261 | cd js4eos-dapp 262 | js4eos dapp init 263 | or 264 | // a version support IDE 'vscode' 265 | js4eos dapp init -v vscode 266 | ``` 267 | ### create contract 268 | ``` 269 | js4eos dapp create anewcontract 270 | ``` 271 | ### compile contract 272 | ``` 273 | js4eos dapp compile hello 274 | ``` 275 | ### deploy contract 276 | ``` 277 | js4eos dapp deploy hello 278 | ``` 279 | ### test hello contract 280 | Only test hello test units with option '-g' 281 | '-g hi' means grep pattern 'hi' and then test 282 | ``` 283 | js4eos dapp test -g hi 284 | ``` 285 | test all test 286 | ``` 287 | js4eos dapp test 288 | ``` 289 | ### Configure your dapp 290 | Configuration of dapp is in file "js4eos_config.js"
291 | please modify this configuration to change deploy config such as deploy account. 292 | # Contact 293 | Feel free to add my wechat:itleaks
294 |
-------------------------------------------------------------------------------- /README_zh.md: -------------------------------------------------------------------------------- 1 | # js4eos 2 | 3 | js4eos is a Command Line javascript Application for EOS
4 | js4eos is also a EOS Test Framework for Smart Contract just like truffle on ethereum
5 | js4eos是一个javascript命令行程序, 包含一个可执行程序js4eos和npm库js4eos。可执行程序js4eos类似EOS的cleos, 完全一样的命令及参数传递方式,以命令行的方式执行EOS命令,一键安装即可立即使用,跨平台,极大降低了EOS使用操作的门槛。同时通过js4eos的npm库,js开发人员能非常简便的开发操作EOS。
6 | js4eos本身也是一个EOS智能合约测试网络,类似以太坊下的Truffle 7 | # 安装(install) js4eos 8 | ``` 9 | npm install js4eos -g 10 | ``` 11 | 然后就可以使用js4eos执行EOS cleos程序的相似操作
12 | js4eos最新版本已增加较多功能,如你已安装js4eos,也强烈推荐你执行上述命令更新js4eos
13 | 如果出错,请将npm, node都更新一下 14 | ``` 15 | npm install -g npm 16 | npm install -g node 17 | ``` 18 | ubuntu等linux OS上, 上面的'npm install' 前需要加sudo 19 | # js4eos合约测试框架 20 | ### Contract Test Framework 21 | ### 初始化一个合约应用(initail a contract application) 22 | ``` 23 | mkdir js4eos-dapp 24 | cd js4eos-dapp 25 | js4eos dapp init 26 | or 27 | // a version support IDE 'vscode' 28 | js4eos dapp init -v vscode 29 | ``` 30 | ### 新增合约(create contract) 31 | ``` 32 | js4eos dapp create anewcontract 33 | ``` 34 | ### 编译智能合约(compile contract) 35 | ``` 36 | js4eos dapp compile hello 37 | ``` 38 | ### 部署智能合约(deploy contract) 39 | ``` 40 | js4eos dapp deploy hello 41 | ``` 42 | ### 测试合约(test hello contract) 43 | 只测试hello contract
44 | '-g hi'指只测试包含'hi'描述的测试用例,由于只有test/hello.js包含'hi'描述,因而只会测试hello contract 45 | ``` 46 | js4eos dapp test -g hi 47 | ``` 48 | 测试全部 49 | ``` 50 | js4eos dapp test 51 | ``` 52 | ### 更多信息 53 | 点击查看 54 | # 创建钱包(create wallet) 55 | js4eos只支持一个钱包,钱包可以管理很多key(账号) 56 | ``` 57 | js4eos wallet create 58 | ``` 59 | # 解锁钱包(unlock wallet) 60 | js4eos的钱包是加密的,解锁前必须输入创建钱包时输出的密码 61 | ``` 62 | js4eos wallet unlock 63 | ``` 64 | # 创建新账号(create new account) 65 | 测试网络账号创建 66 | ``` 67 | js4eos config set --network jungle 68 | js4eos faucet accountxxx 69 | ``` 70 | 这个 accountxxx 为你想要创建的新账号, 必须是12个字符,每个字符只能是a-z,1-4
71 | 主网等其他网络创建请切换到对应网络 72 | ``` 73 | js4eos config set --network mainnet/kylin/fibos 74 | js4eos faucet accountxxx 75 | ``` 76 | # 导入账号私钥(import private key of account) 77 | 你要操作某个账号,必须导入该账号的私钥,导入私钥必须先解锁钱包 78 | ``` 79 | js4eos wallet unlock (然后输入钱包的密码) 80 | js4eos wallet import keyxxx 81 | ``` 82 | keyxxx 为前面账号生成时输出的privateKey 83 | # 编译智能合约(compile contract) 84 | 目前只支持单层目录合约编译 85 | 合约目录结构为xxx/xxx.cpp 86 | ## 编译wasm程序(compile wasm) 87 | ``` 88 | #编译需要网络,请保持网络畅通 89 | cd xxx 90 | js4eos compile -o xxx.wasm xxx.cpp 91 | ``` 92 | 如果是采用eosio.cdt规范的智能合约,请用compile2 93 | ``` 94 | js4eos compile2 -o xxx.wasm xxx.cpp 95 | ``` 96 | ## 生成abi文件(generate abi) 97 | ``` 98 | js4eos compile -g xxx.abi xxx.cpp 99 | ``` 100 | 如果是采用eosio.cdt规范的智能合约,请用compile2, 并指定contract类名 101 | ``` 102 | js4eos compile2 -g xxx.abi xxx.cpp --contract contractclass 103 | ``` 104 | 编译完成后xxx目录下有xxx.cpp, xxx.abi, xxx.wasm三个文件 105 | # 购买ram(buyram) 106 | hello合约大约需要52k ram 107 | 前面通过faucet获取的jungle测试账号是没有余额的,因此需要在下面网址免费获得EOS 108 | http://jungle.cryptolions.io/#faucet, 然后购买ram 109 | ``` 110 | js4eos system buyram acountxxx acountxxx "10.0000 EOS" 111 | ``` 112 | 上面的.0000四个0不能省略 113 | # 部署智能合约(deploy contract) 114 | ``` 115 | js4eos set contract accountxxx xxx 116 | ``` 117 | xxx是上面合约的目录,里面必须包含xxx.wasm和xxx.abi两个文件 118 | 119 | # 其他接口 120 | 其他接口和EOS的cleos一模一样(包括参数名字传递方式) 121 | 122 | # 新增的接口 123 | js4eos config, 该接口用来设置系统配置,比如主网nodeos节点服务信息,网络chainid。通过该命令可以切换EOS网络。]可通过下面的命令来切换到不同网络 124 | ## 切换不同EOS链(switch network) 125 | 比如在测试网络jungle,kylin麒麟和主网之间切换 126 | ``` 127 | js4eos config set --network mainnet/kylin/jungle/enu/fibos 128 | ``` 129 | 130 | ## 修改当前网络参数(比如chainid, httpend的url) 131 | 以下命令会更改当前网络的参数 132 | ``` 133 | js4eos config set --chainid=aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906 --url=http://bp.cryptolions.io:8888 134 | ``` 135 | ## 切换网络,同时修改该网络的参数(change network) 136 | 下面命令就会切换到mainnnet网络并且修改该网络参数 137 | ``` 138 | js4eos config set --network mainnet --chainid=aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906 --url=http://bp.cryptolions.io:8888 139 | ``` 140 | ## 同步网络信息(sync configuration) 141 | 由于httpendpoint有时可能会失效,我们的服务器会不定时更新节点信息,所以本地需要时可以通过config sync来同步 142 | ``` 143 | js4eos config sync 144 | ``` 145 | ## 重置配置(reset configuration) 146 | 有时修改配置导致配置信息错误,可以通过reset命令修复 147 | ``` 148 | js4eos config reset 149 | ``` 150 | # 文档查看(EOS网络切换文档) 151 | 目前js4eos支持主网,EosForce, 测试网络,ENU和FIBOS也在整理即将支持。切换网络就是修改chainid和httpEndpoint,具体操作详情请使用doc network命令查看 152 | 153 | ``` 154 | js4eos doc network 155 | ``` 156 | # 水龙头(创建第一个账号,First account) 157 | 由于EOS操作的复杂性,任何一个EOS公链侧链账号注册是一个高门槛。因而js4eos配置了水龙头功能,只需执行 158 | ``` 159 | js4eos faucet accountxxx 160 | ``` 161 | 这个 accountxxx 为你想要创建的新账号, 必须是12个字符,每个字符只能是a-z,1-4
162 | 163 | # 常见问题(Problems) 164 | 出现问题第一步请执行如下命令更新js4eos 165 | ``` 166 | npm install -g js4eos 167 | ``` 168 | 如还没解决请尝试下面的方法 169 | ## key问题 170 | 出现下面提示,表示你没有导入私钥(需要js4eos wallet import)或者钱包已经锁定(需要js4eos wallet unlock) 171 | js4eos的钱包只有30分钟缓存时间,30分钟无操作需要再次unlock 172 | ``` 173 | missing key, check your keyprovider 174 | ``` 175 | 如果导入私钥或者unlock还是不工作,可以通过如下命令重置钱包 176 | ``` 177 | js4eos wallet stop 178 | js4eos wallet delete 179 | js4eos wallet create 180 | js4eos wallet import xxx 181 | ``` 182 | ## 网络问题(network problem) 183 | 出现fetchError 184 | ``` 185 | { FetchError: request to 186 | ``` 187 | 需要检测是否有网络或者需要更换节点(change httpendpoint) 188 | ``` 189 | js4eos config choose url 190 | ``` 191 | ## 编译问题(compile issue) 192 | compile needs network if no compiler in local 193 | 如果本地没有eosio-cpp编译器环境,js4eos compile 需要网络,请保持电脑网络通畅 194 | ## 错误无解时(what to when no idea) 195 | 错误无解时可以通过如下命令来恢复 196 | ``` 197 | #(ubuntu等需要sudo) 198 | npm install -g js4eos@latest 199 | js4eos config reset 200 | js4eos config sync 201 | ``` 202 | 如还有问题,执行如下操作,如下操作会删除钱包等文件 203 | ``` 204 | npm install -g js4eos@latest 205 | js4eos reset 206 | ``` 207 | 如果还有问题,请手工杀死js4eos_bg进程,然后执行 208 | ``` 209 | npm install -g js4eos@latest 210 | js4eos reset 211 | ``` 212 | 如果还是有问题请报issue或者添加微信itleaks 213 | ## windows兼容问题(windows compatible issue) 214 | 不推荐在mingwin或cygwin等linux模拟器下使用js4eos,可能会出现问题 215 | windows下命令行执行js4eos,有些输入需要转义,比如 216 | ``` 217 | js4eos push action eosio.token transfer '["youraccount", "account2", "1.0000 EOS", "test"]' -p youraccount 218 | ``` 219 | 需要更改为(change to below) 220 | ``` 221 | js4eos push action eosio.token transfer "[""youraccount"", ""account2"", ""1.0000 EOS"", ""test""]" -p youraccount 222 | ``` 223 | 引号"需要增加一个"来转义即""
224 | 如果是vscode下的powershell则需要使用 \ 来转义, 上述命令需更改为如下 225 | ``` 226 | js4eos push action eosio.token transfer '[\"youraccount\", \"account2\", \"1.0000 EOS\", \"test\"]' -p youraccount 227 | ``` 228 | 如果是使用其他window命令行,请自己尝试上述三种方式 229 | 推荐使用vscode,vscode的powershell非常好用,点击查看 230 | 231 | # 常用命令解读(common commands) 232 | 下图的EOS请替换为具体网络的币符号 233 | 比如ENU网络替换为ENU,fibos替换为FO 234 | ## 生成公私钥 235 | ``` 236 | js4eos create key 237 | ``` 238 | ## 导入私钥 239 | ``` 240 | js4eos wallet import xxxxx 241 | ``` 242 | 导入私钥,才能执行该私钥对应的账号写操作,比如抵押CPU,NET等 243 | ## 创建账号 244 | 下面的EOS请使用上面的create key输出的公钥 245 | ``` 246 | js4eos system newaccount --stake-net "0.0000 EOS" --stake-cpu "0.0000 EOS" --buy-ram-kbytes 3 createraccount somenewaccount EOSxxxxx... EOSxxxxx... -p createraccount 247 | ``` 248 | ## 转账 249 | ``` 250 | js4eos push action eosio.token transfer '["itleakstoken", "itleakstokem", "10.0000 EOS", "test"]' -p itleakstoken 251 | ``` 252 | ## 查询账号 253 | ``` 254 | js4eos get account youraccount 255 | ``` 256 | ## 购买RAM 257 | ``` 258 | js4eos system buyram payer receiver "0.0001 EOS" 259 | ``` 260 | ## 出售RAM 261 | ``` 262 | js4eos system sellram payer bytes 263 | ``` 264 | ## 抵押CPU,NET 265 | ``` 266 | js4eos system delegatebw payer receiver "0.0000 EOS" "0.1000 EOS" 267 | ``` 268 | 第一个(0.0000 EOS)是net抵押量,第二个(0.1000 EOS)是cpu抵押量 269 | 你必须有payer账号的操作权限 270 | ## 取消抵押 271 | ``` 272 | js4eos system undelegatebw payer receiver "0.0000 EOS" "0.1000 EOS" 273 | ``` 274 | 第一个(0.0000 EOS)是net抵押量,第二个(0.100 EOS)是cpu抵押量 275 | 你必须有payer账号的操作权限 276 | 277 | ## 部署合约 278 | ``` 279 | js4eos set contract xxx/xxx/contract_name 280 | ``` 281 | contract_name目录下需要有contract_name.abi和contract_name.wasm两个文件 282 | 283 | ## 选择节点(choose httpendpoint) 284 | 由于httpendpoint有时可能会失效,我们可以切换节点 285 | ``` 286 | $ js4eos config choose url 287 | Choose one httpEndpoint for mainnet: 288 | *[0] http://bp.cryptolions.io:8888 289 | [1] https://mainnet.genereos.io 290 | [2] https://mainnet.meet.one 291 | [3] http://mainnet.eoscalgary.io 292 | please input[0~3]> 293 | ``` 294 | ## 选择网络(choose network) 295 | 用户可能不了解网络的名字,可以通过列表选择方式切换网络 296 | ``` 297 | $ js4eos config choose network 298 | Choose one network: 299 | *[0] mainnet 300 | [1] localnet 301 | [2] eosforce 302 | [3] jungle 303 | [4] kylin 304 | [5] enu 305 | [6] fibos 306 | please input[0~6]> 307 | ``` 308 | # Contact 309 | Feel free to add my wechat:itleaks
310 | 有任何问题,可以加我微信:itleaks
311 |
312 | -------------------------------------------------------------------------------- /bg_service: -------------------------------------------------------------------------------- 1 | var exec = require('child_process').exec; 2 | var fs = require('fs') 3 | let adjust = 1; 4 | if (process.argv.length < 1 + adjust) { 5 | throws("invalid arguments") 6 | } 7 | let cmd = process.argv[1 + adjust] 8 | //exec must be executed in a async function 9 | async function main() { 10 | exec(cmd, function(err, stdout, stderr) { 11 | }); 12 | } 13 | 14 | main() 15 | -------------------------------------------------------------------------------- /cmds/compile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../lib') 8 | const Config = Js4Eos.getConfig() 9 | 10 | exports.command = 'compile ' 11 | exports.desc = 'compile contract, only support one file currently' 12 | exports.builder = yargs => yargs 13 | .options("g", { 14 | desc:"generate abi", 15 | type:'string', 16 | }) 17 | .options("o", { 18 | desc:"generate wasm", 19 | type:'string', 20 | }) 21 | 22 | exports.handler = function (argv) { 23 | if (argv.g) { 24 | Js4Eos.compile(argv.file, argv.g, {flag:'g'}).then(data => { 25 | if (!data) { 26 | return; 27 | } 28 | console.log(data.stderr); 29 | console.log(data.stdout); 30 | console.log("Saving to", data.file); 31 | }) 32 | } 33 | if (argv.o) { 34 | Js4Eos.compile(argv.file, argv.o, {flag:'o'}).then(data => { 35 | if (!data) { 36 | return; 37 | } 38 | console.log(data.stderr); 39 | console.log(data.stdout); 40 | console.log("Saving to", data.file); 41 | }) 42 | } 43 | } -------------------------------------------------------------------------------- /cmds/compile2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../lib') 8 | const Config = Js4Eos.getConfig() 9 | 10 | exports.command = 'compile2 ' 11 | exports.desc = 'compile2 support new feature of eosio.cdt' 12 | exports.builder = yargs => yargs 13 | .options("g", { 14 | desc:"generate abi", 15 | type:'string', 16 | }) 17 | .options("o", { 18 | desc:"generate wasm", 19 | type:'string', 20 | }) 21 | .options("c", { 22 | alias:"contract", 23 | desc:"contract name", 24 | type:'string', 25 | }) 26 | 27 | exports.handler = function (argv) { 28 | if (argv.g) { 29 | if (!argv.contract) { 30 | console.log("must given contract name with --contract") 31 | return; 32 | } 33 | 34 | Js4Eos.compile(argv.file, argv.g, {flag:'g2',contract:argv.contract}).then(data => { 35 | if (!data) { 36 | return; 37 | } 38 | console.log(data.stderr); 39 | console.log(data.stdout); 40 | console.log("Saving to", data.file); 41 | }) 42 | } 43 | if (argv.o) { 44 | Js4Eos.compile(argv.file, argv.o, {flag:'o2'}).then(data => { 45 | if (!data) { 46 | return; 47 | } 48 | console.log(data.stderr); 49 | console.log(data.stdout); 50 | console.log("Saving to", data.file); 51 | }) 52 | } 53 | } -------------------------------------------------------------------------------- /cmds/config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'config ' 8 | exports.desc = 'system configuration ' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('config_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/config_cmds/choose.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'choose ' 8 | exports.desc = 'choose configuration' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('choose_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/config_cmds/choose_cmds/network.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../../lib') 8 | 9 | exports.command = 'network' 10 | exports.desc = 'choose network' 11 | exports.builder = {} 12 | 13 | async function process(argv) { 14 | let config = Js4Eos.getConfig() 15 | 16 | console.log("Choose one network:") 17 | let i = 0; 18 | let networks = [] 19 | for(let network in config.networks) { 20 | if (network == config.currentNetwork) { 21 | console.log("\t*[" + i + "] " + network) 22 | } else { 23 | console.log("\t [" + i + "] " + network) 24 | } 25 | networks.push(network) 26 | i++ 27 | } 28 | var readline = require('readline-sync'); 29 | var input = readline.question("please input[0~" + (networks.length-1) + "]> "); 30 | try { 31 | let index = parseInt(input) 32 | if ((!index && index != 0) || index < 0 || index > i-1) { 33 | console.log("index must be 0~" + i) 34 | return; 35 | } 36 | config.currentNetwork = networks[index] 37 | Js4Eos.saveConfig(config) 38 | Js4Eos.printJson(config) 39 | } catch(e) { 40 | console.log(e) 41 | console.log("Invalid input") 42 | } 43 | } 44 | 45 | exports.handler = function (argv) { 46 | process(argv) 47 | } -------------------------------------------------------------------------------- /cmds/config_cmds/choose_cmds/url.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../../lib') 8 | 9 | exports.command = 'url' 10 | exports.desc = 'choose httpEndpoint' 11 | exports.builder = {} 12 | 13 | async function process(argv) { 14 | let config = Js4Eos.getConfig() 15 | let network = config.networks[config.currentNetwork] 16 | let endpoints = [] 17 | if (network.httpEndpoints) { 18 | for (let endpoint of network.httpEndpoints) { 19 | endpoints.push(endpoint) 20 | } 21 | } 22 | if (endpoints.indexOf(network.httpEndpoint) == -1) { 23 | endpoints.push(network.httpEndpoint) 24 | } 25 | 26 | console.log("Choose one httpEndpoint for " + config.currentNetwork + ":") 27 | for(let i in endpoints) { 28 | let endpoint = endpoints[i] 29 | if (endpoint == network.httpEndpoint) { 30 | console.log("\t*[" + i + "] " + endpoint) 31 | } else { 32 | console.log("\t [" + i + "] " + endpoint) 33 | } 34 | } 35 | var readline = require('readline-sync'); 36 | var input = readline.question("please input[0~" + (endpoints.length-1) + "]> "); 37 | try { 38 | let index = parseInt(input) 39 | if ((!index && index != 0) || index < 0 || index > endpoints.length-1) { 40 | console.log("index must be 0~" + (endpoints.length)) 41 | return; 42 | } 43 | config.networks[config.currentNetwork].httpEndpoint = endpoints[index] 44 | Js4Eos.saveConfig(config) 45 | Js4Eos.printJson(config) 46 | } catch(e) { 47 | console.log(e) 48 | console.log("Invalid input") 49 | } 50 | } 51 | 52 | exports.handler = function (argv) { 53 | process(argv) 54 | } -------------------------------------------------------------------------------- /cmds/config_cmds/list.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'list' 10 | exports.desc = 'show system current configuration, such as httpEndpoint, Chainid' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | let config = Js4Eos.getConfig(); 14 | Js4Eos.printJson(config) 15 | } -------------------------------------------------------------------------------- /cmds/config_cmds/reset.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'reset' 10 | exports.desc = 'reset configuration' 11 | exports.builder = {} 12 | 13 | exports.handler = function (argv) { 14 | Js4Eos.resetConfig().then(ret => Js4Eos.printJson(ret)); 15 | } -------------------------------------------------------------------------------- /cmds/config_cmds/set.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'set' 10 | exports.desc = 'set configurtion, such as chainid, httpEndpoint' 11 | exports.builder = yargs => yargs 12 | .options("c", { 13 | alias:'chainid', 14 | desc:"network chainid", 15 | type:'string', 16 | }) 17 | .options("n", { 18 | alias:'network', 19 | desc:"network name", 20 | type:'string', 21 | }) 22 | .options("p", { 23 | alias:'keyprefix', 24 | desc:"public key prefix", 25 | type:'string', 26 | }) 27 | .options("u", { 28 | alias:'url', 29 | desc:"network endpoint", 30 | type:'string', 31 | }) 32 | 33 | exports.handler = function (argv) { 34 | let config = Js4Eos.getConfig(); 35 | let network = argv.network 36 | if (!network) { 37 | //Do nothing 38 | } else if (network in config.networks) { 39 | config.currentNetwork = network 40 | } else { 41 | console.log("network " + network + " not exist") 42 | return; 43 | } 44 | if (argv.chainid) { 45 | config.networks[config.currentNetwork].chainId = argv.chainid; 46 | } 47 | if (argv.url) { 48 | let httpEndpoints = config.networks[config.currentNetwork].httpEndpoints 49 | if (!httpEndpoints) { 50 | httpEndpoints = [] 51 | } 52 | config.networks[config.currentNetwork].httpEndpoint = argv.url; 53 | if (httpEndpoints.indexOf(argv.url) == -1) { 54 | httpEndpoints.push(argv.url) 55 | config.networks[config.currentNetwork].httpEndpoints = httpEndpoints 56 | } 57 | } 58 | 59 | if (argv.keyprefix) { 60 | config.networks[config.currentNetwork].keyPrefix = argv.keyprefix; 61 | } 62 | // Js4Eos.printJson(config) 63 | Js4Eos.saveConfig(config) 64 | Js4Eos.printJson(config) 65 | } -------------------------------------------------------------------------------- /cmds/config_cmds/sync.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'sync' 10 | exports.desc = 'sync configuration file from network' 11 | exports.builder = {} 12 | 13 | async function process(argv) { 14 | let oldNetwork = Js4Eos.getConfig().currentNetwork 15 | let config = await Js4Eos.syncConfig() 16 | if (!config) { 17 | console.log("sync fail") 18 | return; 19 | } 20 | config.currentNetwork = oldNetwork 21 | Js4Eos.saveConfig(config) 22 | Js4Eos.printJson(config) 23 | } 24 | 25 | exports.handler = function (argv) { 26 | process(argv) 27 | } -------------------------------------------------------------------------------- /cmds/create.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'create ' 8 | exports.desc = 'Create various items, on and off the blockchain' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('create_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/create_cmds/account.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'account [activekey]' 10 | exports.desc = 'Create an account, buy ram, stake for bandwidth for the account' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.createAccount(argv.creator, argv.name, argv.ownerkey, argv.activekey?argv.activekey:argv.ownerkey).then(ret => Js4Eos.printTransaction(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/create_cmds/key.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'key' 10 | exports.desc = 'Create a new keypair and print the public and private keys' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.createKey(argv.key).then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/dapp.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'dapp ' 8 | exports.desc = 'dapp commands' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('dapp_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/dapp_cmds/compile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | var Js4Eos = require('../../index') 8 | const path = require('path') 9 | const fs = require('fs') 10 | 11 | exports.command = 'compile ' 12 | exports.desc = 'compile a contract' 13 | exports.builder = {} 14 | 15 | async function compile(argv) { 16 | try { 17 | var currentDir = process.cwd() 18 | var configFile = path.join(currentDir, "js4eos_config.js") 19 | if (!fs.existsSync(configFile)) { 20 | console.log("No config file js4eos_config.js") 21 | return; 22 | } 23 | let config = require(configFile) 24 | var network = argv.network 25 | if (!network) { 26 | network = config.defaultNetwork 27 | } 28 | 29 | let contractDir = path.join("./contracts", argv.contract) 30 | let sourceFile = path.join(contractDir, argv.contract + ".cpp"); 31 | if (!fs.existsSync(sourceFile)) { 32 | console.log("contract source file " + sourceFile + " not exist") 33 | return; 34 | } 35 | if (!config.deploy[argv.contract]) { 36 | console.log("Please add deploy config for contract '", argv.contract, "' in js4eos_config.js") 37 | return; 38 | } 39 | let contractAccount = config.deploy[argv.contract][network] 40 | if (!contractAccount) { 41 | console.log("No contract account, please set in js4eos_config.js") 42 | return; 43 | } 44 | let wasmFile = path.join(contractDir, argv.contract + ".wasm"); 45 | let abiFile = path.join(contractDir, argv.contract + ".abi"); 46 | Js4Eos = Js4Eos({ 47 | network:config.networks[network], 48 | keyProvider:config.keyProvider 49 | }) 50 | if (!config.eosio_cdt) { 51 | console.log("Compile wasm for", sourceFile) 52 | let ret = await Js4Eos.compile(sourceFile, wasmFile, {flag:'o'}) 53 | if (ret) { 54 | console.log(ret.stderr, ret.stdout) 55 | } 56 | console.log("Generated abi for", sourceFile) 57 | ret = await Js4Eos.compile(sourceFile, abiFile, {flag:'g'}) 58 | if (ret) { 59 | console.log(ret.stderr, ret.stdout) 60 | } 61 | } else { 62 | console.log("Compile wasm for", sourceFile) 63 | let ret = await Js4Eos.compile(sourceFile, wasmFile, {flag:'o2'}) 64 | if (ret) { 65 | console.log(ret.stderr, ret.stdout) 66 | } 67 | console.log("Generated abi for", sourceFile) 68 | ret = await Js4Eos.compile(sourceFile, abiFile, {flag:'g2', contract:argv.contract}) 69 | if (ret) { 70 | console.log(ret.stderr, ret.stdout) 71 | } 72 | } 73 | } catch(e) { 74 | console.log(e) 75 | } 76 | return null; 77 | } 78 | 79 | exports.handler = function (argv) { 80 | compile(argv); 81 | } -------------------------------------------------------------------------------- /cmds/dapp_cmds/create.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | const path = require('path') 7 | const fs = require('fs') 8 | exports.command = 'create ' 9 | exports.desc = 'Create an contract' 10 | exports.builder = {} 11 | exports.handler = function (argv) { 12 | var currentDir = process.cwd() 13 | var configFile = path.join(currentDir, "js4eos_config.js") 14 | if (!fs.existsSync(configFile)) { 15 | console.log("Not found js4eos application") 16 | return; 17 | } 18 | 19 | var contractDir = path.join('./contracts', argv.contract) 20 | var contractFile = path.join(contractDir, argv.contract + ".cpp") 21 | try { 22 | fs.mkdirSync(contractDir, '0777', true) 23 | fs.writeFileSync(contractFile, "// Generated by Js4eos.Enjoy programing a EOS contract") 24 | } catch(e) { 25 | console.log(e) 26 | } 27 | } -------------------------------------------------------------------------------- /cmds/dapp_cmds/deploy.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | var Js4Eos = require('../../index') 8 | const path = require('path') 9 | const fs = require('fs') 10 | 11 | exports.command = 'deploy [network]' 12 | exports.desc = 'deploy a contract in a network' 13 | exports.builder = {} 14 | 15 | async function deploy(argv) { 16 | try { 17 | var currentDir = process.cwd() 18 | var configFile = path.join(currentDir, "js4eos_config.js") 19 | if (!fs.existsSync(configFile)) { 20 | console.log("No config file js4eos_config.js") 21 | return; 22 | } 23 | let config = require(configFile) 24 | var network = argv.network 25 | if (!network) { 26 | network = config.defaultNetwork 27 | } 28 | 29 | let contractDir = path.join("./contracts", argv.contract) 30 | let contractAccount = config.deploy[argv.contract][network] 31 | if (!contractAccount) { 32 | console.log("No contract account, please set in js4eos_config.js") 33 | return; 34 | } 35 | 36 | let wasmFile = path.join(contractDir, argv.contract + ".wasm"); 37 | let abiFile = path.join(contractDir, argv.contract + ".abi"); 38 | Js4Eos = Js4Eos({ 39 | network:config.networks[network], 40 | keyProvider:config.keyProvider 41 | }) 42 | if (!fs.existsSync(wasmFile)) { 43 | console.log("No wasmFile", wasmFile) 44 | console.log("please run 'js4eos dapp compile " + argv.contract + "' firstly") 45 | return; 46 | } 47 | ret = await Js4Eos.setContract(contractAccount, contractDir) 48 | Js4Eos.printTransaction(ret) 49 | } catch(e) { 50 | console.log(e) 51 | } 52 | return null; 53 | } 54 | 55 | exports.handler = function (argv) { 56 | deploy(argv); 57 | } -------------------------------------------------------------------------------- /cmds/dapp_cmds/init.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | var fs = require('fs') 7 | var exec = require('child_process').exec; 8 | var unzip = require("unzip"); 9 | var Js4Eos = require('../../lib') 10 | var Utils = require("../../lib/utils") 11 | 12 | exports.command = 'init' 13 | exports.desc = 'init a eos dapp project' 14 | exports.builder = yargs => yargs 15 | .options("v", { 16 | alias:"version", 17 | desc:"init a vscode demo application", 18 | type:'string', 19 | default:'master', 20 | }) 21 | const ZIP_DIR_PREFIX = 'js4eos-demo-' 22 | async function handle(argv) { 23 | let url = Js4Eos.getConfig().appdemourl2 + "/" + argv.version + ".zip" 24 | console.log("Downloading", url) 25 | await Utils.downloadFile(url, './tmp.zip'); 26 | var ZIP_DIR = ZIP_DIR_PREFIX + argv.version; 27 | fs.createReadStream('./tmp.zip').pipe(unzip.Extract({ path: './' })).on('close', function () { 28 | files = fs.readdirSync(ZIP_DIR); 29 | files.forEach(function(file, index) { 30 | var curPath = ZIP_DIR + '/' + file; 31 | var dstPath = './' + file; 32 | fs.renameSync(curPath, dstPath); 33 | }); 34 | try { 35 | fs.rmdirSync(ZIP_DIR); 36 | } catch(e) { 37 | console.log(e) 38 | } 39 | try { 40 | fs.unlinkSync('./tmp.zip'); 41 | } catch(e) { 42 | console.log(e) 43 | } 44 | try{ 45 | exec('npm install', function (error, stdout, stderr) { 46 | process.stdout.write(stdout) 47 | process.stderr.write(stderr) 48 | }); 49 | } catch(e) { 50 | console.log(e) 51 | } 52 | }).on('error', function(err){ 53 | console.log("fail"); 54 | }); 55 | } 56 | 57 | exports.handler = function (argv) { 58 | handle(argv) 59 | } -------------------------------------------------------------------------------- /cmds/dapp_cmds/test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | var exec = require('child_process').exec; 7 | var path = require('path') 8 | 9 | exports.command = 'test [file]' 10 | exports.desc = 'test' 11 | exports.builder = yargs => yargs 12 | .options("g", { 13 | alias:'grep', 14 | desc:"grep pattern", 15 | type:'string', 16 | }) 17 | exports.handler = function (argv) { 18 | try { 19 | var currentDir = process.cwd() 20 | var binFile = path.join(currentDir, "node_modules") 21 | binFile = path.join(binFile, ".bin") 22 | binFile = path.join(binFile, "mocha") 23 | var cmd = binFile 24 | if (argv.file) { 25 | cmd = cmd + " " + argv.file 26 | } 27 | if (argv.grep) { 28 | cmd = binFile + " -g " + argv.grep 29 | } 30 | let tmp = exec(cmd) 31 | tmp.stdout.pipe(process.stdout); 32 | tmp.stderr.pipe(process.stderr); 33 | } catch(e) { 34 | console.log(e) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /cmds/doc.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'doc ' 8 | exports.desc = 'document' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('doc_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/doc_cmds/guild.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | const open = require('open') 9 | 10 | exports.command = 'guild' 11 | exports.desc = 'Getting Started Guild | Js4eos' 12 | exports.builder = {} 13 | exports.handler = function (argv) { 14 | open("https://github.com/itleaks/js4eos/blob/master/README.md"); 15 | } -------------------------------------------------------------------------------- /cmds/doc_cmds/network.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | const open = require('open') 9 | 10 | exports.command = 'network' 11 | exports.desc = 'show eos network' 12 | exports.builder = {} 13 | exports.handler = function (argv) { 14 | open("https://github.com/itleaks/js4eos/blob/master/docs/networks.md"); 15 | } -------------------------------------------------------------------------------- /cmds/ext.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'ext ' 8 | exports.desc = 'extended command' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('ext_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/ext_cmds/claimeeth.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | const Request = require('../../lib/request') 9 | 10 | exports.command = 'claimeeth ' 11 | exports.desc = 'claim token eeth, it will eat 0.24k RAM once' 12 | exports.builder = {} 13 | async function process(argv) { 14 | try { 15 | let ret = await Request.get("https://faucet.eosfavor.com/airdropaccount") 16 | ret = JSON.parse(ret) 17 | let data = [argv.account, ret[0].name, "1.0000 EETH", "免费领取EETH, wallet.eosfavor.com或者TP钱包Dapp发现栏搜索Eosfavor(Send 1 EETH to another account without EETH, you will get 5000 EETH as award),电报群:https://t.me/anyosio,更多请进:anyos.io"] 18 | ret = await Js4Eos.pushRawAction('ethsidechain', 'transfer', JSON.stringify(data), argv.account) 19 | Js4Eos.printTransaction(ret) 20 | } catch(e) { 21 | console.log(e) 22 | } 23 | } 24 | 25 | exports.handler = function (argv) { 26 | process(argv) 27 | } -------------------------------------------------------------------------------- /cmds/faucet.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../lib') 8 | const open = require('open') 9 | const Request = require('../lib/request') 10 | 11 | exports.command = 'faucet ' 12 | exports.desc = 'faucet' 13 | exports.builder = {} 14 | 15 | async function createAccount(url, account) { 16 | try { 17 | let data = await Js4Eos.createKey() 18 | // console.log(url) 19 | let res = await Request.get(url,{ 20 | account, 21 | key:data.publicKey, 22 | }); 23 | res = JSON.parse(res) 24 | // console.log(res) 25 | if (res.error == 0) { 26 | console.log("create account success") 27 | data.account = account; 28 | Js4Eos.printJson(data) 29 | return; 30 | } else { 31 | Js4Eos.printJson(res.info) 32 | } 33 | } catch(e) { 34 | console.log(e) 35 | } 36 | console.log("create account fail") 37 | } 38 | 39 | exports.handler = function (argv) { 40 | let config = Js4Eos.getConfig() 41 | let faucetConfig = Js4Eos.getNetwork().faucet 42 | if (!faucetConfig) { 43 | faucetConfig = config.faucet 44 | } 45 | // console.log(faucetConfig) 46 | 47 | if (faucetConfig.type == 'web') { 48 | open(faucetConfig.url); 49 | } else { 50 | createAccount(faucetConfig.url, argv.account) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /cmds/get.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'get ' 8 | exports.desc = 'Retrieve various items and information from the blockchain' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('get_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/get_cmds/abi.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'abi ' 10 | exports.desc = ' Retrieve the ABI for an account' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getAbi(argv.contract).then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/get_cmds/account.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'account ' 10 | exports.desc = 'Create an empty repo' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getAccount(argv.name).then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/get_cmds/accounts.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'accounts ' 10 | exports.desc = ' get accounts from public key' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getAccounts(argv.pubkey).then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/get_cmds/actions.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'actions [pos] [offset]' 10 | exports.desc = ' get action history of a account' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getActions(argv.account, argv.pos, argv.offset).then(ret => { 14 | if (ret) { 15 | Js4Eos.printTransactions(ret.actions) 16 | } else { 17 | console.log("No datas") 18 | } 19 | }); 20 | } -------------------------------------------------------------------------------- /cmds/get_cmds/block.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'block ' 10 | exports.desc = 'get one block info' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getBlock(argv.height).then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/get_cmds/currency.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'currency ' 8 | exports.desc = 'Retrieve information related to standard currencies' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('currency_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/get_cmds/currency_cmds/balance.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../../lib') 8 | 9 | exports.command = 'balance [symbol]' 10 | exports.desc = 'Retrieve the balance of an account for a given currency' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getCurrencyBalance(argv.contract, argv.account, argv.symbol).then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/get_cmds/currency_cmds/stats.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../../lib') 8 | 9 | exports.command = 'stats ' 10 | exports.desc = 'Retrieve the stats of for a given currency' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getCurrencyStats(argv.contract, argv.symbol).then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/get_cmds/info.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'info' 10 | exports.desc = 'get blockchain info' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getInfo().then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/get_cmds/table.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'table ' 10 | exports.desc = 'Retrieve the contents of a database table' 11 | exports.builder = yargs => yargs 12 | .options("l", { 13 | alias:"limit", 14 | desc:"The maximum number of rows to return", 15 | type:'number', 16 | default:10, 17 | }) 18 | .options("L", { 19 | alias:"lower", 20 | desc:"JSON representation of lower bound value of key, defaults to first", 21 | type:'string', 22 | default:'', 23 | }) 24 | .options("U", { 25 | alias:"upper", 26 | desc:"JSON representation of upper bound value value of key, defaults to last", 27 | type:'string', 28 | default:'', 29 | }) 30 | .options("i", { 31 | alias:"index", 32 | desc:"Index number, 1 - primary (first), 2 - secondary index (in order defined by multi_index), 3 - third index, etc.", 33 | type:'number', 34 | default:1, 35 | }) 36 | .options("k", { 37 | alias:"key_type", 38 | desc:"The key type of --index, primary only supports (i64), all others support (i64, i128, i256, float64, float128, ripemd160, sha256).", 39 | type:'string', 40 | default:'', 41 | }) 42 | exports.handler = function (argv) { 43 | Js4Eos.getTable(argv.contract, argv.scope, argv.table, argv.lower, argv.upper, argv.limit, argv.key_type, argv.index).then(ret => Js4Eos.printJson(ret)); 44 | } -------------------------------------------------------------------------------- /cmds/get_cmds/transaction.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'transaction ' 10 | exports.desc = 'Retrieve a transaction from the blockchain' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getTransaction(argv.trxid, argv.block_num_hint).then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/localnet.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'localnet ' 8 | exports.desc = 'manage local eos network' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('localnet_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/localnet_cmds/reset.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | var exec = require('child_process').exec; 8 | var fs = require('fs'); 9 | 10 | 11 | const Js4Eos = require('../../lib') 12 | const Config = require('../../lib').getConfig() 13 | 14 | const MAGIC_KEY = '0' 15 | 16 | const DEFAULT_PUB_KEY = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV'; 17 | const DEFAULT_PRI_KEY = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'; 18 | const NODEOS_CMD_PREFIX = 'nodeos -e -p eosio --verbose-http-errors --http-server-address 0.0.0.0:8888 --max-transaction-time=1000 --contracts-console --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin' 19 | 20 | exports.command = 'reset [datadir]' 21 | exports.desc = 'reset local eos network' 22 | 23 | exports.builder = yargs => yargs 24 | .options("p", { 25 | alias:'privatekey', 26 | desc:"private key", 27 | type:'string', 28 | }) 29 | 30 | 31 | function sleep(ms) { 32 | return new Promise(resolve => setTimeout(resolve, ms)); 33 | } 34 | 35 | async function process(argv) { 36 | let killDone = false; 37 | var killNodeos = 'pkill -9 nodeos'; 38 | console.log("Killing old nodeos...") 39 | exec(killNodeos, function(err, stdout, stderr) { 40 | // console.log(err, stdout, stderr) 41 | startNodeos(argv).then(function(value) { 42 | // fulfillment 43 | }, function(reason) { 44 | console.log(reason) 45 | }); 46 | }) 47 | } 48 | 49 | async function startNodeos(argv) { 50 | await sleep(1500) //sleep 1.5s 51 | let keys = {}; 52 | if (false && argv.privatekey) { 53 | if (argv.privatekey == MAGIC_KEY) { 54 | keys = Js4Eos.createKey(); 55 | } else { 56 | keys.publicKey = await Js4Eos.privateToPublic(argv.privatekey) 57 | keys.privateKey = argv.privatekey 58 | } 59 | } else { 60 | keys = { 61 | privateKey:DEFAULT_PRI_KEY, 62 | publicKey:DEFAULT_PUB_KEY 63 | }; 64 | } 65 | 66 | let dataDir = argv.datadir 67 | if (!dataDir) { 68 | dataDir = Config.dataDir + "/nodeos" 69 | } 70 | if (!fs.existsSync(dataDir)) { 71 | try { 72 | fs.unlinkSync(dataDir); 73 | } catch(e) { 74 | } 75 | try { 76 | fs.mkdirSync(dataDir, '0777', true) 77 | } catch(e) { 78 | console.log(e) 79 | } 80 | } 81 | 82 | let logFile = dataDir + "/output.log" 83 | let cmd = NODEOS_CMD_PREFIX + ' --delete-all-blocks --config-dir ' + dataDir + ' --data-dir ' + dataDir + ' --private-key ["' + keys.publicKey + '","' + keys.privateKey +'"] > ' + logFile + ' 2>&1' 84 | // console.log(args) 85 | 86 | try { 87 | var daemon = require("daemonize2").setup({ 88 | main: "bg_service", 89 | name: "js4eos_nodeos", 90 | pidfile: require('path').join(require('os').homedir(), ".js4eos_nodeos.pid"), 91 | argv:[cmd] 92 | }); 93 | var pid = daemon.status(); 94 | if (!pid) { 95 | daemon.start(); 96 | daemon.on('started', () => { 97 | console.log("Reset nodeos success, eosio account") 98 | console.log(keys) 99 | }); 100 | } else { 101 | console.log("kill old nodeos fail, please kill it manually") 102 | } 103 | } catch(e) { 104 | console.log(e) 105 | } 106 | } 107 | 108 | exports.handler = function (argv) { 109 | process(argv) 110 | } -------------------------------------------------------------------------------- /cmds/localnet_cmds/restart.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | var exec = require('child_process').exec; 8 | var fs = require('fs'); 9 | 10 | 11 | const Js4Eos = require('../../lib') 12 | const Config = require('../../lib').getConfig() 13 | 14 | const DEFAULT_PUB_KEY = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV'; 15 | const DEFAULT_PRI_KEY = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'; 16 | const NODEOS_CMD_PREFIX = 'nodeos -e -p eosio --http-server-address 0.0.0.0:8888 --max-transaction-time=1000 --contracts-console --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin' 17 | 18 | exports.command = 'restart [datadir]' 19 | exports.desc = 'restart local eos network' 20 | 21 | exports.builder = yargs => yargs 22 | .options("p", { 23 | alias:'privatekey', 24 | desc:"private key", 25 | type:'string', 26 | }) 27 | 28 | async function process(argv) { 29 | let killDone = false; 30 | var killNodeos = 'pkill -9 nodeos'; 31 | exec(killNodeos, function(err, stdout, stderr) { 32 | // console.log(err, stdout, stderr) 33 | startNodeos(argv); 34 | }) 35 | } 36 | 37 | async function startNodeos(argv) { 38 | let keys = {}; 39 | if (false && argv.privatekey) { 40 | if (argv.privatekey == MAGIC_KEY) { 41 | keys = Js4Eos.createKey(); 42 | } else { 43 | keys.publicKey = await Js4Eos.privateToPublic(argv.privatekey) 44 | keys.privateKey = argv.privatekey 45 | } 46 | } else { 47 | keys = { 48 | privateKey:DEFAULT_PRI_KEY, 49 | publicKey:DEFAULT_PUB_KEY 50 | }; 51 | } 52 | let dataDir = argv.datadir 53 | if (!dataDir) { 54 | dataDir = Config.dataDir + "/nodeos" 55 | } 56 | let logFile = dataDir + "/output.log" 57 | let cmd = NODEOS_CMD_PREFIX + ' --hard-replay-blockchain --config-dir ' + dataDir + ' --data-dir ' + dataDir + ' --private-key [' + keys.publicKey + ',' + keys.privateKey +'] > ' + logFile + ' 2>&1' 58 | // console.log(args) 59 | try { 60 | var daemon = require("daemonize2").setup({ 61 | main: "bg_service", 62 | name: "js4eos_nodeos", 63 | pidfile: require('path').join(require('os').homedir(), ".js4eos_nodeos.pid"), 64 | argv:[cmd] 65 | }); 66 | var pid = daemon.status(); 67 | if (!pid) { 68 | daemon.start(); 69 | daemon.on('started', () => { 70 | console.log("Reset nodeos success, eosio account") 71 | console.log(keys) 72 | }); 73 | } else { 74 | console.log("kill old nodeos fail, please kill it manually") 75 | } 76 | } catch(e) { 77 | console.log(e) 78 | } 79 | } 80 | 81 | exports.handler = function (argv) { 82 | process(argv) 83 | } -------------------------------------------------------------------------------- /cmds/localnet_cmds/start.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | var exec = require('child_process').exec; 8 | var fs = require('fs'); 9 | 10 | 11 | const Js4Eos = require('../../lib') 12 | const Config = require('../../lib').getConfig() 13 | 14 | const DEFAULT_PUB_KEY = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV'; 15 | const DEFAULT_PRI_KEY = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'; 16 | const NODEOS_CMD_PREFIX = 'nodeos -e -p eosio --http-server-address 0.0.0.0:8888 --max-transaction-time=1000 --contracts-console --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin' 17 | 18 | exports.command = 'start [datadir]' 19 | exports.desc = 'start local eos network' 20 | 21 | exports.builder = yargs => yargs 22 | .options("p", { 23 | alias:'privatekey', 24 | desc:"private key", 25 | type:'string', 26 | }) 27 | 28 | async function process(argv) { 29 | startNodeos(argv) 30 | } 31 | 32 | async function startNodeos(argv) { 33 | let keys = {}; 34 | if (false && argv.privatekey) { 35 | if (argv.privatekey == MAGIC_KEY) { 36 | keys = Js4Eos.createKey(); 37 | } else { 38 | keys.publicKey = await Js4Eos.privateToPublic(argv.privatekey) 39 | keys.privateKey = argv.privatekey 40 | } 41 | } else { 42 | keys = { 43 | privateKey:DEFAULT_PRI_KEY, 44 | publicKey:DEFAULT_PUB_KEY 45 | }; 46 | } 47 | let dataDir = argv.datadir 48 | if (!dataDir) { 49 | dataDir = Config.dataDir + "/nodeos" 50 | } 51 | let logFile = dataDir + "/output.log" 52 | let cmd = NODEOS_CMD_PREFIX + ' --hard-replay-blockchain --config-dir ' + dataDir + ' --data-dir ' + dataDir + ' --private-key [' + keys.publicKey + ',' + keys.privateKey +'] > ' + logFile + ' 2>&1' 53 | // console.log(args) 54 | try { 55 | var daemon = require("daemonize2").setup({ 56 | main: "bg_service", 57 | name: "js4eos_nodeos", 58 | pidfile: require('path').join(require('os').homedir(), ".js4eos_nodeos.pid"), 59 | argv:[cmd] 60 | }); 61 | var pid = daemon.status(); 62 | if (!pid) { 63 | daemon.start(); 64 | daemon.on('started', () => { 65 | console.log("Reset nodeos success, eosio account") 66 | console.log(keys) 67 | }); 68 | } else { 69 | console.log("nodeos is already running") 70 | } 71 | } catch(e) { 72 | console.log(e) 73 | } 74 | } 75 | 76 | exports.handler = function (argv) { 77 | process(argv) 78 | } -------------------------------------------------------------------------------- /cmds/localnet_cmds/stop.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | const Config = require('../../lib').getConfig() 9 | 10 | var exec = require('child_process').exec; 11 | 12 | exports.command = 'stop' 13 | exports.desc = 'stop local eos network' 14 | exports.builder = {} 15 | async function process(argv) { 16 | let killDone = false; 17 | var killNodeos = 'pkill -9 nodeos'; 18 | exec(killNodeos, function(err, stdout, stderr) { 19 | if (err) { 20 | // console.log(err) 21 | } else { 22 | console.log(stdout) 23 | console.log(stderr) 24 | } 25 | }) 26 | } 27 | 28 | exports.handler = function (argv) { 29 | process(argv) 30 | } -------------------------------------------------------------------------------- /cmds/push.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'push ' 8 | exports.desc = 'Push arbitrary transactions to the blockchain' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('push_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/push_cmds/action.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'action ' 10 | exports.desc = 'Push a transaction with a single action' 11 | exports.builder = yargs => yargs 12 | .options("p", { 13 | alias:"permission", 14 | desc:"An account and permission level to authorize, as in 'account@permission'", 15 | type:'string', 16 | default:false, 17 | }) 18 | exports.handler = function (argv) { 19 | Js4Eos.pushRawAction(argv.contract, argv.action, argv.data, argv.p).then(ret => Js4Eos.printTransaction(ret)); 20 | } -------------------------------------------------------------------------------- /cmds/reset.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | const fs = require('fs') 7 | // const process = require('process') 8 | 9 | exports.command = 'reset' 10 | exports.desc = 'reset to initial state' 11 | exports.builder = {} 12 | 13 | function deleteall(path) { 14 | var files = []; 15 | if(fs.existsSync(path)) { 16 | files = fs.readdirSync(path); 17 | files.forEach(function(file, index) { 18 | var curPath = path + "/" + file; 19 | if(fs.statSync(curPath).isDirectory()) { 20 | deleteall(curPath); 21 | } else { // delete file 22 | fs.unlinkSync(curPath); 23 | } 24 | }); 25 | fs.rmdirSync(path); 26 | } 27 | } 28 | 29 | async function handle() { 30 | bgpidFile = require('path').join(require('os').homedir(), ".js4eos_bg2.pid") 31 | var pid = 0; 32 | if (fs.existsSync(bgpidFile)) { 33 | try { 34 | pid = fs.readFileSync(bgpidFile).toString(); 35 | } catch(e) { 36 | console.log(e) 37 | } 38 | } 39 | if (!pid) { 40 | console.log("Not found bg process") 41 | return; 42 | } 43 | 44 | setTimeout(() => { 45 | try { 46 | var isWin = process.platform === "win32" 47 | if (isWin) { 48 | var exec = require('child_process').exec 49 | exec("taskkill /f /pid " + pid) 50 | } else { 51 | process.kill(pid, 'SIGHUP'); 52 | } 53 | setTimeout(() => { 54 | try { 55 | deleteall(require('path').join(require('os').homedir(), ".js4eos")); 56 | } catch(e) { 57 | console.log(e) 58 | return "delete fail"; 59 | } 60 | }, 1000) 61 | } catch(e) { 62 | console.log(e) 63 | } 64 | }, 1000); 65 | } 66 | 67 | exports.handler = function (argv) { 68 | handle() 69 | } -------------------------------------------------------------------------------- /cmds/set.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'set ' 8 | exports.desc = 'Set or update blockchain state' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('set_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/set_cmds/abi.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'abi ' 10 | exports.desc = 'Create or update the contract on an account' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.setAbi(argv.account, argv.abifile).then(ret => Js4Eos.printTransaction(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/set_cmds/code.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'code ' 10 | exports.desc = 'Create or update the contract on an account' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.setCode(argv.account, argv.wasmfile).then(ret => Js4Eos.printTransaction(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/set_cmds/contract.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'contract ' 10 | exports.desc = 'Create or update the contract on an account' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.setContract(argv.account, argv.dir).then(ret => Js4Eos.printTransaction(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/set_cmds/permission.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'account permission [parent]' 10 | exports.desc = 'set permission' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | // console.log(argv.account) 14 | // console.log(argv.permission) 15 | 16 | if (argv.permission != 'active') { 17 | console.log('only support update active permission') 18 | return; 19 | } 20 | let parent = argv.parent ? argv.parent : 'active' 21 | Js4Eos.setPermission(argv.account, argv.permission, argv.authority, parent).then(ret => Js4Eos.printTransaction(ret)); 22 | } -------------------------------------------------------------------------------- /cmds/system.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'system ' 8 | exports.desc = 'Send eosio.system contract action to the blockchain.' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('system_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/system_cmds/buyram.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'buyram ' 10 | exports.desc = 'Buy RAM' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | // console.log(argv); 14 | Js4Eos.buyRam( 15 | argv.payer, 16 | argv.receiver, 17 | argv.tokens, 18 | ).then(ret => Js4Eos.printTransaction(ret)); 19 | } -------------------------------------------------------------------------------- /cmds/system_cmds/delegatebw.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | */ 5 | 6 | const Js4Eos = require('../../lib') 7 | 8 | exports.command = 'delegatebw ' 9 | exports.desc = 'Delegate bandwidth' 10 | exports.builder = yargs => yargs 11 | .options("transfer", { 12 | desc:"Transfer voting power and right to unstake EOS to receiver", 13 | type:'bool', 14 | default:false, 15 | }) 16 | .options("p", { 17 | alias:"permission", 18 | desc:"An account and permission level to authorize, as in 'account@permission'", 19 | type:'string', 20 | default:false, 21 | }) 22 | exports.handler = function (argv) { 23 | Js4Eos.delegatebw(argv.from, argv.receiver, 24 | argv.stake_net_quantity, 25 | argv.stake_cpu_quantity, argv.transfer ? 1 : 0, 26 | argv.permission 27 | ).then(ret => Js4Eos.printTransaction(ret)); 28 | } -------------------------------------------------------------------------------- /cmds/system_cmds/exchange.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'exchange ' 10 | exports.desc = 'exchange' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | // console.log(argv); 14 | Js4Eos.exchange( 15 | argv.contract, 16 | argv.account, 17 | argv.quantity, 18 | ).then(ret => Js4Eos.printJson(ret)); 19 | } -------------------------------------------------------------------------------- /cmds/system_cmds/newaccount.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | */ 5 | 6 | const Js4Eos = require('../../lib') 7 | 8 | exports.command = 'newaccount [active_key]' 9 | exports.desc = 'Create an account, buy ram, stake for bandwidth for the account' 10 | exports.builder = yargs => yargs 11 | .options("stake-net", { 12 | desc:"The amount of EOS delegated for net bandwidth (required)", 13 | type:'string', 14 | demand: true, 15 | }) 16 | .options("stake-cpu", { 17 | desc:"The amount of EOS delegated for cpu bandwidth (required)", 18 | type:'string', 19 | demand: true, 20 | }) 21 | .options("buy-ram-kbytes", { 22 | desc:"The amount of RAM bytes to purchase for the new account in kibibytes (KiB), default is 8 KiB", 23 | type:'int', 24 | }) 25 | .options("buy-ram", { 26 | desc:"The amount of RAM bytes to purchase for the new account in EOS", 27 | type:'string', 28 | }) 29 | .options("transfer", { 30 | desc:"Transfer voting power and right to unstake EOS to receiver", 31 | type:'bool', 32 | default:false, 33 | }) 34 | // .options("p", { 35 | // alias:"permission", 36 | // desc:"An account and permission level to authorize, as in 'account@permission'", 37 | // type:'string', 38 | // default:false, 39 | // }) 40 | exports.handler = function (argv) { 41 | // console.log(argv); 42 | Js4Eos.newAccount( 43 | argv.creator, 44 | argv.name, 45 | argv.owner_key, 46 | argv.active_key ? argv.active_key : argv.owner_key, 47 | argv.stakeNet, 48 | argv.stakeCpu, 49 | argv.buyRam, 50 | argv.buyRamKbytes*1000, 51 | argv.transfer ? 1:0 52 | ).then(ret => Js4Eos.printTransaction(ret)); 53 | } -------------------------------------------------------------------------------- /cmds/system_cmds/sellram.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | */ 5 | 6 | const Js4Eos = require('../../lib') 7 | 8 | exports.command = 'sellram ' 9 | exports.desc = 'Sell RAM' 10 | exports.builder = {} 11 | exports.handler = function (argv) { 12 | // console.log(argv); 13 | Js4Eos.sellRam( 14 | argv.accountr, 15 | argv.bytes, 16 | ).then(ret => Js4Eos.printTransaction(ret)); 17 | } -------------------------------------------------------------------------------- /cmds/system_cmds/undelegatebw.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | */ 5 | 6 | const Js4Eos = require('../../lib') 7 | 8 | exports.command = 'undelegatebw ' 9 | exports.desc = 'UnDelegate bandwidth' 10 | exports.builder = yargs => yargs 11 | .options("p", { 12 | alias:"permission", 13 | desc:"An account and permission level to authorize, as in 'account@permission'", 14 | type:'string', 15 | default:false, 16 | }) 17 | exports.handler = function (argv) { 18 | Js4Eos.undelegatebw(argv.from, argv.receiver, 19 | argv.stake_net_quantity, 20 | argv.stake_cpu_quantity, 21 | argv.permission 22 | ).then(ret => Js4Eos.printTransaction(ret)); 23 | } -------------------------------------------------------------------------------- /cmds/version.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'version' 8 | exports.desc = 'version of js4eos' 9 | exports.builder = {} 10 | exports.handler = function (argv) { 11 | var pjson = require('../package.json'); 12 | console.log(pjson.version); 13 | } -------------------------------------------------------------------------------- /cmds/wallet.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | exports.command = 'wallet ' 8 | exports.desc = 'Interact with local wallet' 9 | exports.builder = function (yargs) { 10 | return yargs.commandDir('wallet_cmds') 11 | } 12 | exports.handler = function (argv) { 13 | } -------------------------------------------------------------------------------- /cmds/wallet_cmds/create.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'create' 10 | exports.desc = 'create default wallet' 11 | exports.builder = yargs => yargs 12 | .options("n", { 13 | alias:'name', 14 | desc:"wallet name", 15 | type:'string', 16 | }) 17 | exports.handler = function (argv) { 18 | let name = argv.name 19 | if (!name) { 20 | name = 'default' 21 | } 22 | Js4Eos.createWallet(name).then(ret => Js4Eos.printJson(ret)); 23 | } -------------------------------------------------------------------------------- /cmds/wallet_cmds/createkey.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'create_key' 10 | exports.desc = 'create a key within wallet' 11 | exports.builder = yargs => yargs 12 | .options("n", { 13 | alias:'name', 14 | desc:"wallet name", 15 | type:'string', 16 | }) 17 | exports.handler = function (argv) { 18 | let name = argv.name 19 | if (!name) { 20 | name = 'default' 21 | } 22 | Js4Eos.createKeyInWallet(name).then(ret => Js4Eos.printJson(ret)); 23 | } -------------------------------------------------------------------------------- /cmds/wallet_cmds/delete.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'delete' 10 | exports.desc = 'delete wallet' 11 | exports.builder = yargs => yargs 12 | .options("n", { 13 | alias:'name', 14 | desc:"wallet name", 15 | type:'string', 16 | }) 17 | exports.handler = function (argv) { 18 | let name = argv.name 19 | if (!name) { 20 | name = 'default' 21 | } 22 | Js4Eos.deleteWallet(name).then(ret => Js4Eos.printJson(ret)); 23 | } -------------------------------------------------------------------------------- /cmds/wallet_cmds/import.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'import ' 10 | exports.desc = 'Import private key into wallet' 11 | exports.builder = yargs => yargs 12 | .options("n", { 13 | alias:'name', 14 | desc:"wallet name", 15 | type:'string', 16 | }) 17 | 18 | async function process(argv) { 19 | let name = argv.name 20 | if (!name) { 21 | name = 'default' 22 | } 23 | let ret = await Js4Eos.importKey(name, argv.key) 24 | if (ret) { 25 | let pubkey = await Js4Eos.privateToPublic(argv.key); 26 | console.log("Import success:", pubkey); 27 | } 28 | } 29 | 30 | exports.handler = function (argv) { 31 | process(argv) 32 | } -------------------------------------------------------------------------------- /cmds/wallet_cmds/keys.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'keys' 10 | exports.desc = 'list keys' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getPublicKeys().then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/wallet_cmds/list.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'list' 10 | exports.desc = 'list wallet' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.listWallet().then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/wallet_cmds/lock.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'lock' 10 | exports.desc = 'lock wallet' 11 | exports.builder = yargs => yargs 12 | .options("n", { 13 | alias:'name', 14 | desc:"wallet name", 15 | type:'string', 16 | }) 17 | exports.handler = function (argv) { 18 | let name = argv.name 19 | if (!name) { 20 | name = 'default' 21 | } 22 | Js4Eos.lockWallet(name).then(ret => Js4Eos.printJson(ret)); 23 | } -------------------------------------------------------------------------------- /cmds/wallet_cmds/privatekey.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'private_keys' 10 | exports.desc = 'list keys' 11 | exports.builder = {} 12 | exports.handler = function (argv) { 13 | Js4Eos.getPrivateKeys().then(ret => Js4Eos.printJson(ret)); 14 | } -------------------------------------------------------------------------------- /cmds/wallet_cmds/stop.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | const fs = require('fs') 7 | 8 | exports.command = 'stop' 9 | exports.desc = 'stop wallet daemon' 10 | exports.builder = {} 11 | 12 | function handle() { 13 | bgpidFile = require('path').join(require('os').homedir(), ".js4eos_bg2.pid") 14 | var pid = 0; 15 | if (fs.existsSync(bgpidFile)) { 16 | try { 17 | pid = fs.readFileSync(bgpidFile).toString(); 18 | } catch(e) { 19 | console.log(e) 20 | } 21 | } 22 | if (!pid) { 23 | console.log("Not found bg process") 24 | return; 25 | } 26 | 27 | setTimeout(() => { 28 | try { 29 | var isWin = process.platform === "win32" 30 | if (isWin) { 31 | var exec = require('child_process').exec 32 | exec("taskkill /f /pid " + pid) 33 | } else { 34 | process.kill(pid, 'SIGHUP'); 35 | } 36 | console.log("stop success") 37 | } catch(e) { 38 | console.log(e) 39 | } 40 | }, 1000); 41 | } 42 | 43 | exports.handler = function (argv) { 44 | handle() 45 | } -------------------------------------------------------------------------------- /cmds/wallet_cmds/unlock.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | const Js4Eos = require('../../lib') 8 | 9 | exports.command = 'unlock' 10 | exports.desc = 'unlock wallet' 11 | exports.builder = yargs => yargs 12 | .options("n", { 13 | alias:'name', 14 | desc:"wallet name", 15 | type:'string', 16 | }) 17 | .options("p", { 18 | alias:'password', 19 | desc:"wallet password", 20 | type:'string', 21 | }) 22 | exports.handler = function (argv) { 23 | let name = argv.name 24 | if (!name) { 25 | name = 'default' 26 | } 27 | let passwd = argv.password 28 | if (!passwd) { 29 | var readline = require('readline-sync'); 30 | passwd = readline.question("passwd> ", { 31 | hideEchoBack: true // The typed text on screen is hidden by `*` (default). 32 | }); 33 | } 34 | Js4Eos.unlockWallet(name, passwd).then(ret => Js4Eos.printJson(ret)); 35 | } -------------------------------------------------------------------------------- /docs/faucet.md: -------------------------------------------------------------------------------- 1 | # Mainnet主网 2 | ## 创建账号 3 | 主网没有免费账号,大家可以在下面网页有偿创建账号
4 | https://eosfavor.com/newaccount
5 | whaleex和meet.one联合”免费账号注册“活动入口在下面,具体是否真的免费需自己咨询及判断
6 | https://whaleex.zendesk.com/hc/zh-cn/articles/360018574991 7 | # ENU牛油果网络 8 | ## 创建免费账号 9 | TokenPocket钱包可以免费创建 10 | 11 | # EOSForce 12 | ## 创建免费账号 13 | 下载麦子钱包,可以免费创建 14 | 15 | # kylin麒麟网络 16 | ## 创建免费账号 17 | 浏览器输入 18 | http://faucet.cryptokylin.io/create_account?xxxx 19 | 即可创建,并会看到公私钥信息,"xxx"替换为你要创建的账号 20 | 21 | ## 免费获得Token 22 | 浏览器输入 23 | http://faucet.cryptokylin.io/get_token?xxxx 24 | "xxx"替换为你的账号 25 | 26 | # jungle测试网络 27 | jungle网络已停用,切到了Jungle2 28 | ## 创建免费账号 29 | https://monitor.jungletestnet.io/#account 30 | 31 | ## 免费获得Token 32 | 浏览器输入 33 | https://monitor.jungletestnet.io/#faucet 34 | 填入账号即可 35 | 36 | # FIBOS 37 | ## 无免费账号 38 | 39 | # bos-test测试网络 40 | ## 免费账号 41 | 创建免费账号: https://faucet-bos-testnet.keosd.io/create/. 42 | 43 | 例子: 44 | ``` 45 | curl https://faucet-bos-testnet.keosd.io/create/111111111ooo 46 | ``` 47 | 48 | ## 获得免费Token 49 | 获得免费Token: https://faucet-bos-testnet.keosd.io/get_token/. 50 | 51 | 每一次调用能获得100EOS, 每天最多获得1000个EOS. 52 | 53 | 例子: 54 | ``` 55 | curl https://faucet-bos-testnet.keosd.io/get_token/111111111ooo 56 | ``` 57 | -------------------------------------------------------------------------------- /docs/networks.md: -------------------------------------------------------------------------------- 1 | # 切换网络 2 | 可通过下面的命令来切换到不同网络 3 | ``` 4 | js4eos config set --network mainnet/kylin/jungle/enu/fibos 5 | ``` 6 | 7 | # 修改当前网络参数(比如chainid, httpend的url) 8 | 以下命令会更改当前网络的参数 9 | ``` 10 | js4eos config set --chainid=aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906 --url=http://bp.cryptolions.io:8888 11 | ``` 12 | # 切换网络,同时修改该网络的参数 13 | 下面命令就会切换到mainnnet网络并且修改该网络参数 14 | ``` 15 | js4eos config set --network mainnet --chainid=aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906 --url=http://bp.cryptolions.io:8888 16 | ``` 17 | # 同步网络信息 18 | 由于httpendpoint有时可能会失效,我们的服务器会不定时更新节点信息,所以本地需要时可以通过config sync来同步 19 | ``` 20 | js4eos config sync 21 | ``` 22 | # 选择节点 23 | 由于httpendpoint有时可能会失效,我们可以切换节点 24 | ``` 25 | $ js4eos config choose url 26 | Choose one httpEndpoint for mainnet: 27 | *[0] http://bp.cryptolions.io:8888 28 | [1] https://mainnet.genereos.io 29 | [2] https://mainnet.meet.one 30 | [3] http://mainnet.eoscalgary.io 31 | please input[0~3]> 32 | ``` 33 | # 选择网络 34 | 用户可能不了解网络的名字,可以通过列表选择方式切换网络 35 | ``` 36 | $ js4eos config choose network 37 | Choose one network: 38 | *[0] mainnet 39 | [1] localnet 40 | [2] eosforce 41 | [3] jungle 42 | [4] kylin 43 | [5] enu 44 | [6] fibos 45 | please input[0~6]> 46 | ``` -------------------------------------------------------------------------------- /files/config.json: -------------------------------------------------------------------------------- 1 | {"networks":{"mainnet":{"chainId":"aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906","httpEndpoint":"https://api.eosn.io","httpEndpoints":["https://bp.cryptolions.io","https://api.eosargentina.io","https://api.eossweden.org","https://api.eoseoul.io","https://api.main.alohaeos.com","https://api.eosn.io"],"keyPrefix":"EOS"},"localnet":{"chainId":"cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f","httpEndpoint":"http://127.0.0.1:8888","keyPrefix":"EOS"},"eosforce":{"chainId":"bd61ae3a031e8ef2f97ee3b0e62776d6d30d4833c8f7c1645c657b149151004b","httpEndpoint":"http://47.97.115.84:8888","keyPrefix":"EOS"},"jungle":{"chainId":"e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473","httpEndpoint":"http://jungle2.cryptolions.io:8888","httpEndpoints":["https://jungle2.cryptolions.io:443","http://jungle.eosgen.io:80","https://api.jungle.alohaeos.com:443","http://145.239.133.201:8888"],"keyPrefix":"EOS","faucet":{"type":"api","url":"http://api.eosfavor.com/faucetaccount"}},"kylin":{"chainId":"5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191","httpEndpoint":"http://kylin.meet.one:8888","httpEndpoints":["http://39.108.231.157:30065","http://api.kylin.eoseco.com","https://api-kylin.eoslaomao.com"],"keyPrefix":"EOS"},"enu":{"chainId":"5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191","httpEndpoint":"http://enu.mytokenpocket.vip","keyPrefix":"ENU"},"fibos":{"chainId":"6aa7bd33b6b45192465afa3553dedb531acaaff8928cf64b70bd4c5e49b7ec6a","httpEndpoint":"http://se-rpc.fibos.io:8870","keyPrefix":"FO"},"bos":{"chainId":"d5a3d18fbb3c084e3b1f3fa98c21014b5f3db536cc15d08f9f6479517c6a3d86","httpEndpoint":"http://api.bos.alohaeos.com","httpEndpoints":["http://api.bos.alohaeos.com","http://bosapi-one.eosstore.co:8888","http://bosapi-two.eosstore.co:8888"],"keyPrefix":"EOS"},"bostest":{"chainId":"33cc2426f1b258ef8c798c34c0360b31732ea27a2d7e35a65797850a86d1ba85","httpEndpoint":"http://bos-testnet.meet.one:8888","httpEndpoints":["http://bos-testnet.meet.one:8888","http://bos-testnet.mytokenpocket.vip:8890","https://bos-testnet.eosphere.io","https://bostest.api.blockgo.vip"],"keyPrefix":"EOS"}},"faucet":{"type":"web","url":"https://github.com/itleaks/js4eos/blob/master/docs/faucet.md"},"network":{"chainId":"aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906","httpEndpoint":"https://bp.cryptolions.io","keyPrefix":"EOS"},"currentNetwork":"mainnet","serviceUrl":"http://api.eosfavor.com","syncUrl":"https://raw.githubusercontent.com/itleaks/js4eos/master/files/config.json","appdemourl":"https://github.com/itleaks/js4eos-demo/archive/master.zip","appdemourl2":"https://github.com/itleaks/js4eos-demo/archive","keosd_provide_timeout":1800000,"inLibMode":false} -------------------------------------------------------------------------------- /files/weixin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itleaks/js4eos/c0c45c0a109920d835d52d0dadc25bb285ac333f/files/weixin.png -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const fs = require('fs') 3 | 4 | function actionCall(contract, action) { 5 | return async function() { 6 | var data = [] 7 | for (k in arguments) { 8 | data.push(arguments[k]) 9 | } 10 | return await Js4eos.pushRawAction(contract.account, action, JSON.stringify(data), contract.actor) 11 | } 12 | } 13 | 14 | function actorCall(contract) { 15 | return (actor) => { 16 | contract.actor = actor; 17 | } 18 | } 19 | 20 | function tableCall(contract) { 21 | return async(table, scope, table_key, lower_bound, upper_bound, limit, key_type, index_position) => { 22 | return await Js4eos.getTable(contract.account, scope, table, table_key, lower_bound, upper_bound, limit, key_type, index_position) 23 | } 24 | } 25 | 26 | async function requireContract(name, network) { 27 | var configFile = path.join(process.cwd(), "js4eos_config.js") 28 | if (!fs.existsSync(configFile)) { 29 | console.log("No config file js4eos_config.js") 30 | return; 31 | } 32 | let config = require(configFile) 33 | let contractDir = path.join("./contracts", name) 34 | let sourceAbi = path.join(contractDir, name + ".abi"); 35 | if (!fs.existsSync(sourceAbi)) { 36 | throw("contract abi file " + sourceAbi + " not exist, please deploy firstly") 37 | } 38 | 39 | var abi 40 | try { 41 | let data = fs.readFileSync(sourceAbi) 42 | // console.log(data.toString()) 43 | abi = JSON.parse(data.toString()); 44 | } catch(e) { 45 | console.log(e) 46 | return false; 47 | } 48 | 49 | if (!network) { 50 | network = process.env.JS4EOS_APP_NETWORK ? process.env.JS4EOS_APP_NETWORK : config.defaultNetwork 51 | } 52 | let contractAccount = config.deploy[name][network] 53 | var Contract = {account:contractAccount} 54 | Contract.setActor = actorCall(Contract) 55 | Contract.table = tableCall(Contract) 56 | for (let action of abi.actions) { 57 | Contract[action.name] = actionCall(Contract, action.name) 58 | } 59 | return Contract; 60 | } 61 | 62 | async function contract(account) { 63 | 64 | var ret = await Js4eos.getAbi(account) 65 | if (!ret || !ret.abi) { 66 | throw("Contract not found") 67 | } 68 | var abi = ret.abi; 69 | var Contract = {account} 70 | Contract.setActor = actorCall(Contract) 71 | Contract.table = tableCall(Contract) 72 | for (let action of abi.actions) { 73 | Contract[action.name] = actionCall(Contract, action.name) 74 | } 75 | return Contract; 76 | } 77 | 78 | function createJs4Eos(options) { 79 | if (!options) { 80 | throw("please set a js4eos app config") 81 | } 82 | var Config = require('./lib/config') 83 | Config.enterLibMode(true) 84 | Config.setNetwork(options.network) 85 | Config.setKeyProvider(options.keyProvider) 86 | var lib = require('./lib') 87 | lib.ResetEos(); 88 | lib.RequireContract = requireContract 89 | lib.Contract = contract 90 | return lib 91 | } 92 | 93 | function loadOptions() { 94 | try { 95 | var currentDir = process.cwd() 96 | var configFile = require('path').join(currentDir, "js4eos_config.js") 97 | if (!fs.existsSync(configFile)) { 98 | return null; 99 | } 100 | let config = require(configFile) 101 | var network = process.env.JS4EOS_APP_NETWORK ? process.env.JS4EOS_APP_NETWORK : config.defaultNetwork 102 | return { 103 | network:config.networks[network], 104 | keyProvider:config.keyProvider 105 | } 106 | } catch(e) { 107 | console.log(e) 108 | } 109 | return null; 110 | } 111 | 112 | Js4Eos = function Js4Eos(options) { 113 | let defaultOptions = loadOptions(); 114 | if (options && options.keyProvider && defaultOptions && defaultOptions.keyProvider instanceof Array) { 115 | options.keyProvider = defaultOptions.keyProvider.concat(options.keyProvider); 116 | } 117 | options = Object.assign(defaultOptions, options); 118 | // console.log(options) 119 | return createJs4Eos(options) 120 | } 121 | 122 | module.exports = Js4Eos 123 | -------------------------------------------------------------------------------- /js4eos: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | function startCmd() { 4 | const argv = require('yargs') 5 | .commandDir('cmds') 6 | .demandCommand() 7 | .help() 8 | .argv 9 | } 10 | try { 11 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; 12 | var daemon = require("daemonize2").setup({ 13 | main: "js4eos_bg", 14 | name: "js4eos_bg2", 15 | pidfile: require('path').join(require('os').homedir(), ".js4eos_bg2.pid"), 16 | }); 17 | var pid = daemon.status(); 18 | if (!pid) { 19 | // console.log("new start") 20 | daemon.start(); 21 | daemon.on('started', () => { 22 | startCmd(); 23 | }); 24 | daemon.on('error', () => { 25 | console.log("on error of js4eos_bg2") 26 | startCmd(); 27 | }); 28 | } else { 29 | startCmd(); 30 | } 31 | } catch(e) { 32 | console.log("start js4eos_bg2 error") 33 | startCmd(); 34 | } 35 | -------------------------------------------------------------------------------- /js4eos_bg: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var url = require('url'); 3 | var wallet = require('./lib/wallet2'); 4 | 5 | function echoJson(res, data) { 6 | console.log("response", data) 7 | res.writeHead(200, {'Content-Type': 'text/json'}); 8 | res.write(JSON.stringify({data})); 9 | res.end(); 10 | } 11 | 12 | async function processReq(req, res) { 13 | try { 14 | await processReqInner(req, res) 15 | } catch (e) { 16 | return echoJson(res, { 17 | error:e 18 | }) 19 | } 20 | } 21 | 22 | async function processReqInner(req, res) { 23 | let uri=url.parse(req.url); 24 | let page = url.parse(uri).path?url.parse(uri).path.match('^[^?]*')[0].split('/').slice(1)[0] : ''; 25 | var query = url.parse(req.url,true).query 26 | var ret = "" 27 | wallet.resetTime(); 28 | switch(page) { 29 | case "create": 30 | ret = await wallet.create("" + query.name, "" + query.passwd); 31 | return echoJson(res, ret) 32 | case "import": 33 | ret = await wallet.importKey(query.name, query.key) 34 | return echoJson(res, ret) 35 | case "keys": 36 | ret = await wallet.getPrivateKeysSync() 37 | return echoJson(res, ret) 38 | case "unlock": 39 | ret = await wallet.unlock(query.name, query.passwd) 40 | return echoJson(res, ret) 41 | case "lock": 42 | ret = await wallet.lock(query.name) 43 | return echoJson(res, ret) 44 | case "list": 45 | ret = await wallet.list() 46 | return echoJson(res, ret) 47 | case "delete": 48 | ret = await wallet.delete(query.name) 49 | return echoJson(res, ret) 50 | } 51 | return echoJson(res, "") 52 | } 53 | 54 | process.on('SIGHUP', function() { 55 | console.log('Got SIGHUP signal'); 56 | process.exit(0) 57 | }); 58 | 59 | http.createServer(function (req, res) { 60 | processReq(req, res) 61 | }).listen(6666, "127.0.0.1"); -------------------------------------------------------------------------------- /lib/api.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | var fs = require("fs"); 8 | var EosHelper = require('./eoshelper'); 9 | var path = require('path'); 10 | 11 | function getAsset(assetStr) { 12 | if (!assetStr) { 13 | return null 14 | } 15 | let tmps = assetStr.split(" ") 16 | return { 17 | amount:tmps[0], 18 | symbol:tmps.length > 1 ? tmps[1] : null 19 | } 20 | } 21 | 22 | exports.printJson = function (data) { 23 | if (data) { 24 | console.log(JSON.stringify(data, null, 4)) 25 | } 26 | } 27 | 28 | exports.printTransaction = function(tr) { 29 | if (!tr) { 30 | return; 31 | } 32 | if (!tr.transaction_id) { 33 | return this.printJson(tr) 34 | } 35 | // console.log(tr) 36 | let actions = [] 37 | for (let action_trace of tr.processed.action_traces) { 38 | actions.push(action_trace.act); 39 | for (let trace of action_trace.inline_traces) { 40 | actions.push(trace.act); 41 | } 42 | } 43 | // this.printJson(tr) 44 | console.log("executed transaction: " + tr.transaction_id, "block_humber:", tr.transaction.transaction.ref_block_num); 45 | console.log(tr.processed.receipt) 46 | for (let action of actions) { 47 | // console.log(action) 48 | console.log("# " + action.authorization[0].actor + " => " + action.account + "::" + action.name + " " + JSON.stringify(action.data)) 49 | } 50 | } 51 | 52 | exports.printTransactions = function(transactions) { 53 | console.log("# seq when actor => contract::action trx id... args"); 54 | console.log("================================================================================================================") 55 | for (let tr of transactions) { 56 | let action = tr.action_trace.act 57 | // console.log(action) 58 | console.log("# " + tr.account_action_seq, tr.block_time, " ", action.authorization[0].actor + " => " + action.account + "::" + action.name + " " + tr.action_trace.trx_id, JSON.stringify(action.data)) 59 | } 60 | } 61 | 62 | exports.okTransaction = function(tr) { 63 | if (!tr) { 64 | return false; 65 | } 66 | if (!tr.transaction_id) { 67 | return false 68 | } 69 | return true; 70 | } 71 | 72 | exports.getInfo = async function() { 73 | try { 74 | let ret = await EosHelper.EOS().getInfo({}); 75 | return ret; 76 | } catch (e) { 77 | console.log(e) 78 | } 79 | return null; 80 | } 81 | 82 | exports.getBlock = async function(height) { 83 | try { 84 | let ret = await EosHelper.EOS().getBlock(height); 85 | return ret; 86 | } catch (e) { 87 | console.log(e) 88 | } 89 | return null; 90 | } 91 | 92 | exports.getTransaction = async function(txHash, block_num_hint) { 93 | try { 94 | let ret = await EosHelper.EOS().getTransaction(txHash, block_num_hint); 95 | return ret; 96 | } catch (e) { 97 | console.log(e) 98 | } 99 | return null; 100 | } 101 | 102 | exports.getAccount = async function(account) { 103 | try { 104 | let ret = await EosHelper.EOS().getAccount("" + account); 105 | return ret; 106 | } catch (e) { 107 | console.log(e) 108 | } 109 | return null; 110 | } 111 | 112 | exports.getAbi = async function(contract_name) { 113 | try { 114 | let ret = await EosHelper.EOS().getAbi("" + contract_name); 115 | return ret; 116 | } catch (e) { 117 | 118 | } 119 | return null; 120 | } 121 | 122 | exports.getCurrencyBalance = async function(contract, account, symbol) { 123 | try { 124 | let ret = await EosHelper.EOS().getCurrencyBalance("" + contract, "" + account, symbol ? symbol : null) 125 | return ret; 126 | } catch (e) { 127 | console.log(e) 128 | } 129 | return null; 130 | } 131 | 132 | exports.getCurrencyStats = async function(contract, symbol) { 133 | try { 134 | let ret = await EosHelper.EOS().getCurrencyStats("" + contract, symbol) 135 | return ret; 136 | } catch (e) { 137 | console.log(e) 138 | } 139 | return null; 140 | } 141 | 142 | exports.getTable = async function(contract_name, scope, table, lower_bound, upper_bound, limit, key_type, index_position, table_key) { 143 | try { 144 | let ret = await EosHelper.EOS().getTableRows(true, "" + contract_name, scope, table, table_key, lower_bound, upper_bound, limit, key_type, index_position); 145 | return ret; 146 | } catch (e) { 147 | console.log(e) 148 | } 149 | return null; 150 | } 151 | 152 | exports.setContract = async function(account, dir) { 153 | let last = path.basename(dir); 154 | let wasm = fs.readFileSync(path.join(dir, last + ".wasm")); 155 | let abi = fs.readFileSync(path.join(dir, last + ".abi")); 156 | 157 | try { 158 | let ret = await EosHelper.EOS().setabi(account, JSON.parse(abi)); 159 | await EosHelper.EOS().setcode(account, 0, 0, wasm); 160 | return ret; 161 | } catch (e) { 162 | console.log(e) 163 | } 164 | return null; 165 | } 166 | 167 | exports.setAbi = async function(account, abifile) { 168 | let abi = fs.readFileSync(abifile); 169 | 170 | try { 171 | let ret = await EosHelper.EOS().setabi(account, JSON.parse(abi)); 172 | return ret; 173 | } catch (e) { 174 | console.log(e) 175 | } 176 | return null; 177 | } 178 | 179 | exports.setCode = async function(account, wasmfile) { 180 | let wasm = fs.readFileSync(wasmfile); 181 | 182 | try { 183 | let ret = await EosHelper.EOS().setcode(account, 0, 0, wasm); 184 | return ret; 185 | } catch (e) { 186 | console.log(e) 187 | } 188 | return null; 189 | } 190 | 191 | async function getNewPermissions(accountName) { 192 | const account = await EosHelper.EOS().getAccount(accountName) 193 | const perms = JSON.parse(JSON.stringify(account.permissions)) 194 | console.log(perms) 195 | return perms 196 | } 197 | 198 | exports.setPermission = async function(accountName, permission, authority, parent) { 199 | // console.log(accountName, permission, authority, parent) 200 | let ret = await EosHelper.EOS().transaction(tr => { 201 | tr.updateauth({ 202 | account: accountName, 203 | permission: permission, 204 | parent: parent, 205 | auth: JSON.parse(authority) 206 | }) 207 | }) 208 | return ret; 209 | } 210 | 211 | exports.pushAction = async function(contract_name, action, data, actor, permission) { 212 | try { 213 | let tr = await EosHelper.EOS().transaction( 214 | { 215 | actions: [ 216 | { 217 | account: "" + contract_name, 218 | name: action, 219 | authorization: [{ 220 | actor: "" + actor, 221 | permission: permission 222 | }], 223 | data, 224 | } 225 | ] 226 | } 227 | ) 228 | return tr; 229 | } catch(e) { 230 | console.log(e) 231 | } 232 | return null 233 | } 234 | 235 | function parseActor(actorStr) { 236 | if (!actorStr) { 237 | return 238 | } 239 | let tmps = actorStr.split('@') 240 | return { 241 | actor:tmps[0], 242 | permission:tmps.length > 1 ? tmps[1] : 'active' 243 | } 244 | } 245 | 246 | exports.pushRawAction = async function(contractName, actionName, dataStr, actorStr) { 247 | // console.log(dataStr, actorStr) 248 | let ret = await this.getAbi(contractName) 249 | if (!ret || !ret.abi) { 250 | console.log("invalid contract") 251 | return; 252 | } 253 | let abi = ret.abi 254 | let actionType = null; 255 | for (let action of abi.actions) { 256 | if (action.name == actionName) { 257 | actionType = action.type 258 | break 259 | } 260 | } 261 | if (!actionType) { 262 | console.log("action", actionName, "not found") 263 | return; 264 | } 265 | 266 | let fields = null; 267 | for (let struct of abi.structs) { 268 | if (struct.name == actionType) { 269 | fields = struct.fields; 270 | break; 271 | } 272 | } 273 | 274 | let dataInfo 275 | try { 276 | dataInfo = JSON.parse(dataStr) 277 | } catch(e) { 278 | console.log("Invalid action data", dataStr) 279 | return; 280 | } 281 | let data = {} 282 | for(let i=0; i 376 | { 377 | eos.buyram({ 378 | payer: payer, 379 | receiver: receiver, 380 | quant: ramEos, 381 | }) 382 | } 383 | ) 384 | return tr; 385 | } catch (e) { 386 | console.log("fail", e) 387 | } 388 | } 389 | 390 | exports.sellRam = async function(account, ramBytes) { 391 | try { 392 | let tr = await EosHelper.EOS().transaction(eos => 393 | { 394 | eos.sellram({ 395 | account, 396 | bytes: ramBytes 397 | }) 398 | } 399 | ) 400 | return tr; 401 | } catch (e) { 402 | console.log("fail", e) 403 | } 404 | } 405 | 406 | exports.newAccount = async function(creator, name, ownerkey, activeKey, stake_net_quantity, stake_cpu_quantity, ramEos, ramBytes, transfer) { 407 | try { 408 | let tr = await EosHelper.EOS().transaction(eos => 409 | { 410 | eos.newaccount({ 411 | creator: creator, 412 | name: name, 413 | owner: ownerkey, 414 | active: activeKey 415 | }) 416 | if (ramEos) { 417 | eos.buyram({ 418 | payer: creator, 419 | receiver: name, 420 | quantity: ramEos, 421 | }) 422 | } else if (ramBytes) { 423 | eos.buyrambytes({ 424 | payer: creator, 425 | receiver: name, 426 | bytes: ramBytes 427 | }) 428 | } 429 | if (stake_net_quantity && stake_cpu_quantity) { 430 | let netAsset = getAsset(stake_net_quantity) 431 | if (!netAsset || !netAsset.symbol) { 432 | console.log("Invalid net asset") 433 | return; 434 | } 435 | let cpuAsset = getAsset(stake_cpu_quantity) 436 | if (!cpuAsset || !cpuAsset.symbol) { 437 | console.log("Invalid cpu asset") 438 | return; 439 | } 440 | if (netAsset.amount > 0 || cpuAsset.amount > 0) { 441 | eos.delegatebw({ 442 | from: creator, 443 | receiver: name, 444 | stake_net_quantity, 445 | stake_cpu_quantity, 446 | transfer 447 | }) 448 | } 449 | } 450 | } 451 | ) 452 | return tr; 453 | } catch (e) { 454 | console.log("fail", e) 455 | } 456 | return null 457 | } 458 | 459 | exports.createAccount = async function(creator, name, ownerkey, activeKey) { 460 | // console.log(creator, name ,ownerkey,activeKey) 461 | try { 462 | let tr = await EosHelper.EOS().transaction(eos => 463 | { 464 | eos.newaccount({ 465 | creator: creator, 466 | name: name, 467 | owner: ownerkey, 468 | active: activeKey 469 | }) 470 | } 471 | ) 472 | return tr; 473 | } catch (e) { 474 | console.log("fail", e) 475 | } 476 | return null 477 | } 478 | -------------------------------------------------------------------------------- /lib/compile.js: -------------------------------------------------------------------------------- 1 | var request = require('request'); 2 | var path = require('path'); 3 | var fs = require('fs'); 4 | var Config = require('./config').getConfig() 5 | var Utils = require("./utils") 6 | var commandExists = require('command-exists') 7 | var exec = require("child_process").exec 8 | 9 | function execAsync(cmd) { 10 | return new Promise((resolve, reject) => { 11 | try { 12 | let tmp = exec(cmd, function(err, stdout, stderr) { 13 | resolve(true); 14 | }) 15 | tmp.stdout.pipe(process.stdout); 16 | tmp.stderr.pipe(process.stderr); 17 | } catch(e) { 18 | reject(e) 19 | } 20 | }); 21 | } 22 | 23 | function compileInner(file, targetFile, args) { 24 | return new Promise(function(resolve, reject) { 25 | // console.log(args) 26 | var req = request.post(Config.serviceUrl + "/newcompile", function (err, response, data) { 27 | try { 28 | data = JSON.parse(data); 29 | } catch(e) { 30 | console.log("fail due to network or error, please check network and try again") 31 | console.log(e) 32 | return; 33 | } 34 | if (data.file) { 35 | Utils.downloadFile(Config.serviceUrl + "/" + data.file, targetFile).then(() => { 36 | data.file = targetFile; 37 | resolve(data); 38 | }) 39 | } 40 | }); 41 | try { 42 | var form = req.form(); 43 | for (let key in args) { 44 | form.append(key, args[key]) 45 | } 46 | form.append('file', fs.createReadStream(file), { 47 | filename: path.basename(file), 48 | contentType: 'text/plain' 49 | }); 50 | } catch(e) { 51 | console.log(e) 52 | } 53 | }); 54 | } 55 | 56 | async function tryLocalCompile(file, targetFile, args) { 57 | var localCompile = false 58 | 59 | if (args.flag == 'o' || args.flag == 'g') { 60 | try { 61 | await commandExists('eosiocpp') 62 | localCompile = true; 63 | } catch (e) { 64 | } 65 | if (!localCompile) { 66 | return false; 67 | } 68 | let cmd; 69 | if (args.flag == 'o') { 70 | cmd = 'eosiocpp -o ' + targetFile + ' ' + file 71 | } else { 72 | cmd = 'eosiocpp -g ' + targetFile + ' ' + file 73 | } 74 | try { 75 | await execAsync(cmd) 76 | } catch(e) { 77 | console.log(e) 78 | } 79 | return true; 80 | } else if (args.flag == 'g2' || args.flag == 'o2') { 81 | try { 82 | await commandExists('eosio-cpp') 83 | localCompile = true; 84 | } catch (e) { 85 | } 86 | if (!localCompile) { 87 | return false; 88 | } 89 | let cmd; 90 | if (args.flag == 'o2') { 91 | cmd = 'eosio-cpp -o ' + targetFile + ' ' + file 92 | } else { 93 | cmd = 'eosio-abigen --output ' + targetFile + ' ' + file + ' --contract ' + args.contract 94 | } 95 | try { 96 | await execAsync(cmd) 97 | } catch(e) { 98 | console.log(e) 99 | } 100 | return true; 101 | } 102 | return false; 103 | } 104 | 105 | exports.compile = async function(file, targetFile, args) { 106 | if (!fs.existsSync(file)) { 107 | console.log(file, " not found") 108 | return; 109 | } 110 | let codeDir = require('path').dirname(file) 111 | let fileName = require('path').basename(file) 112 | let pos = fileName.lastIndexOf(".") 113 | let realFileName = fileName.slice(0, pos) 114 | let ext = ''; 115 | if (pos >= 0) { 116 | ext = fileName.slice(pos+1) 117 | } 118 | if (ext != 'cpp') { 119 | return { 120 | stderr:'must be a cpp file' 121 | } 122 | } 123 | let local = await tryLocalCompile(file, targetFile, args); 124 | if (local) { 125 | return; 126 | } 127 | let zipFile = require('os').tmpdir() + "/" + realFileName + ".zip" 128 | await Utils.archiveCode(codeDir, zipFile) 129 | let ret = await compileInner(zipFile, targetFile, args); 130 | return ret; 131 | } -------------------------------------------------------------------------------- /lib/config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | const Request = require('./request') 7 | var fs = require('fs'); 8 | var config = {} 9 | defaultConfig = { 10 | networks:{ 11 | mainnet: { 12 | chainId:'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906', 13 | httpEndpoint:'http://eos.greymass.com', 14 | httpEndpoints:[ 15 | 'http://eos.greymass.com', 16 | ], 17 | keyPrefix:'EOS', 18 | }, 19 | localnet: { 20 | chainId:'cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f', 21 | httpEndpoint:'http://127.0.0.1:8888', 22 | keyPrefix:'EOS', 23 | }, 24 | eosforce: { 25 | chainId:'bd61ae3a031e8ef2f97ee3b0e62776d6d30d4833c8f7c1645c657b149151004b', 26 | httpEndpoint:'http://47.97.115.84:8888', 27 | keyPrefix:'EOS', 28 | }, 29 | jungle: { 30 | chainId:'e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473', 31 | httpEndpoint:'http://jungle2.cryptolions.io:8888', 32 | httpEndpoints:[ 33 | 'https://jungle2.cryptolions.io:443', 34 | 'http://jungle.eosgen.io:80', 35 | 'https://api.jungle.alohaeos.com:443', 36 | 'http://145.239.133.201:8888', 37 | ], 38 | keyPrefix:'EOS', 39 | faucet: { 40 | type:"api", 41 | url:"http://api.eosfavor.com/faucetaccount", 42 | } 43 | }, 44 | kylin: { 45 | chainId:'5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191', 46 | httpEndpoint:'http://kylin.meet.one:8888', 47 | httpEndpoints: [ 48 | 'http://39.108.231.157:30065', 49 | 'http://api.kylin.eoseco.com', 50 | 'https://api-kylin.eoslaomao.com', 51 | ], 52 | keyPrefix:'EOS', 53 | }, 54 | enu: { 55 | chainId:'5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191', 56 | httpEndpoint:'http://enu.mytokenpocket.vip', 57 | keyPrefix:'ENU', 58 | }, 59 | fibos: { 60 | chainId:'6aa7bd33b6b45192465afa3553dedb531acaaff8928cf64b70bd4c5e49b7ec6a', 61 | httpEndpoint:'http://se-rpc.fibos.io:8870', 62 | keyPrefix:'FO', 63 | }, 64 | bos: { 65 | chainId:'d5a3d18fbb3c084e3b1f3fa98c21014b5f3db536cc15d08f9f6479517c6a3d86', 66 | httpEndpoint:'http://api.bos.alohaeos.com', 67 | httpEndpoints: [ 68 | 'http://api.bos.alohaeos.com', 69 | 'http://bosapi-one.eosstore.co:8888', 70 | 'http://bosapi-two.eosstore.co:8888', 71 | ], 72 | keyPrefix:'EOS', 73 | }, 74 | bostest: { 75 | chainId:'33cc2426f1b258ef8c798c34c0360b31732ea27a2d7e35a65797850a86d1ba85', 76 | httpEndpoint:'http://bos-testnet.meet.one:8888', 77 | httpEndpoints: [ 78 | 'http://bos-testnet.meet.one:8888', 79 | 'http://bos-testnet.mytokenpocket.vip:8890', 80 | 'https://bos-testnet.eosphere.io', 81 | 'https://bostest.api.blockgo.vip', 82 | ], 83 | keyPrefix:'EOS', 84 | }, 85 | meetone: { 86 | chainId:'cfe6486a83bad4962f232d48003b1824ab5665c36778141034d75e57b956e422', 87 | httpEndpoint:'https://fullnode.meet.one', 88 | httpEndpoints: [ 89 | 'https://api.meetone.eostribe.io', 90 | 'https://meetseed.ikuwara.com:8889', 91 | 'https://api.meetone.alohaeos.com', 92 | 'https://meetone.eossweden.eu', 93 | ], 94 | keyPrefix:'EOS', 95 | }, 96 | }, 97 | faucet:{ 98 | type:'web', 99 | url:'https://github.com/itleaks/js4eos/blob/master/docs/faucet.md' 100 | }, 101 | network:{}, 102 | currentNetwork:'mainnet', 103 | serviceUrl:'http://api.eosfavor.com', 104 | syncUrl:'https://raw.githubusercontent.com/itleaks/js4eos/master/files/config.json', 105 | dataDir:require('path').join(require('os').homedir(), ".js4eos"), 106 | appdemourl:'https://github.com/itleaks/js4eos-demo/archive/master.zip', 107 | appdemourl2:'https://github.com/itleaks/js4eos-demo/archive', 108 | keosd_provide_timeout:30*60*1000, //30min 109 | inLibMode:false, 110 | } 111 | 112 | if (process.env.JS4EOS_DATADIR) { 113 | defaultConfig.dataDir = require('path').join(process.env.JS4EOS_DATADIR, ".js4eos") 114 | } 115 | if (!fs.existsSync(defaultConfig.dataDir)) { 116 | try { 117 | fs.mkdirSync(defaultConfig.dataDir,'0777', true) 118 | } catch(e) { 119 | console.log(e) 120 | } 121 | } 122 | 123 | var configFile = require('path').join(defaultConfig.dataDir, "config.json"); 124 | function loadConfig() { 125 | let config = {} 126 | var applyingConfig = configFile 127 | if (!fs.existsSync(applyingConfig)) { 128 | var applyingConfig = require('path').join(__dirname + "/../files", "config.json"); 129 | if (!fs.existsSync(applyingConfig)) { 130 | console.log("use built-in config") 131 | return config 132 | } 133 | console.log("use default config") 134 | } 135 | try { 136 | let data = fs.readFileSync(applyingConfig); 137 | config = JSON.parse(data); 138 | } catch(e) { 139 | console.log(e) 140 | } 141 | return config; 142 | } 143 | 144 | exports.enterLibMode = function(value) { 145 | config.inLibMode = value; 146 | updateNetwork() 147 | } 148 | 149 | exports.resetConfig = async function() { 150 | if (config.inLibMode) { 151 | config = defaultConfig 152 | return config 153 | } 154 | if (!fs.existsSync(configFile)) { 155 | return config 156 | } 157 | try { 158 | fs.unlinkSync(configFile); 159 | } catch(e) { 160 | console.log("reset fail") 161 | } 162 | config = defaultConfig 163 | updateNetwork() 164 | return config 165 | } 166 | 167 | exports.saveConfig = function(newConfig) { 168 | if (config.inLibMode) { 169 | console.log("Not Support on lib mode") 170 | return; 171 | } 172 | if (config['dataDir'] != undefined) { 173 | delete config['dataDir'] 174 | } 175 | let data = JSON.stringify(newConfig); 176 | try { 177 | fs.writeFileSync(configFile, data); 178 | } catch(e) { 179 | console.log(e) 180 | } 181 | config = newConfig 182 | updateNetwork() 183 | } 184 | 185 | exports.getConfig = function() { 186 | return config; 187 | } 188 | 189 | function setNetwork(network) { 190 | // let current = config.networks[config.currentNetwork]; 191 | config.network.chainId = network.chainId 192 | config.network.httpEndpoint = network.httpEndpoint 193 | config.network.keyPrefix = network.keyPrefix 194 | } 195 | 196 | exports.setNetwork = setNetwork 197 | 198 | function updateNetwork() { 199 | setNetwork(config.networks[config.currentNetwork]); 200 | } 201 | 202 | exports.getNetwork = function() { 203 | return config.network; 204 | } 205 | 206 | exports.setKeyProvider = function(keyProvider) { 207 | config.keyProvider = keyProvider 208 | } 209 | 210 | exports.syncConfig = async function() { 211 | if (config.inLibMode) { 212 | console.log("Not Support on lib mode") 213 | return; 214 | } 215 | try { 216 | let res = await Request.get(config.syncUrl); 217 | config = JSON.parse(res) 218 | return config; 219 | } catch(e) { 220 | return null; 221 | } 222 | } 223 | 224 | var userConfig = loadConfig(); 225 | if (userConfig['dataDir'] != undefined) { 226 | delete userConfig['dataDir'] 227 | } 228 | config = {...defaultConfig, ...userConfig} 229 | updateNetwork() 230 | -------------------------------------------------------------------------------- /lib/crypto.js: -------------------------------------------------------------------------------- 1 | var crypto = require('crypto'); 2 | 3 | //加密 4 | exports.encrypt = function(algorithm, key, buf) { 5 | var encrypted = ""; 6 | var cip = crypto.createCipher(algorithm, key); 7 | encrypted += cip.update(buf, 'binary', 'hex'); 8 | encrypted += cip.final('hex'); 9 | return encrypted 10 | }; 11 | 12 | //解密 13 | exports.decrypt = function(algorithm, key, encrypted) { 14 | var decrypted = ""; 15 | var decipher = crypto.createDecipher(algorithm, key); 16 | decrypted += decipher.update(encrypted, 'hex', 'binary'); 17 | decrypted += decipher.final('binary'); 18 | return decrypted 19 | }; 20 | 21 | exports.randomPasswd = async function() { 22 | let data = await crypto.randomBytes(16); 23 | return data.toString('hex'); 24 | } -------------------------------------------------------------------------------- /lib/eoshelper.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | var Network = require('./config').getNetwork(); 8 | var Config = require('./config').getConfig(); 9 | var Eosjs = require('./eosjs').eosjs; 10 | 11 | var Wallet = require('./wallet'); 12 | 13 | // Private key or keys (array) provided statically or by way of a function. 14 | // For multiple keys, the get_required_keys API is used (more on that below). 15 | async function getKeyProvider() { 16 | if (Config.inLibMode) { 17 | return Config.keyProvider 18 | } else { 19 | return await Wallet.getPrivateKeys(); 20 | } 21 | } 22 | var instance = {}; 23 | 24 | exports.ResetEos = () => { 25 | instance.eos = Eosjs({ 26 | httpEndpoint:Network.httpEndpoint, 27 | chainId:Network.chainId, 28 | keyProvider:() => getKeyProvider(), 29 | expireInSeconds: 60, 30 | broadcast: true, 31 | verbose: false, 32 | sign: true 33 | }) 34 | } 35 | 36 | exports.EOS = () => { 37 | return instance.eos 38 | } 39 | 40 | this.ResetEos() -------------------------------------------------------------------------------- /lib/eosjs.js: -------------------------------------------------------------------------------- 1 | var patch_api = require('./patch_api') 2 | // var eosjs = patch_api(require('eosjs')) 3 | 4 | var eosjs = require('eosjs') 5 | 6 | exports.eosjs = eosjs -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | var Config = require('./config') 2 | var EosHelper = require('./eoshelper') 3 | var Wallet = require('./wallet') 4 | var Api = require('./api') 5 | var Compile = require('./compile') 6 | var Utils = require('./utils') 7 | module.exports = { 8 | ...EosHelper, ...EosHelper.EOS(), ...Api, ...Wallet, ...Config, ...Compile, ...Utils 9 | } -------------------------------------------------------------------------------- /lib/patch_api.js: -------------------------------------------------------------------------------- 1 | var Network = require("./config").getNetwork() 2 | var Patches = require("./patches") 3 | module.exports = function(eosjs) 4 | { 5 | Object.assign(eosjs.modules.json.schema, { 6 | //TODO:Add new API here for some special EOS eco 7 | }); 8 | 9 | var ecc = eosjs.modules.ecc; 10 | 11 | function patchPubKey(pub_key) { 12 | let toString = pub_key.toString; 13 | pub_key.toString = (pubkey_prefix = Network.keyPrefix) => { 14 | var str = toString(pubkey_prefix); 15 | if (str === Network.keyPrefix + '859gxfnXyUriMgUeThh1fWv3oqcpLFyHa3TfFYC4PK2HqhToVM') 16 | return 'EOS859gxfnXyUriMgUeThh1fWv3oqcpLFyHa3TfFYC4PK2HqhToVM'; 17 | return str; 18 | } 19 | 20 | return pub_key; 21 | } 22 | 23 | var privateToPublic = ecc.privateToPublic; 24 | ecc.privateToPublic = function (wif, pubkey_prefix = Network.keyPrefix) { 25 | return privateToPublic(wif, pubkey_prefix); 26 | } 27 | 28 | var PubKey = ecc.PublicKey; 29 | ecc.PublicKey = Q => { 30 | return patchPubKey(PubKey(Q)); 31 | } 32 | 33 | var fromPoint = PubKey.fromPoint; 34 | PubKey.fromPoint = function (Q) { 35 | return patchPubKey(fromPoint(Q)); 36 | }; 37 | 38 | var fromBuffer = PubKey.fromBuffer; 39 | PubKey.fromBuffer = function (buffer) { 40 | return patchPubKey(fromBuffer(buffer)); 41 | }; 42 | 43 | var fromString = PubKey.fromString; 44 | PubKey.fromString = function (public_key, pubkey_prefix = Network.keyPrefix) { 45 | return fromString(public_key, pubkey_prefix); 46 | } 47 | 48 | var fromStringOrThrow = PubKey.fromStringOrThrow; 49 | PubKey.fromStringOrThrow = function (public_key, pubkey_prefix = Network.keyPrefix) { 50 | if (public_key === 'EOS859gxfnXyUriMgUeThh1fWv3oqcpLFyHa3TfFYC4PK2HqhToVM') 51 | public_key = Network.keyPrefix + '859gxfnXyUriMgUeThh1fWv3oqcpLFyHa3TfFYC4PK2HqhToVM'; 52 | // Should not call console.log here 53 | // or throw TypeError: A name can be up to 12 characters long 54 | let ret = fromStringOrThrow(public_key, pubkey_prefix); 55 | return ret 56 | }; 57 | let patchFunc = Patches[Network.keyPrefix] 58 | if (patchFunc) { 59 | eosjs = patchFunc(eosjs) 60 | } 61 | return eosjs; 62 | }; -------------------------------------------------------------------------------- /lib/patches.js: -------------------------------------------------------------------------------- 1 | function fibos(eosjs) 2 | { 3 | Object.assign(eosjs.modules.json.schema, { 4 | retire: { 5 | "base": "", 6 | "action": { 7 | "name": "retire", 8 | "account": "eosio.token" 9 | }, 10 | "fields": { 11 | "quantity": "asset", 12 | "memo": "string" 13 | } 14 | }, 15 | close: { 16 | "base": "", 17 | "action": { 18 | "name": "close", 19 | "account": "eosio.token" 20 | }, 21 | "fields": { 22 | "owner": "account_name", 23 | "symbol": "symbol" 24 | } 25 | }, 26 | excreate: { 27 | "base": "", 28 | "action": { 29 | "name": "excreate", 30 | "account": "eosio.token" 31 | }, 32 | "fields": { 33 | "issuer": "account_name", 34 | "maximum_supply": "asset", 35 | "connector_weight": "float64", 36 | "maximum_exchange": "asset", 37 | "reserve_supply": "asset", 38 | "reserve_connector_balance": "asset" 39 | } 40 | }, 41 | exunlock: { 42 | "base": "", 43 | "action": { 44 | "name": "exunlock", 45 | "account": "eosio.token" 46 | }, 47 | "fields": { 48 | "owner": "account_name", 49 | "quantity": "extended_asset", 50 | "expiration": "time_point_sec", 51 | "memo": "string" 52 | } 53 | }, 54 | exlocktrans: { 55 | "base": "", 56 | "action": { 57 | "name": "exlocktrans", 58 | "account": "eosio.token" 59 | }, 60 | "fields": { 61 | "from": "account_name", 62 | "to": "account_name", 63 | "quantity": "extended_asset", 64 | "expiration": "time_point_sec", 65 | "memo": "string" 66 | } 67 | }, 68 | exissue: { 69 | "base": "", 70 | "action": { 71 | "name": "exissue", 72 | "account": "eosio.token" 73 | }, 74 | "fields": { 75 | "to": "account_name", 76 | "quantity": "extended_asset", 77 | "memo": "string" 78 | } 79 | }, 80 | extransfer: { 81 | "base": "", 82 | "action": { 83 | "name": "extransfer", 84 | "account": "eosio.token" 85 | }, 86 | "fields": { 87 | "from": "account_name", 88 | "to": "account_name", 89 | "quantity": "extended_asset", 90 | "memo": "string" 91 | } 92 | }, 93 | exretire: { 94 | "base": "", 95 | "action": { 96 | "name": "exretire", 97 | "account": "eosio.token" 98 | }, 99 | "fields": { 100 | "from": "account_name", 101 | "quantity": "extended_asset", 102 | "memo": "string" 103 | } 104 | }, 105 | exclose: { 106 | "base": "", 107 | "action": { 108 | "name": "exclose", 109 | "account": "eosio.token" 110 | }, 111 | "fields": { 112 | "owner": "account_name", 113 | "symbol": "extended_symbol" 114 | } 115 | }, 116 | exdestroy: { 117 | "base": "", 118 | "action": { 119 | "name": "exdestroy", 120 | "account": "eosio.token" 121 | }, 122 | "fields": { 123 | "symbol": "extended_symbol" 124 | } 125 | }, 126 | exchange: { 127 | "base": "", 128 | "action": { 129 | "name": "exchange", 130 | "account": "eosio.token" 131 | }, 132 | "fields": { 133 | "owner": "account_name", 134 | "quantity": "asset", 135 | "tosym": "symbol", 136 | "memo": "string" 137 | } 138 | }, 139 | ctxrecharge: { 140 | "base": "", 141 | "action": { 142 | "name": "ctxrecharge", 143 | "account": "eosio.token" 144 | }, 145 | "fields": { 146 | "owner": "account_name", 147 | "quantity": "extended_asset", 148 | "memo": "string" 149 | } 150 | }, 151 | ctxextract: { 152 | "base": "", 153 | "action": { 154 | "name": "ctxextract", 155 | "account": "eosio.token" 156 | }, 157 | "fields": { 158 | "owner": "account_name", 159 | "quantity": "extended_asset", 160 | "memo": "string" 161 | } 162 | }, 163 | ctxtransfer: { 164 | "base": "", 165 | "action": { 166 | "name": "ctxtransfer", 167 | "account": "eosio.token" 168 | }, 169 | "fields": { 170 | "from": "account_name", 171 | "to": "account_name", 172 | "quantity": "extended_asset", 173 | "memo": "string" 174 | } 175 | }, 176 | }); 177 | return eosjs; 178 | }; 179 | 180 | module.exports={ 181 | FO:fibos, 182 | } -------------------------------------------------------------------------------- /lib/request.js: -------------------------------------------------------------------------------- 1 | var qs = require('query-string'); 2 | var request = require('request'); 3 | 4 | var __DEV__ = false; 5 | 6 | function filterJSON(res) { 7 | return res.json(); 8 | } 9 | 10 | function filterStatus(res) { 11 | if (__DEV__) { 12 | console.info(res); 13 | } 14 | if (res.status >= 200 && res.status < 300) { 15 | return res 16 | } 17 | else { 18 | let error = new Error(res.statusText); 19 | error.res = res; 20 | error.type = 'http'; 21 | throw error; 22 | } 23 | } 24 | 25 | exports.get = function(url, params, options = {}, callback) { 26 | return new Promise(function (resolve, reject) { 27 | 28 | const {metaType = 'json'} = options; 29 | let headers = { 30 | 'Accept': 'application/json' 31 | }; 32 | 33 | if (metaType == 'json') { 34 | headers = { 35 | ...headers, 36 | 'Content-Type': 'application/json' 37 | } 38 | } 39 | 40 | if (params) { 41 | url += `?${qs.stringify(params)}`; 42 | } 43 | 44 | if (__DEV__) { 45 | console.info(`GET: ${url}`); 46 | } 47 | request.get(url, function (error, response, data) { 48 | //console.log("result", data); 49 | if (data) { 50 | resolve(data); 51 | } else { 52 | reject(data); 53 | } 54 | }); 55 | }); 56 | } 57 | 58 | exports.post = function(url, body, options = {}) { 59 | return new Promise(function (resolve, reject) { 60 | const {metaType = 'json'} = options; 61 | let headers = { 62 | 'Accept': 'application/json' 63 | }; 64 | 65 | let form = JSON.stringify(body); 66 | 67 | if (metaType == 'json') { 68 | headers = { 69 | ...headers, 70 | 'Content-Type': 'application/json' 71 | } 72 | } 73 | 74 | if (metaType == 'form') { 75 | form = qs.stringify(body); 76 | headers = { 77 | ...headers, 78 | 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' 79 | } 80 | } 81 | 82 | if (__DEV__) { 83 | console.info(`POST: ${url}`); 84 | console.info(`body:`, body) 85 | } 86 | 87 | request.post({ 88 | url: url, 89 | method: "POST", 90 | json: false, 91 | headers, 92 | body: form, 93 | }, function (error, response, data) { 94 | //console.log("result", data); 95 | if (data) { 96 | resolve(data); 97 | } else { 98 | reject(data); 99 | } 100 | }); 101 | }); 102 | } 103 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | var request = require('request'); 2 | var fs = require('fs') 3 | var archiver = require('archiver') 4 | 5 | exports.downloadFile = function(uri, filename){ 6 | return new Promise(function(resolve, reject) { 7 | var stream = fs.createWriteStream(filename); 8 | request(uri).pipe(stream).on('close', (data)=>{ 9 | resolve(data) 10 | }); 11 | }) 12 | } 13 | 14 | exports.readDirFilesSync = function (path){ 15 | let root = fs.readdirSync(path); 16 | let files = []; 17 | root.forEach(function(elem, index){ 18 | var info = fs.statSync(path + "/" + elem) 19 | if(!info.isDirectory()){ 20 | files.push(elem) 21 | } 22 | }) 23 | return files; 24 | } 25 | 26 | exports.archiveCode = function (sourcePath, dstFile) { 27 | return new Promise(function(resolve, reject) { 28 | // console.log(sourcePath, dstFile) 29 | var fileOutput = fs.createWriteStream(dstFile); 30 | var archive = archiver('zip', { 31 | zlib: { level: 9 } // Sets the compression level. 32 | }); 33 | fileOutput.on('close', function () { 34 | // console.log(archive.pointer() + ' total bytes'); 35 | if (archive.pointer() > 1024*1000) { 36 | reject("contract's size is too big and larger than 1M") 37 | } 38 | // console.log('archiver has been finalized and the output file descriptor has closed.'); 39 | resolve(archive.pointer()) 40 | // fs.unlinkSync(dstFile); 41 | }); 42 | 43 | archive.pipe(fileOutput); 44 | archive.glob("*.cpp", { cwd: sourcePath }, { prefix: ''}); //include cpp files 45 | archive.glob("*.hpp", { cwd: sourcePath }, { prefix: ''}); //include hpp files 46 | archive.on('error', function(err){ 47 | reject(err) 48 | }); 49 | archive.finalize(); 50 | }) 51 | } -------------------------------------------------------------------------------- /lib/wallet.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | var Config = require('./config').getConfig() 8 | const fs = require('fs') 9 | const Request = require('./request') 10 | var crypto = require('./crypto') 11 | 12 | var Eosjs = require('./eosjs').eosjs; 13 | const ecc = Eosjs.modules.ecc 14 | 15 | var keys = [] 16 | 17 | const PORT = '6666' 18 | 19 | exports.createKey = async function() { 20 | let privateKey = await ecc.randomKey(); 21 | let publicKey = ecc.privateToPublic(privateKey); 22 | return { 23 | privateKey, 24 | publicKey 25 | } 26 | } 27 | 28 | exports.privateToPublic = async function(privateKey) { 29 | let publicKey = ecc.privateToPublic(privateKey); 30 | return publicKey 31 | } 32 | 33 | exports.loadKeys = async function() { 34 | if (!Config.inLibMode) { 35 | //Load key from remote 36 | let res = await Request.get('http://localhost:' + PORT + '/keys'); 37 | // console.log(res) 38 | keys = JSON.parse(res).data 39 | return; 40 | } 41 | } 42 | 43 | exports.createWallet = async function(wallet) { 44 | if (!Config.inLibMode) { 45 | //Load key from remote 46 | let passwd = await crypto.randomPasswd(); 47 | let res = await Request.get('http://localhost:' + PORT + '/create?passwd='+passwd + "&name=" + wallet); 48 | res = JSON.parse(res).data 49 | if (!res) { 50 | console.log("wallet password:") 51 | console.log(passwd) 52 | } 53 | return res; 54 | } 55 | } 56 | 57 | exports.lockWallet = async function(wallet) { 58 | if (!Config.inLibMode) { 59 | //Load key from remote 60 | let res = await Request.get('http://localhost:' + PORT + '/lock?name=' + wallet); 61 | res = JSON.parse(res).data 62 | this.loadKeys(); 63 | return res; 64 | } 65 | } 66 | 67 | 68 | exports.unlockWallet = async function(wallet, passwd) { 69 | if (!Config.inLibMode) { 70 | //Load key from remote 71 | let res = await Request.get('http://localhost:' + PORT + '/unlock?passwd='+passwd + "&name=" + wallet); 72 | this.loadKeys(); 73 | res = JSON.parse(res).data 74 | return res; 75 | } 76 | } 77 | 78 | exports.listWallet = async function() { 79 | if (!Config.inLibMode) { 80 | //Load key from remote 81 | let res = await Request.get('http://localhost:' + PORT + '/list'); 82 | res = JSON.parse(res).data 83 | return res; 84 | } 85 | } 86 | 87 | exports.deleteWallet = async function(wallet) { 88 | if (!Config.inLibMode) { 89 | //Load key from remote 90 | try { 91 | let res = await Request.get('http://localhost:' + PORT + '/delete?name=' + wallet); 92 | res = JSON.parse(res).data 93 | this.loadKeys(); 94 | return res; 95 | } catch(e) { 96 | console.log(e) 97 | } 98 | } 99 | } 100 | 101 | exports.getPrivateKeysSync = function() { 102 | console.log(keys) 103 | return keys; 104 | } 105 | 106 | exports.getPrivateKeys = async function() { 107 | await this.loadKeys(); 108 | return keys; 109 | } 110 | 111 | exports.getPublicKeys = async function() { 112 | await this.loadKeys(); 113 | let rets = [] 114 | for (let key of keys) { 115 | try{ 116 | let pubkey = await this.privateToPublic(key); 117 | rets.push(pubkey) 118 | } catch(e) { 119 | console.log("Invalid private key, ", key) 120 | } 121 | } 122 | return rets; 123 | } 124 | 125 | exports.createKeyInWallet = async function(name) { 126 | let keys = await this.createKey(); 127 | let ret = await this.importKey(name, keys.privateKey); 128 | return; 129 | } 130 | 131 | async function importKeyToServer(wallet, key) { 132 | let res = await Request.get('http://localhost:' + PORT + '/import?key=' + key + "&name=" + wallet); 133 | res = JSON.parse(res).data 134 | return res; 135 | } 136 | 137 | exports.importKey = async function(wallet, key) { 138 | try { 139 | let pubKey = await this.privateToPublic(key); 140 | } catch(e) { 141 | console.log("Invalid private key, ", key) 142 | return; 143 | } 144 | if (!Config.inLibMode) { 145 | let ret = await importKeyToServer(wallet, key); 146 | if (ret) { 147 | console.log(ret); 148 | return false; 149 | } 150 | } 151 | await this.loadKeys(); 152 | return true; 153 | } 154 | 155 | this.loadKeys() -------------------------------------------------------------------------------- /lib/wallet2.js: -------------------------------------------------------------------------------- 1 | /* 2 | * js4eos Powered by Eosfavor 3 | * Jack Itleaks @2018 4 | * itleaks@126.com 5 | */ 6 | 7 | var Config = require('./config').getConfig() 8 | const fs = require('fs') 9 | 10 | var Eosjs = require('./eosjs').eosjs; 11 | const ecc = Eosjs.modules.ecc 12 | 13 | var crypto = require('./crypto') 14 | var utils = require('./utils') 15 | 16 | var filePasswds = {}; 17 | var keyList = {}; 18 | 19 | var walletDir = Config.dataDir + "/wallets"; 20 | console.log(walletDir) 21 | var wallets = [] 22 | if (!fs.existsSync(walletDir)) { 23 | fs.mkdirSync(walletDir, '0777', true) 24 | } else { 25 | wallets = utils.readDirFilesSync(walletDir); 26 | } 27 | console.log(wallets) 28 | 29 | const MAGIC_DATA = 'js4eos' 30 | var resetTimer = null; 31 | 32 | function reset(wallet=null) { 33 | if (!wallet) { 34 | filePasswds = {}; 35 | keyList = []; 36 | } else { 37 | delete filePasswds[wallet] 38 | delete keyList[wallet] 39 | } 40 | } 41 | 42 | function getKeys() { 43 | let keys = [] 44 | for (let wallet in keyList) { 45 | for (let key of keyList[wallet]) { 46 | if (keys.indexOf(key) == -1) { 47 | keys.push(key) 48 | } 49 | } 50 | } 51 | console.log(keyList) 52 | console.log(keys) 53 | return keys 54 | } 55 | 56 | function getKeyPasswd(wallet) { 57 | return filePasswds[wallet] 58 | } 59 | 60 | function getKeyFile(wallet) { 61 | return walletDir + "/" + wallet 62 | } 63 | 64 | async function loadKeys(wallet, passwd) { 65 | let keys = [] 66 | let keyFile = getKeyFile(wallet) 67 | if (fs.existsSync(keyFile)) { 68 | try { 69 | let encryptedData = fs.readFileSync(keyFile) 70 | console.log(encryptedData.toString()) 71 | let decryptedData = crypto.decrypt('aes192', Buffer.from(passwd), encryptedData.toString()) 72 | console.log(decryptedData) 73 | let data = JSON.parse(decryptedData.toString()); 74 | if (data.header != MAGIC_DATA) { 75 | return false; 76 | } 77 | keys = data.keys; 78 | if (!keys) { 79 | keys = [] 80 | } 81 | return keys; 82 | } catch(e) { 83 | console.log(e) 84 | return false; 85 | } 86 | } 87 | return false; 88 | } 89 | 90 | exports.resetTime = function() { 91 | if (resetTimer) { 92 | clearTimeout(resetTimer) 93 | } 94 | resetTimer = setTimeout(reset, Config.keosd_provide_timeout); 95 | } 96 | 97 | exports.create = async function(wallet, passwd) { 98 | if (fs.existsSync(getKeyFile(wallet))) { 99 | return "wallet already exist" 100 | } 101 | console.log(wallet, passwd) 102 | filePasswds[wallet] = passwd; 103 | wallets.push(wallet) 104 | keyList[wallet] = [] 105 | this.saveKeys(wallet); 106 | return "" 107 | } 108 | 109 | exports.unlock = async function(wallet, passwd) { 110 | let keyFile = getKeyFile(wallet); 111 | if (!fs.existsSync(keyFile)) { 112 | return "please create wallet before unlock" 113 | } 114 | reset(wallet); 115 | console.log(passwd) 116 | const ret = await loadKeys(wallet, passwd); 117 | if (ret === false) { 118 | return "unlock fail,may wrong password" 119 | } 120 | filePasswds[wallet] = passwd 121 | keyList[wallet] = ret 122 | return "unlock success"; 123 | } 124 | 125 | exports.lock = async function(wallet) { 126 | reset(wallet) 127 | return "lock success"; 128 | } 129 | 130 | exports.delete = async function(wallet) { 131 | try{ 132 | reset(wallet) 133 | fs.unlinkSync(getKeyFile(wallet)); 134 | } catch(e) { 135 | console.log(e) 136 | return "delete fail"; 137 | } 138 | let index = wallets.indexOf(wallet); 139 | if (index > -1) { 140 | wallets.splice(index, 1); 141 | } 142 | return "delete success"; 143 | } 144 | 145 | exports.list = async function() { 146 | let ret = [] 147 | for (let wallet of wallets) { 148 | if (getKeyPasswd(wallet)) { 149 | ret.push(wallet) 150 | } else { 151 | ret.push(wallet + " [*] ") 152 | } 153 | } 154 | console.log("list", ret) 155 | return ret; 156 | } 157 | 158 | exports.saveKeys = async function(wallet) { 159 | let filePasswd = getKeyPasswd(wallet) 160 | let keyFile = getKeyFile(wallet); 161 | let data = JSON.stringify({header:MAGIC_DATA, keys:keyList[wallet]}); 162 | let encryptedData = crypto.encrypt("aes192", Buffer.from(filePasswd, 'utf8'), Buffer.from(data, 'utf8')) 163 | console.log(encryptedData) 164 | fs.writeFileSync(keyFile, encryptedData); 165 | } 166 | 167 | exports.getPrivateKeysSync = function() { 168 | let keys = getKeys(); 169 | return keys; 170 | } 171 | 172 | exports.getPrivateKeys = async function() { 173 | let keys = getKeys(); 174 | return keys; 175 | } 176 | 177 | exports.importKey = async function(wallet, key) { 178 | if (!getKeyPasswd(wallet)) { 179 | return "please unlock before import"; 180 | } 181 | if (!keyList[wallet]) { 182 | keyList[wallet] = [] 183 | } 184 | if (keyList[wallet].indexOf(key) >= 0) { 185 | return "key already exist"; 186 | } 187 | keyList[wallet].push(key) 188 | this.saveKeys(wallet); 189 | return ''; 190 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "js4eos", 3 | "version": "1.6.2", 4 | "license": "MIT", 5 | "preferGlobal": true, 6 | "main": "index.js", 7 | "bin": { 8 | "js4eos": "js4eos", 9 | "js4eos_bg": "js4eos_bg", 10 | "bg_service": "bg_service" 11 | }, 12 | "repository": "https://github.com/itleaks/js4eos", 13 | "scripts": { 14 | "test": "node dev-demo.js" 15 | }, 16 | "keywords": [ 17 | "eos", 18 | "javascript eos", 19 | "eos cleos", 20 | "eos client" 21 | ], 22 | "dependencies": { 23 | "archiver": "^3.0.0", 24 | "command-exists": "^1.2.8", 25 | "daemonize2": "^0.4.2", 26 | "eosjs": "16.0.8", 27 | "mocha": "^5.2.0", 28 | "open": ">=6.0.0", 29 | "query-string": "^6.2.0", 30 | "readline-sync": "^1.4.9", 31 | "request": "^2.88.0", 32 | "unzip": "^0.1.11", 33 | "yargs": "^7.0.2" 34 | } 35 | } 36 | --------------------------------------------------------------------------------