Socket
Socket
Sign inDemoInstall

solidity-shell

Package Overview
Dependencies
400
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    solidity-shell

[](https://diligence.consensys.net) <sup> [[ 🌐 ](https://diligence.consensys.net


Version published
Maintainers
1
Created

Changelog

Source

v0.1.0

⚠️ pot. breaking changes: solidity-shell now ships with ganache. use .chain set-provider to switch chain providers. the built-in ganache provider is used by default.

  • new: built in ganache provider
  • new: .chain subcommand
    • .chain restart - restarts the service (formerly known as .restartblockchain)
    • .chain set-provider [fork-url] - switch between the internal or an external ganache-cli command or url-provider. Optionally specify a ganache fork-url.
      • .chain set-provider internal https://mainnet.infura.io/v3/yourApiKey
    • .chain accounts - show ganache accounts
    • .chain eth_<X> [args...] - arbitrary eth JSONrpc method calls to blockchain provider.
      • e.g. .chain eth_accounts returns the blockchain providers response to the eth_accounts JSONrpc call.
  • new: command line switches:
    • --fork overrides fork-url option for internal ganache provider solidity-shell --fork https://mainnet.infura.io/v3/yourApiKey.
    • --reset-config resets the config file.
    • --show-config-file prints the path to the config file.
  • fix: better error handling. prevent vicious cycles where broken config trashes the app 🤦‍♂️
  • update: dependencies and solc references updated

Readme

Source

get in touch with Consensys Diligence
[ 🌐 📩 🔥 ]

Solidity Shell

An interactive Solidity shell with lightweight session recording and remote compiler support.

💾 npm install -g solidity-shell

note: requires npm install -g ganache-cli unless it is already installed :)

⇒  solidity-shell
 
🚀 Entering interactive Solidity shell. '.help' and '.exit' are your friends.
 »  ℹ️  ganache-mgr: starting temp. ganache instance ...
 »
 »  uint a = 100
 »  uint b = 200
 »  a + b + 2 + uint8(50)
352
 »  $_
352

Oh, did you know that we automatically fetch a matching remote compiler when you change the solidity pragma? It is as easy as typing pragma solidity 0.5.0 and solidity-shell will do the rest 🙌.

Hints

  • pragma solidity <version> attempts to dynamically load the selected compiler version (remote compiler, may take a couple of seconds).
  • use { <statement>; } to ignore a calls return value.
  • 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).
  • .reset completely removes all statements. .undo removes the last statement.
  • See what's been generated under the hood? call .dump.
  • 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.
  • $_ is a placeholder for the last known result. Feel free to use that placeholder in your scripts :)
  • Special commands are dot-prefixed. Everything else is evaluated as Solidity code.
  • import "<path>" assumes that path is relative to the current working-dir (CWD) or {CWD}/node_modules/. There's experimental support for HTTPs URL's. You can disable https resolving by setting » .config set resolveHttpImports false.
 »  import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC721/IERC721.sol"

Usage

Cmdline Passthru

Any arguments provided after an empty -- are directly passed to ganacheCmd (default: ganache-cli). This way, for example, you can start a solidity shell on a ganache fork of mainnet via infura. Check ganache-cli --help for a list of available options.

⇒  solidity-shell -- --fork https://mainnet.infura.io/v3/yourApiToken
 
🚀 Entering interactive Solidity shell. Type '.help' for help, '.exit' to exit.
 »  ℹ️  ganache-mgr: starting temp. ganache instance ...
 »
 »  interface ERC20 {
multi> function name() external view returns (string memory);
multi> }
 
 »  ERC20(0xB8c77482e45F1F44dE1745F52C74426C631bDD52).name()
BNB

Repl
🚀 Entering interactive Solidity ^0.8.11 shell. '.help' and '.exit' are your friends.
 »  ℹ️  ganache-mgr: starting temp. ganache instance ...
 »
 »  .help

📚 Help:
   -----

 $_ is a placeholder holding the most recent evaluation result.
 pragma solidity <version> to change the compiler version.


 General:
    .help                                ... this help :)
    .exit                                ... exit the shell
    .restartblockchain                   ... restart the ganache blockchain service

 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:
    .proc                                ... show processes managed by solidity-shell (ganache)
    .dump                                ... show template contract
    .echo                                ... every shell needs an echo command


cheers 🙌 
    @tintinweb 
    ConsenSys Diligence @ https://consensys.net/diligence/
    https://github.com/tintinweb/solidity-shell/ 

Examples

solidity-shell

Transaction vars: msg.sender etc.

 »  msg.sender
0x70e9B09abd6A13D2F5083CD5814076b77427199F
 »  address(uint160(address(msg.sender)))
0x70e9B09abd6A13D2F5083CD5814076b77427199F

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.

Keywords

FAQs

Last updated on 13 Apr 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc