Skip to content

Feat: Solidity Repl #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brockelmore opened this issue Dec 14, 2021 · 6 comments
Closed

Feat: Solidity Repl #230

brockelmore opened this issue Dec 14, 2021 · 6 comments
Labels
C-forge Command: forge T-feature Type: feature

Comments

@brockelmore
Copy link
Member

Have seen a few requests for a solidity repl. This can be a tracking issue for the feature

Helpful things:

@transmissions11
Copy link
Contributor

Omg would be so dope if it had all your contract abis loaded to go so you could do something like ERC20 token new ERC20() in the shell right away and just play around with it

@mattsse
Copy link
Member

mattsse commented Dec 14, 2021

some thoughts after skimming solidity-shell's codebase

it appears an appropriate approach to this could be:

  1. run a repl like https://github.com/kkawakam/rustyline, see also https://github.com/kpcyrd/sn0int for an example implementation
  2. listen for user input
    a. if it's a solidity statement, inject that into a template contract, compile and deploy that
    b. if it's some math expr, inject that into a function, deploy and return the response after calling that template function
    c. else try to find a matching function that was previously deployed and call that

There's also TempProject now in ethers-solc which is probably helpful

If anyone would like to take this on, I'm happy to help

@transmissions11
Copy link
Contributor

Can we persist variables? That’d be a dream

@mattsse
Copy link
Member

mattsse commented Dec 14, 2021

totally, what I'm thinking is something like this:

pub struct SolRepl {
    /// this gives us the user input
    rl: Readline,
    /// this stores all previously evaluated user inputs, like vars, etc
    session: Session,
    /// the type that executes all the things
    sol: Sol,
}

struct Sol {
  /// the virtual project where we store all the things (perhaps not even necessary if we only use solc standard json input/output)
  project: TempProject,
  // stores all the deployed contracts/abis etc...
  state: SolState
}

then the actual repl would probably look something like:

loop {
 
 let input = self.rl.readline();
 let res = self.sol.execute(&line);
 println!("{}", res);
  }

@wilsoncusack
Copy link
Contributor

Would love to see gas cost printed after evaluation :)

@mattsse
Copy link
Member

mattsse commented Jan 27, 2023

closed via #3465

@mattsse mattsse closed this as completed Jan 27, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-feature Type: feature
Projects
Archived in project
Development

No branches or pull requests

6 participants