Skip to content

Instantly share code, notes, and snippets.

@nivida
Last active December 12, 2018 07:58
Show Gist options
  • Save nivida/fc5bcb86c18843c46c4f636c8464e75f to your computer and use it in GitHub Desktop.
Save nivida/fc5bcb86c18843c46c4f636c8464e75f to your computer and use it in GitHub Desktop.
Web3 CLI specification (draft)
These are the web3 commands:
  
  Starting with a project:
    init      Starts the setup
      
  Development commands:
    run       Starts a node and the project
  
  EthPM managment:
    add       Adds a contract package to the current project
    remove    Removes a contract package to the current project
    
  Generating of code (generate:*):
    generate:contract  Generates a contract class based on the contract abi
      
  Call a JSON-RPC method:
    method    calls an JSON-RPC method

Starting with a project:

Init

  • Which "runtimes" should it support (node.js, angular, react, vue.js, ...)
  • Do we want to use yeoman for the setup?
  • What are the setup steps?
  • Which options will this command have?

Development commands

Open questions
  • Should it have the possibility to select a node type (parity, geth, ganache, ...)

run

  web3 run --watch --net="dev"
Options
watch
  • Build on file change (wrapper of framework cli)
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)
  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.    
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.

Call a JSON-RPC method:

method

  web3 method <methodName: eth:*, shh:*, ...>  <options: methodParameters>
  > '0x0'
Options
methodName
  • All methods defined in namespaces (e.g. eth:call)
options
  • How should the JSON-RPC method parameters are given to the method?

CLI configuration

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

  //... package.json
  {
    "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"
      }
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment