Add `script` CLI command
- Lenguaje dominante
- Rust
- Estrellas
- 78
- Forks
- 129
- Merge medio
- 4 d 14 h
- PR fusionados (30 d)
- 52
Descripción
# Summary
This issue is a result of the `miden-client` and `midenup` CLI Improvement Proposal discussions.
For context, take a look here:
- [`miden-client` CLI improvement proposal](https://github.com/0xMiden/miden-client/discussions/1394)
- [`midenup` improvement proposal](https://github.com/0xMiden/midenup/discussions/108)
## Description
Real-world blockchain development, especially in DeFi, requires complex deployment sequences that go far beyond simple contract constructors. Developers often need to:
- Deploy multiple contracts simultaneously
- Perform complex initialization sequences
- Execute multiple setup calls per contract
- Compose and interact with Notes
- Implement custom Account code deployments
A simple `deploy` command (as proposed in [#1397](https://github.com/0xMiden/miden-client/issues/1397)) is insufficient for these sophisticated use cases. Developers need a flexible, programmable approach that allows them to write custom logic for their specific deployment and interaction requirements.
Architecturally, this new command would do the following:
- Initialize a client for the user
- Execute the code in the Rust script file as specified by the input
## Proposed Solution
Add a `script` command to `miden-client` that enables developers to write and execute custom Rust scripts for any client interactions within their project.
**Architecture:**
- Initialize a pre-configured Miden client for the user (using the `miden-client` keystore and sqlite database)
- Execute custom Rust code from script files
### Distinction to running a Rust binary
While the proposed `script` command shares similarities with running a standalone Rust binary that implements a Miden client, there are several key distinctions that make this approach more developer-friendly.
#### 1. Provide better structure to devs
The most important benefit of this would be to provide a foundational structure for devs that are developing on Miden. As of now, many things are undefined, and we do not really have best practices for devs on how to structure things or do contract deployment / interactions on Miden. Unfortunately, best-practices and providing defaults are both highly requested by our pioneers.
By providing developers with a pre-defined scripts directory (initialized by `miden new`), and a default way of how to write network interactions, we would tremendously level-up our development experience and provide devs with a good foundation for developing on Miden.
#### 2. Plug into the miden-client CLI config
The `script` command would automatically initializes a properly configured client instance using the local CLI config. That means that developers could create an Account in the CLI, and then use that same account to perform on-chain actions using the same account. This provides a more seamless dev experience, as devs would not be required to instantiate a Client or the account within the script itself
#### 3. Integrate other features of the miden-client CLI through utility functions
There is an upcoming feature for performing custom contract code deployment from a CLI command, [see here](https://github.com/0xMiden/miden-client/issues/1397).
When adding this feature, we will most likely implement code for building and deploying an account just by using a file path. We can then provide this same feature as a utility function to scripts. This would be tremendously useful as this would effectively mean that developers could deploy Smart Contract code **just by using one function in Rust**. That would be amazing!
### Goal & Foundry reference
All in all, the goal here would be for this command would be to give users a structured and straight forward way on how to write Rust scripts for any client interactions within their project.
In essence, it should work similarly to running `forge script` with Foundry. [See this example](https://getfoundry.sh/guides/scripting-with-solidity/#deploying-the-counter-contract) to get a better understanding of how that currently looks like.
## Note on `midenup` & default project structure
This feature will most likely be used inside of the development environment instantiated by `miden new`. It might make sense to transfer this issue to the `midenup` repository, if we want to make this feature exclusive to the `miden new` development environment.
Furthermore, there is also an ongoing discussion on what kind of project structure to provide to developers: https://github.com/0xMiden/compiler/discussions/646
## User experience
### Intended command
```bash
miden-client script
```
Examples:
```bash
miden-client script scripts/deploy_contract.rs
miden-client script scripts/create_note.rs
miden-client script scripts/increment_counter_count.rs
```
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.