GithubHelp home page GithubHelp logo

protofire / eth-cli Goto Github PK

View Code? Open in Web Editor NEW
242.0 21.0 46.0 11.58 MB

CLI swiss army knife for Ethereum developers

Home Page: https://www.npmjs.com/package/eth-cli

License: MIT License

JavaScript 8.05% Batchfile 0.02% Dockerfile 0.27% Shell 26.99% TypeScript 54.09% Solidity 10.59%
ethereum cli blockchain

eth-cli's Introduction

eth-cli

A CLI swiss army knife for Ethereum developers

Donate with Ethereum

Build Status NPM version MIT licensed dependencies Status devDependencies Status

Why use it?

eth-cli allows you to fetch data from the blockchain, start an interactive REPL connected to some node, call methods on deployed contracts, and more, all at the comfort of your command line. Checkout the examples below for more information or check the full list of commands.

Table of Contents

Installation

Install it globally:

npm install -g eth-cli

You can also try it with npx:

$ npx eth-cli repl --mainnet erc721@0x06012c8cf97bead5deae237070f9587f8e7a266d
> erc721.methods.name().call()
'CryptoKitties'

Demo

Check this screencast to see it in action.

Examples

There are a lot of things that you can do with eth-cli, and we keep adding more. These are some of our favorites:

Fetch data from the blockchain

Use commands like block:number, tx:get and address:balance to get information from the blockchain.

Fetch data from the blockchain

more examples

Autocomplete

eth-cli supports some basic autocompletion, generated with completely.

The completion directory has a bash completion script (eth-completion.bash) and a zsh completion script (_eth). If you use bash, download the script and source it in your bashrc. If you use zsh, download the script and put it in some directory in your fpath.

Init file

If you want to have some helper variables or functions in your REPL, you can create an init file that will be loaded every time you use eth repl. Just create a file called .eth_cli_repl_init.js in your home directory. For example, if you create it with some content like:

module.exports = function(context) {
  context.toWei = x => context.web3.utils.toWei(x.toString())
  context.fromWei = x => context.web3.utils.fromWei(x.toString())
}

you will have toWei and fromWei as global functions in the REPL.

Sibling projects

  • Solhint: A linter for the Solidity language.

Back us

eth-cli is free to use and open-sourced. If you value our effort and feel like helping us to keep pushing this tool forward, you can send us a small donation. We'll highly appreciate it :)

Donate with Ethereum

Credits

Table of Contents generated with DocToc

eth-cli's People

Contributors

acolytec3 avatar agupane avatar dependabot[bot] avatar dminones avatar emmaodia avatar fernandomg avatar fgagneten avatar fvictorio avatar gillchristian avatar hpmaxi avatar lmcorbalan avatar mariano-aguero avatar mgarciap avatar nicosampler avatar pablofullana avatar patitonar avatar semantic-release-bot avatar sistemico avatar smitrajput avatar uivlis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eth-cli's Issues

Expose accounts in global variable

Similar to how web3 and eth are exposed, it would be nice to have accounts available (right now I eval eth.getAccounts() and copy the first address).

Add a summary for each top level command

The readme has a detailed explanation on each command (both "partial" and "full"), but maybe it would be useful to have a list of the top level commands to give a rough idea of the kind of things that can be done. Alternatively, see how to give a high level overview of the available functionality, without using a huge list.

Load "linked" contract in repl

With the current repl command, is easy to start the repl and load a contract given its address and ABI:

eth repl erc20@0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359
# or
eth repl
> .loadc erc20@0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359

But sometimes a contract has a related address which can be obtained with a state variable or method. In that case you have to load the first contract, consult the related address, and load the second contract (this can be done inside the repl with loadc, or you have to close the repl and open it again with the second contract).

It would be nice to have a easier way to do this.

Option 1: Extend the repl command syntax

This would work like this:

eth repl myContract@0x123... [email protected]

That is: the first contract has a variable (or view method without parameters) called other that returns an address, and myOtherContract is the ABI for that related contract.

While this could work, I have some concerns:

  • I've been wanting to extend this "syntax" for a while, to allow the user to name the loaded contract. Something like eth repl erc20@0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359:dai. This potential new syntax and the one for related contracts are compatible, but I'm not sure about converting this into a sort of DSL.
  • Sometimes the related address needs an argument. The obvious example is when you have an array with addresses. And while you could do something like eth repl myContract@0x123... [email protected](0), I think that's going too far into the weird zone.

Option 2: Make .loadc accept promises

My first alternative was something like (inside the repl):

.loadc myOtherContract myContract.methods.other().call()

This would solve the problem when the method that returns the address has parameters. The problem is that it's not arrow-up-able (a word I just made up and that means "you can't reuse the shell history easily"). Also, the .loadc syntax, like the one for repl, uses @, but I actually don't like that, so I'd be fine with using a plain whitespace instead.

Option 3: Improve conf

This is not solving the described problem, but maybe it resolves the underlying problem: not wanting to remember and/or copy and paste a lot of addresses. If conf could be used for saving contracts addresses (and perhaps even address/ABI pairs, think eth repl dai), maybe that would be enough.

Option 4: Save repl state

Alternatively, add a command that you can use to preserve variables between repl sessions. This would be useful for other things too, but I'm afraid that you couldn't really save contract instances because they are not serializable.

`contract:deploy` doesn't stop at third confirmation when deploying to ganache

Estimated gas: 119955
TX: 0xa617d3fb3a1d9a5db495fef4a040d00985f4148d36c21fd090df8b22cdc4de50
{
  "address": "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab"
}
Confirmation 1 of 3
Confirmation 2 of 3
Confirmation 3 of 3
Confirmation 4 of 3
Confirmation 5 of 3
Confirmation 6 of 3
Confirmation 7 of 3
Confirmation 8 of 3
Confirmation 9 of 3
Confirmation 10 of 3
Confirmation 11 of 3
Confirmation 12 of 3
Confirmation 13 of 3
Confirmation 14 of 3
Confirmation 15 of 3
Confirmation 16 of 3
Confirmation 17 of 3
Confirmation 18 of 3
Confirmation 19 of 3
Confirmation 20 of 3
Confirmation 21 of 3
Confirmation 22 of 3
Confirmation 23 of 3
Confirmation 24 of 3

After the 24th confirmation it does stop. But besides that, it doesn't really make sense to wait for more blocks in ganache, since probably no more blocks are going to be generated (unless other transactions are created elsewhere). Idea: in commands that create transactions, add an option for the number of confirmation blocks to wait for, defaulting to 1.

Known ABIs

It would be nice if eth-cli would come with certain well-known ABIs (ERC20, ERC721, etc.). I see two use cases for this:

  • Use them in any command that expects a path to an ABI file (contract:load, etc.)
  • Add a command that prints the ABI. For example, if you want to add an ERC20 token to metamask, doing eth abi:show ERC20 would be slightly more convenient than googling it.

Improve multiple contracts naming

From this conversation #29 (comment)

Contracts naming in the REPL context can be improved.

A suggestion I have is to use the abi file name and part of its name, instead of adding a suffix. For instance:

eth lc --mainnet path/to/ERC20.abi 0x another/path/to/ERC20.abi 0x path/to/ERC725.abi 0x

Will result in: ERC20, ERC20_to_path_another, ERC725

Now that I wrote it down, it may be a bit awkward if the path is too long, but we can think of a name length limit and from there start to add suffixes.

Add connected network info to prompt

Show network information in the prompt.

Open question, what should we display about the network?:

  1. The network name.
  2. The network url (covers the --url case, I believe).

Make load-contract infer the contract name from the ABI file

Right now the loaded contract is exposed as Contract. We should use the filename of the ABI file to infer the name.

This can be done with path.basename(abiPath, path.extname(abiPath)). Note that if the file is called Token.abi.json, then the variable will be named Token.abi and will not be available in the repl. The alternative is to do basename.split('.')[0],

Add autocompletion support

This is easy to to do, but I think we should wait until oclif/plugin-autocomplete#13 is done, otherwise the experience with eth repl abi@address is significantly worse IMO. That being said, adding autocompletion is completely optional, so if someone wants to start working on this, be my guest.

Make a better introduction in the README

I think the "What is this" section in the README could do a better job of explaining how eth-cli can be useful. Not sure how, but the current content is too generic and doesn't really say much.

Deprecate (or remove) `method:send-transaction`

I can never remember what's the difference between method:send and method:send-transaction. The first one is probably more useful, so I think send-transaction should be removed, deprecated, or maybe merged somehow into send.

Expose Web3 in the repl

Besides exposing web3 (the instance), sometimes is useful to have Web3 (the constructor) available.

Look for alternatives to yargs

e.g. global options are available to all the commands when there are cases where that they are unnecessary.

For instance, when running eth network --help there are several global options that shouldn't be displayed.
image

Display wallet private key as part of random-address command output

Goal

Original request by @ArseniiPetrovich was to have a command in the fashion of eth-cli ra, that generates wallet's address but also outputs its private part (supporting JSON format as well)

Internal discussion notes

eth vanity '' already does that, but it's kind of a side effect actually. Maybe the three things could be integrated under one command:

  1. eth random-address To generate a random address
  2. eth random-address --full To generate a JSON with the address and corresponding private key
  3. eth random-address --prefix aa Same as eth vanity aa
  4. Another option is to, by default, output the JSON, and have a flag --only-address

A simpler version could be:

  1. eth random-address To generate a JSON with the address and the private key.
  2. eth random-address --prefix aa Same as eth vanity aa

Let's discuss these (and any other) alternatives

Add command to create random address

Something like eth random-address that just outputs a random eth address. Sort of a shortcut for doing ganache-cli and copying the first address in the list.

Improve readme

The readme could use a serious revamp:

  • Separate commands in categories (REPLs, encode/decode, others)
  • Add instructions to use the eth completion command in both bash and zsh

`eth vanity` sometimes fails

