Skip to content

Instantly share code, notes, and snippets.

@joshstevens19
Forked from nivida/Web3-CLI.md
Last active December 20, 2018 18:57
Show Gist options
  • Save joshstevens19/dcb8d138c330ba25934410815a61f90a to your computer and use it in GitHub Desktop.
Save joshstevens19/dcb8d138c330ba25934410815a61f90a to your computer and use it in GitHub Desktop.
Web3 CLI specification (draft)
These are the web3 commands:
  
  Starting with a project:
    init <--browser|--server|--server-api> [options]      Starts the setup, will then ask questions like NPM does (name of project etc).
                                                          Will create a basic web or node app for them.
    
    options: 
         --browser
         --server
         --server-api - could hook into express and generate them a entire boilerplate node API?
        
  Development commands:
    run       Starts a node and the project or serves them the browser if they 'init --browser'
    
  Authenticatation - login to the CLI to do authenticated tasks
    web3 login <private-key>                 Login to your eth account
    web3 logout                              Logout the authenticated account
    web3 create [entropy]                    Creates a new account with the CLI
    
  Account - manage authenticated accounts in the CLI (throwing some ideas out)
    web3 wallet create [entropy]             Generates one or more accounts in the wallet. 
                                        If wallets already exist they will not be overridden.          
    web3 wallet add <privatekey>             Adds an account using a private key or account object to the wallet.
    web3 wallet rm <index>               Removes an account from the wallet.
    web3 wallet clear                        Securely empties the wallet and removes all its accounts.
    web3 wallet encrypt <password>
    web3 wallet decrypt 
    web3 wallet load <password> 
    web3 wallet ls
  
  EthPM managment:
    web3 ethpm publish <packageName>               Adds a contract package to the current project
    web3 ethpm uninstall <packageName>             Removes a contract package to the current project
    web3 ethpm update <packageName>                Updates a contract package to the current project
                                        (could just use publish all the time)
    web3 ethpm ls                                  Lists the contract packages in the current project
    web3 ethpm install                             Install all ethpm packages
    web3 ethpm install [<packageName>[@version]>   Installs a ethpm package to the current project
    web3 ethpm owner ls <packageName>              See who the owner(s) of the package is
    web3 ethpm owner change <privatekey>           Change the owner of a package (only work if you sign it) 
                                        and only work if you authenticated with the CLI
    
  ENS management:
    web3 ens registry                           Returns the network specific ENS registry
    web3 ens resolver <ENSName>                 Returns the resolver contract to an Ethereum address.
    web3 ens owner <ENSName>                    Returns the owner of the ens domain
    web3 ens owner change <ENSName> <address>   Sets the address of an ENS name in his resolver.
    
    
  Generating of code (generate:*):
    web3 generate <tool> [options]           Generates certain files depeneding on the tool
    
    Ideas:
      web3 generate <contract>               Generates a contract class based on the contract abi
      web3 generate <sign> [sign|sign-transaction|send-sign-transaction] - Generates a code basic class with code examples
      web3 generate interface 
      web3 generate class
      web3 generate enum
      web3 generate types <ABI>              Generate full typings for a ABI
      web3 generate code <ABI>               Generate classes for the code ?? pretty neat idea! 
      .. surely we will discover move on the way! 
      
  Call a JSON-RPC method:
    web3 jsonrpc <network> <version> <method> [<params>] <id>    Calls an JSON-RPC method
    
 Contract calls: 
    web3 contract <method> [params] call [<required-options>]    Calls an contract method based on the current project (maybe json interface is defined in the package.json or something, so we don't have to ask for it everytime) ?
    web3 contract <method> [params] send [<required-options>]    send using 
    web3 contract <method> estimateGas [<required-options>]  
    web3 contract <method> encodeABI [<required-options>]  
    web3 contract events ls                                     List all events for the contract
    web3 contract events ls --past                              List only past events for a contract
    
    
  Open documents 
     web3 doc <package | keyword>  Open document to the package and what it does
     
  Version:
    web3 version                    Outputs web3 CLI version. 
    
  Alias:
    web3 alias add  ..  Add your own alias mappings for the CLI
    web3 alias rm  ..   Remove your alias mappings
    
  Star:
    web3 stars                    Returns all the things you have starred
    web3 star doc <name> <url>    Star a documentation so you can easily get back to it
   .. maybe other things we can star?
   
  ping:
    web3 ping <network|customrpc>          Check if network is alive
    
  deploy??!:
    Do we want to hook in auto deployment or here? basically doing the hard lifting in truffle and allowing ease of deployment, with a single CLI tool?

  ... think we can do cool things like `web3 audit` to audit code to try to make sure its secure as well. Probably for v2.
    

Starting with a project:

Init

  • Which "runtimes" should it support (node.js, angular, react, vue.js, ...) - (Josh: think the CLI should be built in node we can use npm to deploy it and make it install globally for users. Users are use to this experience so i think it makes sense. Stuff like commander etc can help us create a lovely CLI design).
  • Do we want to use yeoman for the setup?
  • What are the setup steps? - (Josh: npm install web-cli -g)
  • Which options will this command have? - (Josh: put my suggestions above)

Development commands

Open questions
  • Should it have the possibility to select a node type (parity, geth, ganache, ...) (Josh: maybe could be nice)

run

  web3 run --watch --net="dev"
Options
watch
  • Build on file change (wrapper of framework cli) (Josh: yeah like how angular do it, on changing a file it rebuilds. Defo worth having)
net
  • Select the node to connect

build

  web3 build --browser --node
Options
browser
  • Creates a build with the browser config
node
  • Creates a build with the node config

Package managment (powered by EthPM)

Open questions
  1. Do we want a ethpm.json as truffle has or do we just extending the package.json of npm? (Sam: I would just extend the package.json) (Josh: After looking at the package.json below i think we should have our own json file 'web3-cli.json' like angular do)
  2. Which additional options should the command add have?

add

  web3 add [email protected] --save
  > Package [email protected] would be added to the package.json.
  > Package [email protected] successfully added.
Options
packageName
  • <package name>@<version>

remove

  web3 remove MYPackage
  > Package with name MYPackage removed.    

(Josh: probs would go with rm to follow npm linux CLI style)

Options
packageName
  • The EthPM package name

Generating of code (generate:*)

contract

  web3 generate:contract <packageName|--abi|--address> --out --types
  > Contract with name TestContract created in PATH.    
Options
packageName (optional)
  • The EthPM package name
abi (optional)
  • The root of the path should be the project folder root (e.g. "./assets/ContractABI").
out (optional)
  • Default path is "./"
  • The root of the path should be the project folder root (e.g "./contracts/").
address (optional)
  • The contract address or an ENS name to a contract
types
  • Generates a TypeScript interface from the ABI. (Josh: This is a brilliant idea, i mentioned this above as well, defo something we should include, i was also thinking we could generate a entire class of their funtionalty written in JS or TS, we could easily define a base line app for them based on the ABI?)

Call a JSON-RPC method:

method

  web3 method <methodName: eth:*, shh:*, ...>  <options: methodParameters>
  > '0x0'

(Josh: Put my ideas above think we should have a generic one i.e. jsonrpc [] . I also think we should handle 'send' 'estimateGas' etc within calling methods for a contract)

Options
methodName
  • All methods defined in namespaces (e.g. eth:call)
options
  • How should the JSON-RPC method parameters are given to the method? (Josh: have to work out the most elegant way for this as we wouldnt want to command to get complex)

CLI configuration

The post install hook of npm should be used to installing the contract dependencies.

  //... package.json (Josh: probs best to put this in its own json file after looking at this, 'web3-cli.json' like angular do)
  {
    "web3": {
      "build": {
        "browser": {
            provider: ["metamask", "mist", "status", "brave"] // ["ws:168.111.0.1:8564"]
        },
        "node": {
            provider: "ws:168.111.0.1:8564"// IPC_PATH | http://
        }
      },
      "mainnet": {
          provider: "ws:168.111.0.1:8564" // IPC_PATH | http://
      },
      "development": {
          "net": "ganache", // ["geth", {protocol: 'HTTP', ...}]
          "truffle": false, // If true truffle will be used for the deploying of the contracts 
          "rootDir": "./",
          "packages": "./node_modules/"
      },
      "dependencies": {
          "myContractPackage": "^0.1.0",
          "myChainContractPackage: "0x0",
          "myENSNameContractPackage: "contract.eth"
      }
    }
  }
@joshstevens19
Copy link
Author

Once you done that i will create us a professional google doc and we go from there 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment