/solidity-shell

An interactive Solidity shell.

Primary LanguageJavaScript

get in touch with Consensys Diligence
[ 🌐 📩 🔥 ]

Solidity Shell

An interactive Solidity shell with lightweight session recording.

💾 npm install solidity-shell

  solidity-shell
 
🚀 Entering interactive Solidity shell. Type '.help' for help, '.exit' to exit.
 »  ℹ️  ganache-mgr: starting temp. ganache instance ...
 »
 »  uint a = 100
 »  uint b = 200
 »  a + b + 2 + uint8(50)
352

Hints

  • Note: Sessions can be saved and restored using the .session command. Your previous session is always stored and can be loaded via .session load previous (not safe when running concurrent shells).
  • Note: .reset completely removes all statements. .undo removes the last statement.
  • Note: See what's been generated under the hood? call .dump.
  • Note: Settings are saved on exit (not safe when running concurrent shells). call config set <key> <value> to change settings like ganache port, ganache autostart, etc.
  • Note: Solidity version is currently fixed to the solc package that comes with the shell. If there's interest we might change that to allow remote compiler versions.
  • Note: $_ is a placeholder for the last known result. Feel free to use that placeholder in your scripts :)
  • Note: Special commands are dot-prefixed. Everything else is evaluated as Solidity code.

Examples

solidity-shell

Sample Usage

 »  .help

📚 Help:
   -----

  General:
    .help                                ... this help :)
    .exit                                ... exit the shell

  Settings:
    .config                              ... show settings
            set <key> <value>            ... set setting
            unset <key>                  ... unset setting
  Session:
    .session                             ... list sessions
            load <id>                    ... load session
            save <id>                    ... save session
            
    .undo                                ... undo last command
    .reset                               ... reset cmd history. start from scratch.

  Debug:
    .dump                                ... (debug) show template contract


cheers 🙌 
    @tintinweb 
    ConsenSys Diligence @ https://diligence.consensys.net/

Contracts, Structs, Functions

  solidity-shell
 
🚀 Entering interactive Solidity shell. Type '.help' for help, '.exit' to exit.
 »  ℹ️  ganache-mgr: starting temp. ganache instance ...
 »
 »  contract TestContract {}
 »  new TestContract()
0xFBC1B2e79D816E36a1E1e923dd6c6fad463F4368
 »  msg.sender
0x363830C6aee2F0c43922bcB785C570a7cca613b5
 »  block.timestamp
1630339581
 »  struct yolo {uint8 x; uint8 y;}
 »  function mytest(uint x) public pure returns(uint) {
multi> return x -5;
multi> }
 »  mytest(100)
95

solidity-shell2

Advanced usage

 »  struct yolo {uint8 x; uint8 y;}
 »  .dump
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.7;

contract TestContract {}

struct yolo {uint8 x; uint8 y;}

contract MainContract {

    

    function main() public  {
        uint a = 100;
        uint b = 200;
        a + b + 2 + uint8(50);
        new TestContract();
        msg.sender;
        block.timestamp;
        return ;
    }
}


Acknowledgements

  • Inspired by the great but unfortunately unmaintained solidity-repl.