There is a bug in web3 that makes this happen. A PR with a fix is already open in web3 (see web3/web3.js#1912). When that PR is merged and a new version is published, we should update the web3 dependency and close this.

Allow both .abi files an truffle artifacts when using load-contract

The load-contract command requires as first argument a path to the ABI file of the contract.

It would be nice to allow using truffle artifacts files too. It shouldn't be hard: if the given file has an array, interpret it as an ABI file. If it's an object and it has an abi propery, interpret it as a truffle artifact.

Consolidate network flags under a single flag

Right now we have all these flags for connecting to different networks:

  --kovan        Connect to Kovan network
  --mainnet      Connect to Mainnet network
  --poa          Connect to POA network
  --rinkeby      Connect to Rinkeby network
  --ropsten      Connect to Ropsten network
  --rsk          Connect to RSK network
  --rsk-testnet  Connect to RSK testnet network
  --sokol        Connect to Sokol network
  --url=url      [default: http://localhost:8545] URL of the ethereum node to connect.
  --xdai         Connect to xDAI network

I propose we merge all those into a single flag: --network, --net or maybe --url. The default value continues to be http://localhost:8545. If the given value is not an URL, it will be interpreted as a "shortcut" to one of the known networks (exposed by eth network:urls).

Improve logging

  • Adding --verbose options
  • Find a better way to log info messages to stderr from oclif or perhaps another lib. Now we are using process.stderr.write.

Add command to show network ids

Add command to show the network ids for each known network (possibly limited to only the ones that have shortcuts for the RPC).

The command should be a subcommand of eth networks (that doesn't exist yet). Not sure about the subcommand name, maybe ids.

Compilation warnings

MacOS + Node.js v11 = many compilation warnings.

Just a gist of it...

MacRamboPro:www demian$ npm install -g eth-cli
npm WARN deprecated [email protected]: ⚠️  WARNING ⚠️ tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
npm WARN deprecated [email protected]: Use mz or fs-extra^3.0 with Promise Support

> [email protected] preinstall /usr/local/lib/node_modules/eth-cli/node_modules/scrypt
> node node-scrypt-preinstall.js

/usr/local/bin/eth -> /usr/local/lib/node_modules/eth-cli/src/index.js

> [email protected] install /usr/local/lib/node_modules/eth-cli/node_modules/keccak
> npm run rebuild || echo "Keccak bindings compilation fail. Pure JS implementation will be used."


> [email protected] rebuild /usr/local/lib/node_modules/eth-cli/node_modules/keccak
> node-gyp rebuild

  CXX(target) Release/obj.target/keccak/src/addon.o
In file included from ../src/addon.cc:2:
../../nan/nan.h:1064:44: warning: 'ToString' is deprecated: Use maybe version [-Wdeprecated-declarations]
      v8::Local<v8::String> string = from->ToString(v8::Isolate::GetCurrent());
                                           ^
/Users/demian/.node-gyp/11.1.0/include/node/v8.h:2537:3: note: 'ToString' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/demian/.node-gyp/11.1.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/addon.cc:37:34: warning: 'IntegerValue' is deprecated: Use maybe version [-Wdeprecated-declarations]
    unsigned int rate = info[0]->IntegerValue();
                                 ^
/Users/demian/.node-gyp/11.1.0/include/node/v8.h:2570:3: note: 'IntegerValue' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", int64_t IntegerValue() const);
  ^
/Users/demian/.node-gyp/11.1.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/addon.cc:38:38: warning: 'IntegerValue' is deprecated: Use maybe version [-Wdeprecated-declarations]
    unsigned int capacity = info[1]->IntegerValue();
                                     ^
/Users/demian/.node-gyp/11.1.0/include/node/v8.h:2570:3: note: 'IntegerValue' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", int64_t IntegerValue() const);
  ^
/Users/demian/.node-gyp/11.1.0/include/node/v8config.h:326:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../src/addon.cc:56:35: warning: 'IntegerValue' is deprecated: Use maybe version [-Wdeprecated-declarations]
    unsigned char bits = info[0]->IntegerValue();

Allow outputting keystore in `address:random`

Something like this should work:

$ eth address:random --password mysecretpassword
{ version: 3,
  id: '2c1135b2-a74d-4154-a359-e27e42297f36',
  address: 'aec3c8ed9516a206a4fd47ec77f026edd533cf17',
  crypto:
   { ciphertext:
      'd8e0430ffc1a544ed9f6b952cc2ee52b158f652b82d544c643d3d072cc394119',
     cipherparams: { iv: 'e74a30081dbceb807fd79774c3e9bdbc' },
     cipher: 'aes-128-ctr',
     kdf: 'scrypt',
     kdfparams:
      { dklen: 32,
        salt:
         '47e53f2caf2dd2e53ed87d225a9659781499a261e729cd597e1b61e18d5110da',
        n: 8192,
        r: 8,
        p: 1 },
     mac:
      'e8fd2b497e873733917e9032c70c917b5e7e7ad68f8f3a98a10714fa0f7fcb65' } }

Question: what happens if the user specifies a number of addresses? For example: eth ra --password mysecretpassword 2. For now we can just disallow this, it doesn't seem very useful anyway.

Problem with contract:deploy

I've found a problem trying to deploy a contract.

For example running this command eth contract:deploy --ropsten 0x0fb78ee19db8da275893a7b6aa176edc09699e56bb0ba63ff6affa70660da4e9 ./MyPhrase.bin It took a lot of time and at the end it finished the execution without any visible result.

Add tx:events method

Add a tx:events method that, given some ABIs and a transaction hash, prints all the emitted events, properly parsed when they belong to one of the given ABIs.

Something we need to define: how are the ABIs passed to the command? One option is to do something like:

eth tx:events --abi abi1 --abi abi2 txHash

This should work, but the question is if we should also include the "known ABIs". I mean: if erc20 and erc721 should be included even if you don't specify them.

Allow loading more than one contract with load-contract

Depends on #20.

The syntax would be eth load-contract abi1 address1 [abi2 address2 [...]].

I'm not totally sure about what to do with the variable names if two abis have the same basename. Adding a suffix (Token_1, Token_2) may work, but maybe there's a better alternative.

Improve output of help commands

This issue will be a little underdefined, but I'd like to start a discussion around this. Is there a way to improve the output of the help commands? Can discoverability be improved? We are using the default help from oclif, and just adding the relevant data. Can we make a custom help function more suitable for this project?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.